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(
|
||||
javascript.assemble('caret',
|
||||
'setPlatform', sys.platform, qVersion()))
|
||||
self._js_call('setInitialCursor', self._selection_cb)
|
||||
self._js_call('setInitialCursor', callback=self._selection_cb)
|
||||
|
||||
def _selection_cb(self, enabled):
|
||||
"""Emit selection_toggled based on setInitialCursor."""
|
||||
@ -266,32 +266,25 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
||||
self._js_call('disableCaret')
|
||||
|
||||
def move_to_next_line(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveDown')
|
||||
self._js_call('moveDown', count)
|
||||
|
||||
def move_to_prev_line(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveUp')
|
||||
self._js_call('moveUp', count)
|
||||
|
||||
def move_to_next_char(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveRight')
|
||||
self._js_call('moveRight', count)
|
||||
|
||||
def move_to_prev_char(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveLeft')
|
||||
self._js_call('moveLeft', count)
|
||||
|
||||
def move_to_end_of_word(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveToEndOfWord')
|
||||
self._js_call('moveToEndOfWord', count)
|
||||
|
||||
def move_to_next_word(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveToNextWord')
|
||||
self._js_call('moveToNextWord', count)
|
||||
|
||||
def move_to_prev_word(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveToPreviousWord')
|
||||
self._js_call('moveToPreviousWord', count)
|
||||
|
||||
def move_to_start_of_line(self):
|
||||
self._js_call('moveToStartOfLine')
|
||||
@ -300,20 +293,16 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
||||
self._js_call('moveToEndOfLine')
|
||||
|
||||
def move_to_start_of_next_block(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveToStartOfNextBlock')
|
||||
self._js_call('moveToStartOfNextBlock', count)
|
||||
|
||||
def move_to_start_of_prev_block(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveToStartOfPrevBlock')
|
||||
self._js_call('moveToStartOfPrevBlock', count)
|
||||
|
||||
def move_to_end_of_next_block(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveToEndOfNextBlock')
|
||||
self._js_call('moveToEndOfNextBlock', count)
|
||||
|
||||
def move_to_end_of_prev_block(self, count=1):
|
||||
for _ in range(count):
|
||||
self._js_call('moveToEndOfPrevBlock')
|
||||
self._js_call('moveToEndOfPrevBlock', count)
|
||||
|
||||
def move_to_start_of_document(self):
|
||||
self._js_call('moveToStartOfDocument')
|
||||
@ -322,7 +311,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
||||
self._js_call('moveToEndOfDocument')
|
||||
|
||||
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):
|
||||
self._js_call('dropSelection')
|
||||
@ -383,8 +372,9 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
||||
self._tab.run_js_async(js_code, lambda jsret:
|
||||
self._follow_selected_cb(jsret, tab))
|
||||
|
||||
def _js_call(self, command, callback=None):
|
||||
self._tab.run_js_async(javascript.assemble('caret', command), callback)
|
||||
def _js_call(self, command, *args, callback=None):
|
||||
code = javascript.assemble('caret', command, *args)
|
||||
self._tab.run_js_async(code, callback)
|
||||
|
||||
|
||||
class WebEngineScroller(browsertab.AbstractScroller):
|
||||
|
@ -1163,47 +1163,47 @@ window._qutebrowser.caret = (function() {
|
||||
}
|
||||
};
|
||||
|
||||
CaretBrowsing.move = function(direction, granularity) {
|
||||
CaretBrowsing.move = function(direction, granularity, count = 1) {
|
||||
let action = "move";
|
||||
if (CaretBrowsing.selectionEnabled) {
|
||||
action = "extend";
|
||||
}
|
||||
window.
|
||||
getSelection().
|
||||
modify(action, direction, granularity);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
window.
|
||||
getSelection().
|
||||
modify(action, direction, granularity);
|
||||
}
|
||||
|
||||
if (CaretBrowsing.isWindows &&
|
||||
(direction === "forward" ||
|
||||
direction === "right") &&
|
||||
granularity === "word") {
|
||||
CaretBrowsing.move("left", "character");
|
||||
} else {
|
||||
window.setTimeout(() => {
|
||||
CaretBrowsing.updateCaretOrSelection(true);
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
CaretBrowsing.finishMove = function() {
|
||||
window.setTimeout(() => {
|
||||
CaretBrowsing.updateCaretOrSelection(true);
|
||||
}, 0);
|
||||
CaretBrowsing.stopAnimation();
|
||||
};
|
||||
|
||||
CaretBrowsing.moveToBlock = function(paragraph, boundary) {
|
||||
CaretBrowsing.moveToBlock = function(paragraph, boundary, count = 1) {
|
||||
let action = "move";
|
||||
if (CaretBrowsing.selectionEnabled) {
|
||||
action = "extend";
|
||||
}
|
||||
window.
|
||||
getSelection().
|
||||
modify(action, paragraph, "paragraph");
|
||||
for (let i = 0; i < count; i++) {
|
||||
window.
|
||||
getSelection().
|
||||
modify(action, paragraph, "paragraph");
|
||||
|
||||
window.
|
||||
getSelection().
|
||||
modify(action, boundary, "paragraphboundary");
|
||||
|
||||
window.setTimeout(() => {
|
||||
CaretBrowsing.updateCaretOrSelection(true);
|
||||
}, 0);
|
||||
|
||||
CaretBrowsing.stopAnimation();
|
||||
window.
|
||||
getSelection().
|
||||
modify(action, boundary, "paragraphboundary");
|
||||
}
|
||||
};
|
||||
|
||||
CaretBrowsing.toggle = function(value) {
|
||||
@ -1331,67 +1331,80 @@ window._qutebrowser.caret = (function() {
|
||||
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.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveLeft = () => {
|
||||
CaretBrowsing.move("left", "character");
|
||||
};
|
||||
|
||||
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.moveToPreviousWord = (count = 1) => {
|
||||
CaretBrowsing.move("backward", "word", count);
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveToStartOfLine = () => {
|
||||
CaretBrowsing.move("left", "lineboundary");
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveToEndOfLine = () => {
|
||||
CaretBrowsing.move("right", "lineboundary");
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveToStartOfNextBlock = () => {
|
||||
CaretBrowsing.moveToBlock("forward", "backward");
|
||||
funcs.moveToStartOfNextBlock = (count = 1) => {
|
||||
CaretBrowsing.moveToBlock("forward", "backward", count);
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveToStartOfPrevBlock = () => {
|
||||
CaretBrowsing.moveToBlock("backward", "backward");
|
||||
funcs.moveToStartOfPrevBlock = (count = 1) => {
|
||||
CaretBrowsing.moveToBlock("backward", "backward", count);
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveToEndOfNextBlock = () => {
|
||||
CaretBrowsing.moveToBlock("forward", "forward");
|
||||
funcs.moveToEndOfNextBlock = (count = 1) => {
|
||||
CaretBrowsing.moveToBlock("forward", "forward", count);
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveToEndOfPrevBlock = () => {
|
||||
CaretBrowsing.moveToBlock("backward", "forward");
|
||||
funcs.moveToEndOfPrevBlock = (count = 1) => {
|
||||
CaretBrowsing.moveToBlock("backward", "forward", count);
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveToStartOfDocument = () => {
|
||||
CaretBrowsing.move("backward", "documentboundary");
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.moveToEndOfDocument = () => {
|
||||
CaretBrowsing.move("forward", "documentboundary");
|
||||
funcs.moveLeft();
|
||||
CaretBrowsing.finishMove();
|
||||
};
|
||||
|
||||
funcs.dropSelection = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user