Add separate function in js to set current platform

This commit is contained in:
Artur Shaikhullin 2018-01-19 22:13:47 +06:00
parent 81a9ea58d6
commit 4fde8ff204
2 changed files with 19 additions and 9 deletions

View File

@ -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):

View File

@ -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);
};