Apply caret mode workarounds correctly
This commit is contained in:
parent
1647c28632
commit
3738a8c8a9
@ -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):
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user