Add some movement caret actions
This commit is contained in:
parent
b184d2f94d
commit
82b1bd10ec
@ -179,39 +179,56 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
|
|
||||||
@pyqtSlot(usertypes.KeyMode)
|
@pyqtSlot(usertypes.KeyMode)
|
||||||
def _on_mode_entered(self, mode):
|
def _on_mode_entered(self, mode):
|
||||||
js_code = javascript.assemble('caret', 'setInitialCursor')
|
self._tab.run_js_async(
|
||||||
self._tab.run_js_async(js_code)
|
javascript.assemble('caret', 'setInitialCursor'))
|
||||||
|
|
||||||
@pyqtSlot(usertypes.KeyMode)
|
@pyqtSlot(usertypes.KeyMode)
|
||||||
def _on_mode_left(self):
|
def _on_mode_left(self):
|
||||||
pass
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'toggle'))
|
||||||
|
|
||||||
def move_to_next_line(self, count=1):
|
def move_to_next_line(self, count=1):
|
||||||
log.stub()
|
for _ in range(count):
|
||||||
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveDown'))
|
||||||
|
|
||||||
def move_to_prev_line(self, count=1):
|
def move_to_prev_line(self, count=1):
|
||||||
log.stub()
|
for _ in range(count):
|
||||||
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveUp'))
|
||||||
|
|
||||||
def move_to_next_char(self, count=1):
|
def move_to_next_char(self, count=1):
|
||||||
log.stub()
|
for _ in range(count):
|
||||||
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveRight'))
|
||||||
|
|
||||||
def move_to_prev_char(self, count=1):
|
def move_to_prev_char(self, count=1):
|
||||||
log.stub()
|
for _ in range(count):
|
||||||
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveLeft'))
|
||||||
|
|
||||||
def move_to_end_of_word(self, count=1):
|
def move_to_end_of_word(self, count=1):
|
||||||
log.stub()
|
for _ in range(count):
|
||||||
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveToEndOfWord'))
|
||||||
|
|
||||||
def move_to_next_word(self, count=1):
|
def move_to_next_word(self, count=1):
|
||||||
log.stub()
|
for _ in range(count):
|
||||||
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveToNextWord'))
|
||||||
|
|
||||||
def move_to_prev_word(self, count=1):
|
def move_to_prev_word(self, count=1):
|
||||||
log.stub()
|
for _ in range(count):
|
||||||
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveToPreviousWord'))
|
||||||
|
|
||||||
def move_to_start_of_line(self):
|
def move_to_start_of_line(self):
|
||||||
log.stub()
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveToStartOfLine'))
|
||||||
|
|
||||||
def move_to_end_of_line(self):
|
def move_to_end_of_line(self):
|
||||||
log.stub()
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'moveToEndOfLine'))
|
||||||
|
|
||||||
def move_to_start_of_next_block(self, count=1):
|
def move_to_start_of_next_block(self, count=1):
|
||||||
log.stub()
|
log.stub()
|
||||||
@ -232,7 +249,8 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
log.stub()
|
log.stub()
|
||||||
|
|
||||||
def toggle_selection(self):
|
def toggle_selection(self):
|
||||||
log.stub()
|
self._tab.run_js_async(
|
||||||
|
javascript.assemble('caret', 'toggleSelection'))
|
||||||
|
|
||||||
def drop_selection(self):
|
def drop_selection(self):
|
||||||
log.stub()
|
log.stub()
|
||||||
@ -287,7 +305,6 @@ 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))
|
||||||
|
|
||||||
|
|
||||||
class WebEngineScroller(browsertab.AbstractScroller):
|
class WebEngineScroller(browsertab.AbstractScroller):
|
||||||
|
|
||||||
"""QtWebEngine implementations related to scrolling."""
|
"""QtWebEngine implementations related to scrolling."""
|
||||||
|
@ -1076,7 +1076,15 @@ window._qutebrowser.caret = (function() {
|
|||||||
* first text character in the document.
|
* first text character in the document.
|
||||||
*/
|
*/
|
||||||
funcs.setInitialCursor = () => {
|
funcs.setInitialCursor = () => {
|
||||||
|
if (!CaretBrowsing.initiated) {
|
||||||
CaretBrowsing.setInitialCursor();
|
CaretBrowsing.setInitialCursor();
|
||||||
|
} else {
|
||||||
|
CaretBrowsing.toggle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.toggle = () => {
|
||||||
|
CaretBrowsing.toggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
CaretBrowsing.setInitialCursor = function() {
|
CaretBrowsing.setInitialCursor = function() {
|
||||||
@ -1094,6 +1102,8 @@ window._qutebrowser.caret = (function() {
|
|||||||
}
|
}
|
||||||
CaretBrowsing.setAndValidateSelection(start, start);
|
CaretBrowsing.setAndValidateSelection(start, start);
|
||||||
CaretBrowsing.toggle();
|
CaretBrowsing.toggle();
|
||||||
|
CaretBrowsing.initiated = true;
|
||||||
|
CaretBrowsing.selectionEnabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1534,11 +1544,7 @@ window._qutebrowser.caret = (function() {
|
|||||||
* @return {boolean} True if the cursor should move by word.
|
* @return {boolean} True if the cursor should move by word.
|
||||||
*/
|
*/
|
||||||
CaretBrowsing.isMoveByWordEvent = function(evt) {
|
CaretBrowsing.isMoveByWordEvent = function(evt) {
|
||||||
if (CaretBrowsing.isMac) {
|
|
||||||
return evt.altKey;
|
|
||||||
} else {
|
|
||||||
return evt.ctrlKey;
|
return evt.ctrlKey;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1589,6 +1595,75 @@ window._qutebrowser.caret = (function() {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
funcs.moveRight = () => {
|
||||||
|
var evt = Object.assign({}, document.activeElement);
|
||||||
|
evt.keyCode = 39;
|
||||||
|
CaretBrowsing.onKeyDown(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.moveLeft = () => {
|
||||||
|
var evt = Object.assign({}, document.activeElement);
|
||||||
|
evt.keyCode = 37;
|
||||||
|
CaretBrowsing.onKeyDown(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.moveDown = () => {
|
||||||
|
var evt = Object.assign({}, document.activeElement);
|
||||||
|
evt.keyCode = 40;
|
||||||
|
CaretBrowsing.onKeyDown(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.moveUp = () => {
|
||||||
|
var evt = Object.assign({}, document.activeElement);
|
||||||
|
evt.keyCode = 38;
|
||||||
|
CaretBrowsing.onKeyDown(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.moveToEndOfWord = () => {
|
||||||
|
funcs.moveToNextWord();
|
||||||
|
funcs.moveLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.moveToNextWord = () => {
|
||||||
|
var evt = Object.assign({}, document.activeElement);
|
||||||
|
evt.keyCode = 39;
|
||||||
|
evt.ctrlKey = true;
|
||||||
|
CaretBrowsing.onKeyDown(evt);
|
||||||
|
funcs.moveRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.moveToPreviousWord = () => {
|
||||||
|
var evt = Object.assign({}, document.activeElement);
|
||||||
|
evt.keyCode = 37;
|
||||||
|
evt.ctrlKey = true;
|
||||||
|
CaretBrowsing.onKeyDown(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.moveToStartOfLine = () => {
|
||||||
|
CaretBrowsing.moveToLineBoundary('left');
|
||||||
|
}
|
||||||
|
|
||||||
|
funcs.moveToEndOfLine = () => {
|
||||||
|
CaretBrowsing.moveToLineBoundary('right');
|
||||||
|
}
|
||||||
|
|
||||||
|
CaretBrowsing.moveToLineBoundary = function(side) {
|
||||||
|
window
|
||||||
|
.getSelection()
|
||||||
|
.modify(
|
||||||
|
CaretBrowsing.selectionEnabled ? 'extend' : 'move',
|
||||||
|
side,
|
||||||
|
'lineboundary');
|
||||||
|
|
||||||
|
window.setTimeout(function() {
|
||||||
|
CaretBrowsing.updateCaretOrSelection(true);
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
funcs.toggleSelection = () => {
|
||||||
|
CaretBrowsing.selectionEnabled = !CaretBrowsing.selectionEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user presses the right arrow. If there's a selection,
|
* Called when the user presses the right arrow. If there's a selection,
|
||||||
* moves the cursor to the end of the selection range. If it's a cursor,
|
* moves the cursor to the end of the selection range. If it's a cursor,
|
||||||
@ -2002,24 +2077,15 @@ window._qutebrowser.caret = (function() {
|
|||||||
* @return {boolean} True if the default action should be performed.
|
* @return {boolean} True if the default action should be performed.
|
||||||
*/
|
*/
|
||||||
CaretBrowsing.onKeyDown = function(evt) {
|
CaretBrowsing.onKeyDown = function(evt) {
|
||||||
if (evt.defaultPrevented) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.keyCode == 118) { // F7
|
|
||||||
CaretBrowsing.toggle();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CaretBrowsing.isEnabled) {
|
if (!CaretBrowsing.isEnabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evt.shiftKey = CaretBrowsing.selectionEnabled;
|
||||||
if (evt.target && CaretBrowsing.isControlThatNeedsArrowKeys(
|
if (evt.target && CaretBrowsing.isControlThatNeedsArrowKeys(
|
||||||
/** @type (Node) */(evt.target))) {
|
/** @type (Node) */(evt.target))) {
|
||||||
if (evt.keyCode == 27) {
|
if (evt.keyCode == 27) {
|
||||||
CaretBrowsing.escapeFromControl(/** @type {Node} */(evt.target));
|
CaretBrowsing.escapeFromControl(/** @type {Node} */(evt.target));
|
||||||
evt.preventDefault();
|
|
||||||
evt.stopPropagation();
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
@ -2062,11 +2128,6 @@ window._qutebrowser.caret = (function() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == false) {
|
|
||||||
evt.preventDefault();
|
|
||||||
evt.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
CaretBrowsing.updateCaretOrSelection(result == false);
|
CaretBrowsing.updateCaretOrSelection(result == false);
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -2161,7 +2222,7 @@ window._qutebrowser.caret = (function() {
|
|||||||
CaretBrowsing.init = function() {
|
CaretBrowsing.init = function() {
|
||||||
CaretBrowsing.isWindowFocused = document.hasFocus();
|
CaretBrowsing.isWindowFocused = document.hasFocus();
|
||||||
|
|
||||||
document.addEventListener('keydown', CaretBrowsing.onKeyDown, false);
|
// document.addEventListener('keydown', CaretBrowsing.onKeyDown, false);
|
||||||
document.addEventListener('click', CaretBrowsing.onClick, false);
|
document.addEventListener('click', CaretBrowsing.onClick, false);
|
||||||
window.addEventListener('focus', CaretBrowsing.onWindowFocus, false);
|
window.addEventListener('focus', CaretBrowsing.onWindowFocus, false);
|
||||||
window.addEventListener('blur', CaretBrowsing.onWindowBlur, false);
|
window.addEventListener('blur', CaretBrowsing.onWindowBlur, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user