Fix selecting text fields with QtWebKit
Using focus() in JS there means that existing text in the field gets selected. Move the cursor to the end after focusing it to prevent that. Fixes #2359
This commit is contained in:
parent
f9697f1ebe
commit
1e1ba34b60
@ -28,6 +28,7 @@ Fixed
|
||||
- URLs are now redacted properly (username/password, and path/query for HTTPS) when using Proxy Autoconfig with QtWebKit
|
||||
- Fixed the web inspector with QtWebEngine
|
||||
- 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
|
||||
|
||||
v0.10.0
|
||||
-------
|
||||
|
@ -326,6 +326,11 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
||||
raise Error("Element position is out of view!")
|
||||
return pos
|
||||
|
||||
def _move_text_cursor(self):
|
||||
"""Move cursor to end after clicking."""
|
||||
if self.is_text_input() and self.is_editable():
|
||||
self._tab.caret.move_to_end_of_document()
|
||||
|
||||
def _click_fake_event(self, click_target):
|
||||
"""Send a fake click event to the element."""
|
||||
pos = self._mouse_pos()
|
||||
@ -356,11 +361,7 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
||||
for evt in events:
|
||||
self._tab.send_event(evt)
|
||||
|
||||
def after_click():
|
||||
"""Move cursor to end after clicking."""
|
||||
if self.is_text_input() and self.is_editable():
|
||||
self._tab.caret.move_to_end_of_document()
|
||||
QTimer.singleShot(0, after_click)
|
||||
QTimer.singleShot(0, self._move_text_cursor)
|
||||
|
||||
def _click_editable(self, click_target):
|
||||
"""Fake a click on an editable input field."""
|
||||
|
@ -302,7 +302,9 @@ class WebKitElement(webelem.AbstractWebElement):
|
||||
|
||||
def _click_editable(self, click_target):
|
||||
ok = self._elem.evaluateJavaScript('this.focus(); true;')
|
||||
if not ok:
|
||||
if ok:
|
||||
self._move_text_cursor()
|
||||
else:
|
||||
log.webelem.debug("Failed to focus via JS, falling back to event")
|
||||
self._click_fake_event(click_target)
|
||||
|
||||
|
@ -4,10 +4,21 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Simple input</title>
|
||||
<script type="text/javascript">
|
||||
function setup_event_listener() {
|
||||
var elem = document.getElementById('qute-input-existing');
|
||||
console.log(elem);
|
||||
elem.addEventListener('input', function() {
|
||||
console.log("contents: " + elem.value);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<body onload="setup_event_listener()">
|
||||
<form><input id="qute-input"></input></form>
|
||||
With padding:
|
||||
<form><input type="text" style="padding-left: 20px;"></input></form>
|
||||
With existing text (logs to JS)::
|
||||
<form><input id="qute-input-existing" value="existing"></input></form>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -188,6 +188,14 @@ Feature: Using hints
|
||||
And I run :hint
|
||||
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
|
||||
When I set general -> log-javascript-console to info
|
||||
And I open data/hints/input.html
|
||||
And I run :click-element id qute-input-existing
|
||||
And I run :fake-key new
|
||||
Then the javascript message "contents: existingnew" should be logged
|
||||
|
||||
### iframes
|
||||
|
||||
@qtwebengine_todo: Hinting in iframes is not implemented yet
|
||||
|
Loading…
Reference in New Issue
Block a user