Extract js call method

This commit is contained in:
Artur Shaikhullin 2017-12-30 23:46:04 +06:00
parent e22dc1b5c6
commit 695f734142

View File

@ -208,87 +208,69 @@ class WebEngineCaret(browsertab.AbstractCaret):
@pyqtSlot(usertypes.KeyMode) @pyqtSlot(usertypes.KeyMode)
def _on_mode_left(self): def _on_mode_left(self):
self.drop_selection() self.drop_selection()
self._tab.run_js_async( self._js_call('toggle')
javascript.assemble('caret', 'toggle'))
def move_to_next_line(self, count=1): def move_to_next_line(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveDown')
javascript.assemble('caret', 'moveDown'))
def move_to_prev_line(self, count=1): def move_to_prev_line(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveUp')
javascript.assemble('caret', 'moveUp'))
def move_to_next_char(self, count=1): def move_to_next_char(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveRight')
javascript.assemble('caret', 'moveRight'))
def move_to_prev_char(self, count=1): def move_to_prev_char(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveLeft')
javascript.assemble('caret', 'moveLeft'))
def move_to_end_of_word(self, count=1): def move_to_end_of_word(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveToEndOfWord')
javascript.assemble('caret', 'moveToEndOfWord'))
def move_to_next_word(self, count=1): def move_to_next_word(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveToNextWord')
javascript.assemble('caret', 'moveToNextWord'))
def move_to_prev_word(self, count=1): def move_to_prev_word(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveToPreviousWord')
javascript.assemble('caret', 'moveToPreviousWord'))
def move_to_start_of_line(self): def move_to_start_of_line(self):
self._tab.run_js_async( self._js_call('moveToStartOfLine')
javascript.assemble('caret', 'moveToStartOfLine'))
def move_to_end_of_line(self): def move_to_end_of_line(self):
self._tab.run_js_async( self._js_call('moveToEndOfLine')
javascript.assemble('caret', 'moveToEndOfLine'))
def move_to_start_of_next_block(self, count=1): def move_to_start_of_next_block(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveToStartOfNextBlock')
javascript.assemble('caret', 'moveToStartOfNextBlock'))
def move_to_start_of_prev_block(self, count=1): def move_to_start_of_prev_block(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveToStartOfPrevBlock')
javascript.assemble('caret', 'moveToStartOfPrevBlock'))
def move_to_end_of_next_block(self, count=1): def move_to_end_of_next_block(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveToEndOfNextBlock')
javascript.assemble('caret', 'moveToEndOfNextBlock'))
def move_to_end_of_prev_block(self, count=1): def move_to_end_of_prev_block(self, count=1):
for _ in range(count): for _ in range(count):
self._tab.run_js_async( self._js_call('moveToEndOfPrevBlock')
javascript.assemble('caret', 'moveToEndOfPrevBlock'))
def move_to_start_of_document(self): def move_to_start_of_document(self):
self._tab.run_js_async( self._js_call('moveToStartOfDocument')
javascript.assemble('caret', 'moveToStartOfDocument'))
def move_to_end_of_document(self): def move_to_end_of_document(self):
self._tab.run_js_async( self._js_call('moveToEndOfDocument')
javascript.assemble('caret', 'moveToEndOfDocument'))
def toggle_selection(self): def toggle_selection(self):
self._tab.run_js_async( self._js_call('toggleSelection')
javascript.assemble('caret', 'toggleSelection'))
def drop_selection(self): def drop_selection(self):
self._tab.run_js_async( self._js_call('dropSelection')
javascript.assemble('caret', 'dropSelection'))
def has_selection(self): def has_selection(self):
if qtutils.version_check('5.10'): if qtutils.version_check('5.10'):
@ -351,6 +333,10 @@ class WebEngineCaret(browsertab.AbstractCaret):
self._tab.run_js_async(js_code, lambda jsret: self._tab.run_js_async(js_code, lambda jsret:
self._follow_selected_cb(jsret, tab)) self._follow_selected_cb(jsret, tab))
def _js_call(self, command):
self._tab.run_js_async(
javascript.assemble('caret', command))
class WebEngineScroller(browsertab.AbstractScroller): class WebEngineScroller(browsertab.AbstractScroller):