Move cursor to end with input elements on QtWebEngine

This commit is contained in:
Florian Bruhin 2017-03-01 17:30:48 +01:00
parent 1e1ba34b60
commit bc0a9cd94d
7 changed files with 19 additions and 9 deletions

View File

@ -29,6 +29,7 @@ Fixed
- Fixed the web inspector with QtWebEngine - Fixed the web inspector with QtWebEngine
- Version checks when starting qutebrowser now also take the Qt version PyQt was compiled against into account - Version checks when starting qutebrowser now also take the Qt version PyQt was compiled against into account
- Hinting a input now doesn't select existing text anymore with QtWebKit - Hinting a input now doesn't select existing text anymore with QtWebKit
- The cursor now moves to the end when input elements are selected with QtWebEngine
v0.10.0 v0.10.0
------- -------

View File

@ -328,8 +328,7 @@ class AbstractWebElement(collections.abc.MutableMapping):
def _move_text_cursor(self): def _move_text_cursor(self):
"""Move cursor to end after clicking.""" """Move cursor to end after clicking."""
if self.is_text_input() and self.is_editable(): raise NotImplementedError
self._tab.caret.move_to_end_of_document()
def _click_fake_event(self, click_target): def _click_fake_event(self, click_target):
"""Send a fake click event to the element.""" """Send a fake click event to the element."""

View File

@ -157,6 +157,12 @@ class WebEngineElement(webelem.AbstractWebElement):
self._id) self._id)
self._tab.run_js_async(js_code) self._tab.run_js_async(js_code)
def _move_text_cursor(self):
if self.is_text_input() and self.is_editable():
js_code = javascript.assemble('webelem', 'move_cursor_to_end',
self._id)
self._tab.run_js_async(js_code)
def _click_editable(self, click_target): def _click_editable(self, click_target):
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-58515 # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-58515
# pylint doesn't know about Qt.MouseEventSynthesizedBySystem # pylint doesn't know about Qt.MouseEventSynthesizedBySystem
@ -171,6 +177,7 @@ class WebEngineElement(webelem.AbstractWebElement):
# This actually "clicks" the element by calling focus() on it in JS. # This actually "clicks" the element by calling focus() on it in JS.
js_code = javascript.assemble('webelem', 'focus', self._id) js_code = javascript.assemble('webelem', 'focus', self._id)
self._tab.run_js_async(js_code) self._tab.run_js_async(js_code)
self._move_text_cursor()
def _click_js(self, _click_target): def _click_js(self, _click_target):
settings = QWebEngineSettings.globalSettings() settings = QWebEngineSettings.globalSettings()

View File

@ -300,6 +300,10 @@ class WebKitElement(webelem.AbstractWebElement):
break break
elem = elem._parent() # pylint: disable=protected-access elem = elem._parent() # pylint: disable=protected-access
def _move_text_cursor(self):
if self.is_text_input() and self.is_editable():
self._tab.caret.move_to_end_of_document()
def _click_editable(self, click_target): def _click_editable(self, click_target):
ok = self._elem.evaluateJavaScript('this.focus(); true;') ok = self._elem.evaluateJavaScript('this.focus(); true;')
if ok: if ok:

View File

@ -203,5 +203,11 @@ window._qutebrowser.webelem = (function() {
elem.focus(); elem.focus();
}; };
funcs.move_cursor_to_end = function(id) {
var elem = elements[id];
elem.selectionStart = elem.value.length;
elem.selectionEnd = elem.value.length;
};
return funcs; return funcs;
})(); })();

View File

@ -188,7 +188,6 @@ Feature: Using hints
And I run :hint And I run :hint
Then the error "No elements found." should be shown Then the error "No elements found." should be shown
@qtwebengine_todo: Doesn't move the cursor to the end
Scenario: Clicking input with existing text Scenario: Clicking input with existing text
When I set general -> log-javascript-console to info When I set general -> log-javascript-console to info
And I open data/hints/input.html And I open data/hints/input.html

View File

@ -48,12 +48,6 @@ def test_insert_mode(file_name, elem_id, source, input_text, auto_insert, zoom,
if source == 'keypress': if source == 'keypress':
quteproc.press_keys(input_text) quteproc.press_keys(input_text)
elif source == 'clipboard': elif source == 'clipboard':
if request.config.webengine:
pytest.xfail(reason="QtWebEngine TODO: caret mode is not "
"implemented")
# Note we actually run the keypress tests with QtWebEngine, as for
# some reason it selects all the text when clicking the field the
# second time.
quteproc.send_cmd(':debug-set-fake-clipboard "{}"'.format(input_text)) quteproc.send_cmd(':debug-set-fake-clipboard "{}"'.format(input_text))
quteproc.send_cmd(':insert-text {clipboard}') quteproc.send_cmd(':insert-text {clipboard}')
else: else: