Make sure we only update the caret selection once
Otherwise, stuff goes haywire when trying to use the caret mode very fast (like in a unit test), because new stuff runs before we've managed to update the selection.
This commit is contained in:
parent
db6935b42e
commit
03dea493de
@ -248,7 +248,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
self._tab.run_js_async(
|
self._tab.run_js_async(
|
||||||
javascript.assemble('caret',
|
javascript.assemble('caret',
|
||||||
'setPlatform', sys.platform, qVersion()))
|
'setPlatform', sys.platform, qVersion()))
|
||||||
self._js_call('setInitialCursor', self._selection_cb)
|
self._js_call('setInitialCursor', callback=self._selection_cb)
|
||||||
|
|
||||||
def _selection_cb(self, enabled):
|
def _selection_cb(self, enabled):
|
||||||
"""Emit selection_toggled based on setInitialCursor."""
|
"""Emit selection_toggled based on setInitialCursor."""
|
||||||
@ -266,32 +266,25 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
self._js_call('disableCaret')
|
self._js_call('disableCaret')
|
||||||
|
|
||||||
def move_to_next_line(self, count=1):
|
def move_to_next_line(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveDown', count)
|
||||||
self._js_call('moveDown')
|
|
||||||
|
|
||||||
def move_to_prev_line(self, count=1):
|
def move_to_prev_line(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveUp', count)
|
||||||
self._js_call('moveUp')
|
|
||||||
|
|
||||||
def move_to_next_char(self, count=1):
|
def move_to_next_char(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveRight', count)
|
||||||
self._js_call('moveRight')
|
|
||||||
|
|
||||||
def move_to_prev_char(self, count=1):
|
def move_to_prev_char(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveLeft', count)
|
||||||
self._js_call('moveLeft')
|
|
||||||
|
|
||||||
def move_to_end_of_word(self, count=1):
|
def move_to_end_of_word(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveToEndOfWord', count)
|
||||||
self._js_call('moveToEndOfWord')
|
|
||||||
|
|
||||||
def move_to_next_word(self, count=1):
|
def move_to_next_word(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveToNextWord', count)
|
||||||
self._js_call('moveToNextWord')
|
|
||||||
|
|
||||||
def move_to_prev_word(self, count=1):
|
def move_to_prev_word(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveToPreviousWord', count)
|
||||||
self._js_call('moveToPreviousWord')
|
|
||||||
|
|
||||||
def move_to_start_of_line(self):
|
def move_to_start_of_line(self):
|
||||||
self._js_call('moveToStartOfLine')
|
self._js_call('moveToStartOfLine')
|
||||||
@ -300,20 +293,16 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
self._js_call('moveToEndOfLine')
|
self._js_call('moveToEndOfLine')
|
||||||
|
|
||||||
def move_to_start_of_next_block(self, count=1):
|
def move_to_start_of_next_block(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveToStartOfNextBlock', count)
|
||||||
self._js_call('moveToStartOfNextBlock')
|
|
||||||
|
|
||||||
def move_to_start_of_prev_block(self, count=1):
|
def move_to_start_of_prev_block(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveToStartOfPrevBlock', count)
|
||||||
self._js_call('moveToStartOfPrevBlock')
|
|
||||||
|
|
||||||
def move_to_end_of_next_block(self, count=1):
|
def move_to_end_of_next_block(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveToEndOfNextBlock', count)
|
||||||
self._js_call('moveToEndOfNextBlock')
|
|
||||||
|
|
||||||
def move_to_end_of_prev_block(self, count=1):
|
def move_to_end_of_prev_block(self, count=1):
|
||||||
for _ in range(count):
|
self._js_call('moveToEndOfPrevBlock', count)
|
||||||
self._js_call('moveToEndOfPrevBlock')
|
|
||||||
|
|
||||||
def move_to_start_of_document(self):
|
def move_to_start_of_document(self):
|
||||||
self._js_call('moveToStartOfDocument')
|
self._js_call('moveToStartOfDocument')
|
||||||
@ -322,7 +311,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
self._js_call('moveToEndOfDocument')
|
self._js_call('moveToEndOfDocument')
|
||||||
|
|
||||||
def toggle_selection(self):
|
def toggle_selection(self):
|
||||||
self._js_call('toggleSelection', self.selection_toggled.emit)
|
self._js_call('toggleSelection', callback=self.selection_toggled.emit)
|
||||||
|
|
||||||
def drop_selection(self):
|
def drop_selection(self):
|
||||||
self._js_call('dropSelection')
|
self._js_call('dropSelection')
|
||||||
@ -383,8 +372,9 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
self._tab.run_js_async(js_code, lambda jsret:
|
self._tab.run_js_async(js_code, lambda jsret:
|
||||||
self._follow_selected_cb(jsret, tab))
|
self._follow_selected_cb(jsret, tab))
|
||||||
|
|
||||||
def _js_call(self, command, callback=None):
|
def _js_call(self, command, *args, callback=None):
|
||||||
self._tab.run_js_async(javascript.assemble('caret', command), callback)
|
code = javascript.assemble('caret', command, *args)
|
||||||
|
self._tab.run_js_async(code, callback)
|
||||||
|
|
||||||
|
|
||||||
class WebEngineScroller(browsertab.AbstractScroller):
|
class WebEngineScroller(browsertab.AbstractScroller):
|
||||||
|
@ -1163,34 +1163,39 @@ window._qutebrowser.caret = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CaretBrowsing.move = function(direction, granularity) {
|
CaretBrowsing.move = function(direction, granularity, count = 1) {
|
||||||
let action = "move";
|
let action = "move";
|
||||||
if (CaretBrowsing.selectionEnabled) {
|
if (CaretBrowsing.selectionEnabled) {
|
||||||
action = "extend";
|
action = "extend";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
window.
|
window.
|
||||||
getSelection().
|
getSelection().
|
||||||
modify(action, direction, granularity);
|
modify(action, direction, granularity);
|
||||||
|
}
|
||||||
|
|
||||||
if (CaretBrowsing.isWindows &&
|
if (CaretBrowsing.isWindows &&
|
||||||
(direction === "forward" ||
|
(direction === "forward" ||
|
||||||
direction === "right") &&
|
direction === "right") &&
|
||||||
granularity === "word") {
|
granularity === "word") {
|
||||||
CaretBrowsing.move("left", "character");
|
CaretBrowsing.move("left", "character");
|
||||||
} else {
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
CaretBrowsing.finishMove = function() {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
CaretBrowsing.updateCaretOrSelection(true);
|
CaretBrowsing.updateCaretOrSelection(true);
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
|
||||||
|
|
||||||
CaretBrowsing.stopAnimation();
|
CaretBrowsing.stopAnimation();
|
||||||
};
|
};
|
||||||
|
|
||||||
CaretBrowsing.moveToBlock = function(paragraph, boundary) {
|
CaretBrowsing.moveToBlock = function(paragraph, boundary, count = 1) {
|
||||||
let action = "move";
|
let action = "move";
|
||||||
if (CaretBrowsing.selectionEnabled) {
|
if (CaretBrowsing.selectionEnabled) {
|
||||||
action = "extend";
|
action = "extend";
|
||||||
}
|
}
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
window.
|
window.
|
||||||
getSelection().
|
getSelection().
|
||||||
modify(action, paragraph, "paragraph");
|
modify(action, paragraph, "paragraph");
|
||||||
@ -1198,12 +1203,7 @@ window._qutebrowser.caret = (function() {
|
|||||||
window.
|
window.
|
||||||
getSelection().
|
getSelection().
|
||||||
modify(action, boundary, "paragraphboundary");
|
modify(action, boundary, "paragraphboundary");
|
||||||
|
}
|
||||||
window.setTimeout(() => {
|
|
||||||
CaretBrowsing.updateCaretOrSelection(true);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
CaretBrowsing.stopAnimation();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CaretBrowsing.toggle = function(value) {
|
CaretBrowsing.toggle = function(value) {
|
||||||
@ -1331,67 +1331,80 @@ window._qutebrowser.caret = (function() {
|
|||||||
CaretBrowsing.toggle();
|
CaretBrowsing.toggle();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveRight = () => {
|
funcs.moveRight = (count = 1) => {
|
||||||
|
CaretBrowsing.move("right", "character", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
|
};
|
||||||
|
|
||||||
|
funcs.moveLeft = (count = 1) => {
|
||||||
|
CaretBrowsing.move("left", "character", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
|
};
|
||||||
|
|
||||||
|
funcs.moveDown = (count = 1) => {
|
||||||
|
CaretBrowsing.move("forward", "line", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
|
};
|
||||||
|
|
||||||
|
funcs.moveUp = (count = 1) => {
|
||||||
|
CaretBrowsing.move("backward", "line", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
|
};
|
||||||
|
|
||||||
|
funcs.moveToEndOfWord = (count = 1) => {
|
||||||
|
CaretBrowsing.move("forward", "word", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
|
};
|
||||||
|
|
||||||
|
funcs.moveToNextWord = (count = 1) => {
|
||||||
|
CaretBrowsing.move("forward", "word", count);
|
||||||
CaretBrowsing.move("right", "character");
|
CaretBrowsing.move("right", "character");
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveLeft = () => {
|
funcs.moveToPreviousWord = (count = 1) => {
|
||||||
CaretBrowsing.move("left", "character");
|
CaretBrowsing.move("backward", "word", count);
|
||||||
};
|
CaretBrowsing.finishMove();
|
||||||
|
|
||||||
funcs.moveDown = () => {
|
|
||||||
CaretBrowsing.move("forward", "line");
|
|
||||||
};
|
|
||||||
|
|
||||||
funcs.moveUp = () => {
|
|
||||||
CaretBrowsing.move("backward", "line");
|
|
||||||
};
|
|
||||||
|
|
||||||
funcs.moveToEndOfWord = () => {
|
|
||||||
funcs.moveToNextWord();
|
|
||||||
funcs.moveLeft();
|
|
||||||
};
|
|
||||||
|
|
||||||
funcs.moveToNextWord = () => {
|
|
||||||
CaretBrowsing.move("forward", "word");
|
|
||||||
funcs.moveRight();
|
|
||||||
};
|
|
||||||
|
|
||||||
funcs.moveToPreviousWord = () => {
|
|
||||||
CaretBrowsing.move("backward", "word");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveToStartOfLine = () => {
|
funcs.moveToStartOfLine = () => {
|
||||||
CaretBrowsing.move("left", "lineboundary");
|
CaretBrowsing.move("left", "lineboundary");
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveToEndOfLine = () => {
|
funcs.moveToEndOfLine = () => {
|
||||||
CaretBrowsing.move("right", "lineboundary");
|
CaretBrowsing.move("right", "lineboundary");
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveToStartOfNextBlock = () => {
|
funcs.moveToStartOfNextBlock = (count = 1) => {
|
||||||
CaretBrowsing.moveToBlock("forward", "backward");
|
CaretBrowsing.moveToBlock("forward", "backward", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveToStartOfPrevBlock = () => {
|
funcs.moveToStartOfPrevBlock = (count = 1) => {
|
||||||
CaretBrowsing.moveToBlock("backward", "backward");
|
CaretBrowsing.moveToBlock("backward", "backward", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveToEndOfNextBlock = () => {
|
funcs.moveToEndOfNextBlock = (count = 1) => {
|
||||||
CaretBrowsing.moveToBlock("forward", "forward");
|
CaretBrowsing.moveToBlock("forward", "forward", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveToEndOfPrevBlock = () => {
|
funcs.moveToEndOfPrevBlock = (count = 1) => {
|
||||||
CaretBrowsing.moveToBlock("backward", "forward");
|
CaretBrowsing.moveToBlock("backward", "forward", count);
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveToStartOfDocument = () => {
|
funcs.moveToStartOfDocument = () => {
|
||||||
CaretBrowsing.move("backward", "documentboundary");
|
CaretBrowsing.move("backward", "documentboundary");
|
||||||
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.moveToEndOfDocument = () => {
|
funcs.moveToEndOfDocument = () => {
|
||||||
CaretBrowsing.move("forward", "documentboundary");
|
CaretBrowsing.move("forward", "documentboundary");
|
||||||
funcs.moveLeft();
|
CaretBrowsing.finishMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs.dropSelection = () => {
|
funcs.dropSelection = () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user