Implement all caret browsing methods

This commit is contained in:
Artur Shaikhullin 2017-11-21 19:56:00 +06:00
parent 82b1bd10ec
commit 8aca37e5d5
2 changed files with 76 additions and 40 deletions

View File

@ -231,22 +231,28 @@ class WebEngineCaret(browsertab.AbstractCaret):
javascript.assemble('caret', 'moveToEndOfLine'))
def move_to_start_of_next_block(self, count=1):
log.stub()
self._tab.run_js_async(
javascript.assemble('caret', 'moveToStartOfNextBlock'))
def move_to_start_of_prev_block(self, count=1):
log.stub()
self._tab.run_js_async(
javascript.assemble('caret', 'moveToStartOfPrevBlock'))
def move_to_end_of_next_block(self, count=1):
log.stub()
self._tab.run_js_async(
javascript.assemble('caret', 'moveToEndOfNextBlock'))
def move_to_end_of_prev_block(self, count=1):
log.stub()
self._tab.run_js_async(
javascript.assemble('caret', 'moveToEndOfPrevBlock'))
def move_to_start_of_document(self):
log.stub()
self._tab.run_js_async(
javascript.assemble('caret', 'moveToStartOfDocument'))
def move_to_end_of_document(self):
log.stub()
self._tab.run_js_async(
javascript.assemble('caret', 'moveToEndOfDocument'))
def toggle_selection(self):
self._tab.run_js_async(

View File

@ -825,7 +825,6 @@ window._qutebrowser.caret = (function() {
str = word + str;
nodesCrossed = nodesCrossed.concat(newNodesCrossed);
startCursor.copyFrom(wordStartCursor);
v
// Get the previous word and go back to the top of the loop.
newNodesCrossed = [];
word = TraverseUtil.getPreviousWord(
@ -1595,28 +1594,54 @@ window._qutebrowser.caret = (function() {
return result;
};
CaretBrowsing.move = function(direction, granularity) {
window
.getSelection()
.modify(
CaretBrowsing.selectionEnabled ? 'extend' : 'move',
direction,
granularity);
window.setTimeout(function() {
CaretBrowsing.updateCaretOrSelection(true);
}, 0);
}
CaretBrowsing.moveToBlock = function(paragraph, boundary) {
window
.getSelection()
.modify(
CaretBrowsing.selectionEnabled ? 'extend' : 'move',
paragraph,
'paragraph');
window
.getSelection()
.modify(
CaretBrowsing.selectionEnabled ? 'extend' : 'move',
boundary,
'paragraphboundary');
window.setTimeout(function() {
CaretBrowsing.updateCaretOrSelection(true);
}, 0);
}
funcs.moveRight = () => {
var evt = Object.assign({}, document.activeElement);
evt.keyCode = 39;
CaretBrowsing.onKeyDown(evt);
CaretBrowsing.move('right', 'character');
}
funcs.moveLeft = () => {
var evt = Object.assign({}, document.activeElement);
evt.keyCode = 37;
CaretBrowsing.onKeyDown(evt);
CaretBrowsing.move('left', 'character');
}
funcs.moveDown = () => {
var evt = Object.assign({}, document.activeElement);
evt.keyCode = 40;
CaretBrowsing.onKeyDown(evt);
CaretBrowsing.move('forward', 'line');
}
funcs.moveUp = () => {
var evt = Object.assign({}, document.activeElement);
evt.keyCode = 38;
CaretBrowsing.onKeyDown(evt);
CaretBrowsing.move('backward', 'line');
}
funcs.moveToEndOfWord = () => {
@ -1625,40 +1650,45 @@ window._qutebrowser.caret = (function() {
}
funcs.moveToNextWord = () => {
var evt = Object.assign({}, document.activeElement);
evt.keyCode = 39;
evt.ctrlKey = true;
CaretBrowsing.onKeyDown(evt);
CaretBrowsing.move('forward', 'word');
funcs.moveRight();
}
funcs.moveToPreviousWord = () => {
var evt = Object.assign({}, document.activeElement);
evt.keyCode = 37;
evt.ctrlKey = true;
CaretBrowsing.onKeyDown(evt);
CaretBrowsing.move('backward', 'word');
}
funcs.moveToStartOfLine = () => {
CaretBrowsing.moveToLineBoundary('left');
CaretBrowsing.move('left', 'lineboundary');
}
funcs.moveToEndOfLine = () => {
CaretBrowsing.moveToLineBoundary('right');
CaretBrowsing.move('right', 'lineboundary');
}
CaretBrowsing.moveToLineBoundary = function(side) {
window
.getSelection()
.modify(
CaretBrowsing.selectionEnabled ? 'extend' : 'move',
side,
'lineboundary');
funcs.moveToStartOfNextBlock = () => {
CaretBrowsing.moveToBlock('forward', 'backward');
}
window.setTimeout(function() {
CaretBrowsing.updateCaretOrSelection(true);
}, 0);
};
funcs.moveToStartOfPrevBlock = () => {
CaretBrowsing.moveToBlock('backward', 'backward');
}
funcs.moveToEndOfNextBlock = () => {
CaretBrowsing.moveToBlock('forward', 'forward');
}
funcs.moveToEndOfPrevBlock = () => {
CaretBrowsing.moveToBlock('backward', 'forward');
}
funcs.moveToStartOfDocument = () => {
CaretBrowsing.move('backward', 'documentboundary');
}
funcs.moveToEndOfDocument = () => {
CaretBrowsing.move('forward', 'documentboundary');
}
funcs.toggleSelection = () => {
CaretBrowsing.selectionEnabled = !CaretBrowsing.selectionEnabled;