codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.44k stars 343 forks source link

Cursor gets stuck when typing at the end of a line on an Android device #1358

Closed lovelle-cardoso closed 2 months ago

lovelle-cardoso commented 3 months ago

Describe the issue

Reproduction Steps:

  1. On an android device, load any codemirror editor that uses a language package. (The example editors on https://codemirror.net/examples/lang-package and https://codemirror.net/examples/mixed-language both exhibit this bug on my Android phone.)

  2. Try typing test at the end of any line in the editor.

Expected Result:

The word test is typed at the end of the line.

Actual Result:

Because the cursor gets stuck for the first two characters, instead of typing test the editor types stet

Additional Notes:

We noticed this bug in our editor after updating our codemirror packages to the latest version. This bug seems to only appear on Android. It works fine on iOS and desktop. It also seems to only happen in the language package examples on the codemirror website. The other examples work fine.

AndroidKeyboardBug

Browser and platform

Android, Samsung Galaxy 10+, Samsung Mobile Browser & Chrome Mobile Browser, Default android keyboard

Reproduction link

https://codemirror.net/examples/mixed-language

lishid commented 3 months ago

We have recently updated codemirror-view to 6.24.1 4e355ea (previously using 6.21.4 5dfda8e) and we are getting a lot of reports for this issue as well. Lots of details and videos (inconveniently in zip files) at https://forum.obsidian.md/t/cursor-ends-up-before-the-letter-on-android-samsung-keyboard/78185

In addition, we are also seeing a similar issue on desktop with IMEs with details here, which I am also able to reproduce in the mixed-language demo page: https://forum.obsidian.md/t/problem-with-cursor-positioning-after-some-formatting-symbols-when-using-input-method-ime-cjk/78455

@marijnh Has this been reproducible at all? We would be grateful if you can take a look at it as we are getting a significant amount of users running into this, and our app store reviews has seem better days as well :joy:.

lishid commented 3 months ago

I have bisected the problem to be from the commit https://github.com/codemirror/view/commit/4e355eab50de94ab315ed293729f5365841fe3c8

lovelle-cardoso commented 3 months ago

@marijnh Any workaround for this? Or should we just roll back codemirror/view to 6.24.1 for now?

marijnh commented 3 months ago

It looks like 6.26.1 already makes this less disruptive—the cursor still appears in the wrong place after starting a single letter, but continuing to type does the expected thing.

The underlying issue here seems to be a bug in that virtual keyboard, which mispositions the cursor when the DOM changes right at the start of the composition, putting it before instead of after the typed character. Other keyboards like GBoard don't have this problem.

lovelle-cardoso commented 3 months ago

@marijnh Updating to 6.26.1 seems to fix things (on my Android phone at least) Thanks! I'm not sure if it fixes it in all the situations @lishid describes, but in my case, you're welcome to close this bug.

lishid commented 3 months ago

I will update and test again in a few days, thanks!

lovelle-cardoso commented 2 months ago

@marijnh Actually, spoke too soon! This is still broken for me.

lovelle-cardoso commented 2 months ago

@lishid I see that Obsidian was able to workaround this bug for their latest 1.5.12 update. Was that accomplished by simply downgrading codemirror to a particular version?

lishid commented 2 months ago

@lishid I see that Obsidian was able to workaround this bug for their latest 1.5.12 update. Was that accomplished by simply downgrading codemirror to a particular version?

We have a fork on which I've performed a revert on the specific commit.

lovelle-cardoso commented 2 months ago

@lishid Thanks! Following suit, we have also forked @codemirror/view and reverted commit https://github.com/codemirror/view/commit/4e355eab50de94ab315ed293729f5365841fe3c8 to get things working again on Android devices. It's a bit difficult to maintain, but it'll do as a temporary workaround!

@marijnh if there is some sort of configuration option we could utilize to skip this composition barrier logic, let us know! Otherwise, we'll just keep working off of a fork for now.

marijnh commented 2 months ago

I haven't been able to find a way to fix #1324 without triggering this misbehavior in the virtual keyboard, so I went ahead and reverted that fix in 6.26.2. Experimenting with using EditContext to sidestep this whole pile of hacks, but that's a major project, and might take a while.