New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use IME/accessibility to find out about editable fields #2471
Comments
From @amosbird focusObject = QApplication.focusObject()
if not focusObject:
log.misc.info('bad')
return
query = QInputMethodQueryEvent(Qt.ImCursorRectangle);
QApplication.sendEvent(focusObject, query);
r = query.value(Qt.ImCursorRectangle);
if r:
log.misc.info('good')
else:
log.misc.info('bad') If that works reliably, it might be able to replace a lot of custom logic with better results. Ideally, we'd even have a way to get a signal on changes without having to turn on accessibility (which IIRC results in QtWebEngine slowing down significantly and might not even be exposed to PyQt/qutebrowser). Certainly invites some more investigation sooner rather than later. |
I digged into this a bit more today, and probably found the holy grail 🎉 Turns out, we don't actually have to implement a custom IME to get events from Qt when a cursor appears/disappears! Instead, we can access the existing from PyQt5.QtWidgets import QApplication
QApplication.inputMethod().cursorRectangleChanged.connect(lambda: print(QApplication.inputMethod().cursorRectangle())) This is likely going to cause a couple of false-positives (when the cursor is moved due to relayouting and such?), but I suppose we could do something like Either way: This would probably allow us to have insert mode entered as soon as a blinking cursor appears somewhere, while getting rid of a lot of heuristics! Open questions:
Resources: |
Might be possible to just use |
I've been testing a few of my absolute favourite web assets with the cursor rectangle changed event. It works pretty well. Beyond that I have two heuristics.
very WIP patch
Decoupling the entry of insert mode from clicking is quite the difference in behaviour in some cases. For instance slack focuses the message entry box whenever the webpage is focused, including when exiting command mode, and when switching between channels. Perhaps doing the ImEnabled query on click would help with the "clicking on editable things" detection and there could be a new setting to enable this mode. The auto enter/exit mode ones could use per-url enabling too. I've had good results with the existing is editable detection by getting rid of the button press handling path and just always doing it on button release. This helps with sites that create an editable element from a button like with jira comments where by the time the JS runs for the release event the new text box is focused. Changing the existing is_editable check for querying ImEnabled may require adding an extra delay to get that benefit (the webelem click code would have to be changed to generate real mouse events to focus the element so that hinting non-editable elements would change mode correctly). Presumably we would still want to inspect elements for editableness without focusing them in some cases? |
Hey there, I've noticed that this issue (where there is a blinking cursor, but the browser isn't in insert mode) is happening so often to me, that my muscle memory has lost any trust in the browser and I'm clicking / firing commands multiple times for any input. I'm wondering if people struggle with input fields (faked / shadow dom / js) not triggering insert mode, and if there are workarounds or ways to improve it. |
@andys8 Sorry for the delay, I was taking a break from things for a bit. I suppose you could try playing with the |
Here's an updated version of the patch @toofar posted above. Updated Patch for 3.x
Seems to work for me with the 3.x branch |
Currently we use a heuristic to find out whether editable elements are clicked. We might be able to hook into a QInputMethodEvent instead (though Qt 5.8 with QtWebEngine has some issues there...)
The text was updated successfully, but these errors were encountered: