From 695f7341429b2b4e68b8aeb08051363f0261af82 Mon Sep 17 00:00:00 2001 From: Artur Shaikhullin Date: Sat, 30 Dec 2017 23:46:04 +0600 Subject: [PATCH] Extract js call method --- qutebrowser/browser/webengine/webenginetab.py | 58 +++++++------------ 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 42cbc3d2a..38a16b323 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -208,87 +208,69 @@ class WebEngineCaret(browsertab.AbstractCaret): @pyqtSlot(usertypes.KeyMode) def _on_mode_left(self): self.drop_selection() - self._tab.run_js_async( - javascript.assemble('caret', 'toggle')) + self._js_call('toggle') def move_to_next_line(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveDown')) + self._js_call('moveDown') def move_to_prev_line(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveUp')) + self._js_call('moveUp') def move_to_next_char(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveRight')) + self._js_call('moveRight') def move_to_prev_char(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveLeft')) + self._js_call('moveLeft') def move_to_end_of_word(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToEndOfWord')) + self._js_call('moveToEndOfWord') def move_to_next_word(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToNextWord')) + self._js_call('moveToNextWord') def move_to_prev_word(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToPreviousWord')) + self._js_call('moveToPreviousWord') def move_to_start_of_line(self): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToStartOfLine')) + self._js_call('moveToStartOfLine') def move_to_end_of_line(self): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToEndOfLine')) + self._js_call('moveToEndOfLine') def move_to_start_of_next_block(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToStartOfNextBlock')) + self._js_call('moveToStartOfNextBlock') def move_to_start_of_prev_block(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToStartOfPrevBlock')) + self._js_call('moveToStartOfPrevBlock') def move_to_end_of_next_block(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToEndOfNextBlock')) + self._js_call('moveToEndOfNextBlock') def move_to_end_of_prev_block(self, count=1): for _ in range(count): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToEndOfPrevBlock')) + self._js_call('moveToEndOfPrevBlock') def move_to_start_of_document(self): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToStartOfDocument')) + self._js_call('moveToStartOfDocument') def move_to_end_of_document(self): - self._tab.run_js_async( - javascript.assemble('caret', 'moveToEndOfDocument')) + self._js_call('moveToEndOfDocument') def toggle_selection(self): - self._tab.run_js_async( - javascript.assemble('caret', 'toggleSelection')) + self._js_call('toggleSelection') def drop_selection(self): - self._tab.run_js_async( - javascript.assemble('caret', 'dropSelection')) + self._js_call('dropSelection') def has_selection(self): if qtutils.version_check('5.10'): @@ -351,6 +333,10 @@ class WebEngineCaret(browsertab.AbstractCaret): self._tab.run_js_async(js_code, lambda jsret: self._follow_selected_cb(jsret, tab)) + def _js_call(self, command): + self._tab.run_js_async( + javascript.assemble('caret', command)) + class WebEngineScroller(browsertab.AbstractScroller):