florisboard / florisboard

An open-source keyboard for Android which respects your privacy. Currently in early-beta.
https://florisboard.org
Apache License 2.0
5.61k stars 379 forks source link

Clear input cache on input restart #1916

Closed yourealwaysbe closed 1 year ago

yourealwaysbe commented 2 years ago

If input is restarted on a field (e.g. if the text is changed outside of FlorisBoard), then the expectedContentQueue is not cleared. It is only cleared in the onFinishInput methods, which are not called on restart. Since a restart can imply the contents of the editable have changed, i think the expectedContentQueue also needs refreshing.

Specifically (ignore if not needed), i have this inputconnection in my app. It's a crossword app, the view is of the whole board, but the input connection is supposed to simulate editing a single cell in the grid. Initially, the EditorInfo returns the contents of the cell, and a selection covering all the contents. Each time a cell is filled, the highlight moves to the next cell, so the contents of the input connection are refreshed to the next cell, and a restart triggered. With FlorisBoard, pressing delete right away clears the cell as expected (the cell contents are replaced with ""). However, if i enter (say) 3 characters, the highlight moves, and the letters go in the right place, but if i press delete, no replace is called (after 3 deletes i think it falls back to hardware key events). As a current workaround i am overriding BaseInputConnection's deleteSurroundingText to capture the delete, which i think is called from deleteBackwards in EditorInstance.kt, because it's trying to delete three characters that aren't there (in the current cell).

Apologies if i misunderstand something about IMEs: i'm still learning.

patrickgold commented 2 years ago

Thanks for your bug report!

Indeed you are correct, the expected content queue is not reset for restarts. I've now provided a fix in above linked commit (tested out with other apps and debugger) and it should now reset properly using the code base from above PR.

If possible, could you test the input connection now either with the artifact debug APK or by building the PR's branch yourself to check if it now works properly for you? If you find another state issue don't hesitate to mention it so I can have a look.

after 3 deletes i think it falls back to hardware key events

FlorisBoard falls back to hardware delete if a rich editor reports selection 0,0 with no text, because then the logic doesn't know if the editor is really empty or has text but is being lied to. This is a thing, because some apps have really weird and bugged out logic, so I had to implement this fallback. Alternatively if your app presents itself as a raw editor, FlorisBoard will always send hardware delete.

Apologies if i misunderstand something about IMEs: i'm still learning.

No worries, even I am still learning a little bit about IMEs (especially the input connection handling), because app devs find soo many creative and different ways to send input, it is really astonishing :)

yourealwaysbe commented 2 years ago

If possible, could you test the input connection now either with the artifact debug APK or by building the PR's branch yourself to check if it now works properly for you? If you find another state issue don't hesitate to mention it so I can have a look.

Great, thanks. I'm tied up today, but will try tomorrow.

yourealwaysbe commented 2 years ago

If possible, could you test the input connection now either with the artifact debug APK or by building the PR's branch yourself to check if it now works properly for you? If you find another state issue don't hesitate to mention it so I can have a look.

Works as expected, thanks!