From 3738a8c8a93405936502db2d2b1aeba2983db029 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 8 Sep 2018 16:20:58 +0200 Subject: [PATCH] Apply caret mode workarounds correctly --- qutebrowser/browser/webengine/webenginetab.py | 15 ++++++++++-- qutebrowser/javascript/caret.js | 23 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index a5367de82..c307df043 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -234,6 +234,17 @@ class WebEngineCaret(browsertab.AbstractCaret): """QtWebEngine implementations related to moving the cursor/selection.""" + def _flags(self): + """Get flags to pass to JS.""" + flags = [] + if qtutils.version_check('5.7.1', compiled=False): + flags.append('filter-prefix') + if not qtutils.version_check('5.10', compiled=False): + flags.append('end-of-doc-workaround') + if utils.is_windows: + flags.append('windows') + return flags + @pyqtSlot(usertypes.KeyMode) def _on_mode_entered(self, mode): if mode != usertypes.KeyMode.caret: @@ -246,8 +257,8 @@ class WebEngineCaret(browsertab.AbstractCaret): self._tab.search.clear() self._tab.run_js_async( - javascript.assemble('caret', - 'setPlatform', sys.platform, qVersion())) + javascript.assemble('caret', 'setFlags', self._flags())) + self._js_call('setInitialCursor', callback=self._selection_cb) def _selection_cb(self, enabled): diff --git a/qutebrowser/javascript/caret.js b/qutebrowser/javascript/caret.js index ecb4f97c8..08d5b7382 100644 --- a/qutebrowser/javascript/caret.js +++ b/qutebrowser/javascript/caret.js @@ -788,9 +788,17 @@ window._qutebrowser.caret = (function() { /** * Whether we're running on on old Qt 5.7.1. + * There, we need to use -webkit-filter. * @type {boolean} */ - CaretBrowsing.isOldQt = null; + CaretBrowsing.needsFilterPrefix = null; + + /** + * Whether we're running on Qt < 5.10. + * There, we need some additional movement workarounds. + * @type {boolean} + */ + CaretBrowsing.needsEndOfDocWorkaround = null; /** * Check if a node is a control that normally allows the user to interact @@ -868,7 +876,7 @@ window._qutebrowser.caret = (function() { }; CaretBrowsing.injectCaretStyles = function() { - const prefix = CaretBrowsing.isOldQt ? "-webkit-" : ""; + const prefix = CaretBrowsing.needsFilterPrefix ? "-webkit-" : ""; const style = ` .CaretBrowsing_Caret { position: absolute; @@ -1322,9 +1330,11 @@ window._qutebrowser.caret = (function() { return CaretBrowsing.selectionEnabled; }; - funcs.setPlatform = (platform, qtVersion) => { - CaretBrowsing.isWindows = platform.startsWith("win"); - CaretBrowsing.isOldQt = qtVersion === "5.7.1"; + funcs.setFlags = (flags) => { + CaretBrowsing.isWindows = flags.includes("windows"); + CaretBrowsing.needsFilterPrefix = flags.includes("filter-prefix"); + CaretBrowsing.needsEndOfDocWorkaround = + flags.includes("end-of-doc-workaround"); }; funcs.disableCaret = () => { @@ -1408,6 +1418,9 @@ window._qutebrowser.caret = (function() { funcs.moveToEndOfDocument = () => { CaretBrowsing.move("forward", "documentboundary"); + if (CaretBrowsing.needsEndOfDocWorkaround) { + CaretBrowsing.move("left", "character"); + } CaretBrowsing.finishMove(); };