Apply caret mode workarounds correctly

This commit is contained in:
Florian Bruhin 2018-09-08 16:20:58 +02:00
parent 1647c28632
commit 3738a8c8a9
2 changed files with 31 additions and 7 deletions

View File

@ -234,6 +234,17 @@ class WebEngineCaret(browsertab.AbstractCaret):
"""QtWebEngine implementations related to moving the cursor/selection.""" """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) @pyqtSlot(usertypes.KeyMode)
def _on_mode_entered(self, mode): def _on_mode_entered(self, mode):
if mode != usertypes.KeyMode.caret: if mode != usertypes.KeyMode.caret:
@ -246,8 +257,8 @@ class WebEngineCaret(browsertab.AbstractCaret):
self._tab.search.clear() self._tab.search.clear()
self._tab.run_js_async( self._tab.run_js_async(
javascript.assemble('caret', javascript.assemble('caret', 'setFlags', self._flags()))
'setPlatform', sys.platform, qVersion()))
self._js_call('setInitialCursor', callback=self._selection_cb) self._js_call('setInitialCursor', callback=self._selection_cb)
def _selection_cb(self, enabled): def _selection_cb(self, enabled):

View File

@ -788,9 +788,17 @@ window._qutebrowser.caret = (function() {
/** /**
* Whether we're running on on old Qt 5.7.1. * Whether we're running on on old Qt 5.7.1.
* There, we need to use -webkit-filter.
* @type {boolean} * @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 * 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() { CaretBrowsing.injectCaretStyles = function() {
const prefix = CaretBrowsing.isOldQt ? "-webkit-" : ""; const prefix = CaretBrowsing.needsFilterPrefix ? "-webkit-" : "";
const style = ` const style = `
.CaretBrowsing_Caret { .CaretBrowsing_Caret {
position: absolute; position: absolute;
@ -1322,9 +1330,11 @@ window._qutebrowser.caret = (function() {
return CaretBrowsing.selectionEnabled; return CaretBrowsing.selectionEnabled;
}; };
funcs.setPlatform = (platform, qtVersion) => { funcs.setFlags = (flags) => {
CaretBrowsing.isWindows = platform.startsWith("win"); CaretBrowsing.isWindows = flags.includes("windows");
CaretBrowsing.isOldQt = qtVersion === "5.7.1"; CaretBrowsing.needsFilterPrefix = flags.includes("filter-prefix");
CaretBrowsing.needsEndOfDocWorkaround =
flags.includes("end-of-doc-workaround");
}; };
funcs.disableCaret = () => { funcs.disableCaret = () => {
@ -1408,6 +1418,9 @@ window._qutebrowser.caret = (function() {
funcs.moveToEndOfDocument = () => { funcs.moveToEndOfDocument = () => {
CaretBrowsing.move("forward", "documentboundary"); CaretBrowsing.move("forward", "documentboundary");
if (CaretBrowsing.needsEndOfDocWorkaround) {
CaretBrowsing.move("left", "character");
}
CaretBrowsing.finishMove(); CaretBrowsing.finishMove();
}; };