diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index ea646cda3..128b4c945 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -21,7 +21,7 @@ import math import functools -import platform +import sys import html as html_utils import sip @@ -206,8 +206,8 @@ class WebEngineCaret(browsertab.AbstractCaret): return self._tab.run_js_async( - javascript.assemble('caret', 'setInitialCursor', - platform.platform())) + javascript.assemble('caret', 'setPlatform', sys.platform)) + self._js_call('setInitialCursor') @pyqtSlot(usertypes.KeyMode) def _on_mode_left(self): diff --git a/qutebrowser/javascript/webengine_caret.js b/qutebrowser/javascript/webengine_caret.js index 052d3a4c1..7dafd9136 100644 --- a/qutebrowser/javascript/webengine_caret.js +++ b/qutebrowser/javascript/webengine_caret.js @@ -707,6 +707,12 @@ window._qutebrowser.caret = (function() { */ CaretBrowsing.blinkFlag = true; + /** + * The os that user is using. + * @type {boolean} + */ + CaretBrowsing.platform = null; + /** * Check if a node is a control that normally allows the user to interact * with it using arrow keys. We won't override the arrow keys when such a @@ -814,9 +820,9 @@ window._qutebrowser.caret = (function() { * If there's no initial selection, set the cursor just before the * first text character in the document. */ - CaretBrowsing.setInitialCursor = function(platform) { - if (platform) { - CaretBrowsing.isWindows = platform.indexOf("Windows") !== -1; + CaretBrowsing.setInitialCursor = function() { + if (CaretBrowsing.platform) { + CaretBrowsing.isWindows = CaretBrowsing.platform.startsWith("win"); } const selectionRange = window.getSelection().toString().length; if (selectionRange === 0) { @@ -1252,7 +1258,7 @@ window._qutebrowser.caret = (function() { CaretBrowsing.isCaretVisible = (CaretBrowsing.isEnabled && CaretBrowsing.isWindowFocused); if (CaretBrowsing.isCaretVisible && !CaretBrowsing.caretElement) { - CaretBrowsing.setInitialCursor(CaretBrowsing.isWindows); + CaretBrowsing.setInitialCursor(); CaretBrowsing.updateCaretOrSelection(true); if (CaretBrowsing.caretElement) { CaretBrowsing.blinkFunctionId = window.setInterval( @@ -1304,9 +1310,9 @@ window._qutebrowser.caret = (function() { const funcs = {}; - funcs.setInitialCursor = (platform) => { + funcs.setInitialCursor = () => { if (!CaretBrowsing.initiated) { - CaretBrowsing.setInitialCursor(platform); + CaretBrowsing.setInitialCursor(); return; } @@ -1316,6 +1322,10 @@ window._qutebrowser.caret = (function() { CaretBrowsing.toggle(); }; + funcs.setPlatform = (platform) => { + CaretBrowsing.platform = platform; + } + funcs.disableCaret = () => { CaretBrowsing.toggle(false); };