Skip to content
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

Android: Samsung Keyboards "Predictive text" breaks editor state when autocompleting #1504

Open
AlexGrafl opened this issue Jan 14, 2025 · 5 comments

Comments

@AlexGrafl
Copy link

AlexGrafl commented Jan 14, 2025

Describe the issue

When using a Samsung device with the (unfortunately by default) enabled "Predictive text" feature, choosing an option from the autocomplete dropdown will break the editor state and cause unwanted cursor positioning and editing. This behavior is not observed when accepting the option using the enter key on the softkeyboard or when disabling "Predictive text".

Steps to reproduce:

  • Open https://codemirror.net/try/ on a Samsung device (make sure "Predictive text" is enabled in Samsung Keyboard settings)
  • Type i.e. fun and chose the function definition by tapping on the option in the dropdown
  • Observe most of the function definition is underlined and typing causes it to be replaced partially
  • Further typing and/or placing the selection somewhere else might not work (although I could not reproduce this reliably, but sometimes it does not allow text to be deleted/replaced/selected)
editor_break_after_autocomplete.mp4

Browser and platform

Android 15
Chrome 131.0.6778.200
Samsung Keyboard 5.8.20.7

Reproduction link

https://codemirror.net/try/

@marijnh
Copy link
Member

marijnh commented Jan 14, 2025

There's an attribute that is supposed to turn this off, and Safari respects it (see also #1486), but I'm not super surprised Samsung's browser would ignore that. You could try reporting both the invasive app-breaking behavior and the ignoring of that attribute as bugs via the built-in error reporting feature (but I don't really expect much of a useful response from the company). Beyond that, it may be hard to fix this. CodeMirror is kind of at the mercy of the platform, and when the platform is a crude custom browser like this, which implements their predictive text in an invasive and poorly considered way, that kind of pulls the rug from under us.

@AlexGrafl
Copy link
Author

Thanks for the fast response. I understand, unfortunately the browser in question is Chrome and the same behavior can also be observed when using CodeMirror in an Android WebView, both of which should be supporting the attribute.
Any idea why the behavior is different when choosing an option from the dropdown versus using the enter key to accept?

@marijnh
Copy link
Member

marijnh commented Jan 14, 2025

No idea. I will try to get my hands on a Samsung device to poke around at this.

@AlexGrafl
Copy link
Author

I investigated a bit more, as a previous PoC we evaluated did not exhibit the same issues and found that this behavior is only present when using @codemirror/view version 6.34.3 or later. Could this be caused by codemirror/view@9658d5e ?

marijnh added a commit to codemirror/view that referenced this issue Jan 28, 2025
FIX: Work around an issue with Chrome's `EditContext` that shows up
when using autocompletion while composing with Samsung's virtual Android
keyboard.

Issue codemirror/dev#1504
@marijnh
Copy link
Member

marijnh commented Jan 28, 2025

This issue appears to be another symptom of #1472 . The Samsung keyboard doesn't abort its composition when the composed word is replaced, which leaves the edit context stuck in a composition that no longer reflects the text, making it impossible to properly interpret further changes originating from it.

Attached patch should limit the damage from this. But it doesn't really solve the family of issues in a fundamental way. I'm considering disabling our use of EditorContext use again, since w3c/edit-context#111 doesn't show much activity, and is not something that can be worked around properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants