Okay, from the front I should say that I’m nearly positive that it’s not a bug in the library, I’m positive it’s the problem with my setup of CodeMirror.
I’m experiencing weird behaviour of the editor on mobile, and only in mobile view. If I use “Computer view” in my phone it works perfectly. If I enable normal “Phone view”, then it behaves wierdly.
I’ve made a regording, what I’m seeing is that:
When I press Enter on my mobile phone (0:14)
I see that newline is added to EditorState
But I see two lines in the view
Then I press Backspace, and the cursor in the view goes back, but there are now two new lines
On the recording there first string below the editor is JSON.stringify() of view.state.toString(), and the HTML below is view.contentDOM.innerHTML.
I have no idea what’s going on, I know I messed up some key bindings probably, but I don’t know what I did wrong. What can I do to fix this?
If this doesn’t happen in a plain setup, I guess the first step to debugging it is to simplify your setup piece by piece to see which extension/configuration causes the issue.
I tried debugging, and I looked up what changes was exactly, and when I passed it as an object literal, the bug disappeared. That lead me to believe that there’s probably something about the changes references that take action.
Here’s info for you. If you update this line with a deep-copy of changes:
There’s something about object references that messes it up. I don’t know what exactly, but with a hard copy of changes in newlineAndIndent it works perfectly.
insertNewlineAndIndent is what the default keymap binds to Enter. Is this also happening for you on a plain basicSetup configuration with no external code?
The bug is not reproducible on other browser on my Note10+, like Firefox. But there’s the same bug on Edge; which leads me to believe any Chromium Browser would be affected.
@marijn I’m willing to Try and run any POC you’d like and report the output to you, if that’s what it takes.
Cause I have a feeling you find my solution with Text.of unsatisfactory?
Add some letters, like "One" but without newline at the end
Call insertNewlineAndIndent()
If you call insertNewlineAndIndent() on an empty line or line with spaces, the bug is not reproducible.
And also if you have highlightActiveLine() extension added it won’t be reproducible either. And I also can’t reproduce it on a “Computer version” in my phone, only mobile.
When I do that I see one new "\n" in EditorState, but two new lines in the view.
I am seeing the exact same behaviour in pixel 5 emulator and also on Mac OS Chrome Version 98.0.4758.80: pixel 5 device/ galaxy fold/ or any android device.
If I don’t use highlightActiveLine() extension this happens on every newline, but if I use highlightActiveLine() extension It only happens when there are 2 or more “words” (words = its own span tag)
I think similar bugs have been also reported by some other users in the github issues:
Here is another similar case, I’m not sure if there is any relationship between these cases.
My device: iPhone 11 with iOS 15.3.1, I just use Safari to open codemirror.net/6 and use iOS default Chinese IME.
If you select the words and immediately press return(换行 at the right corner), two new lines will be created:
If you select the words and wait for about 2 seconds then press return, only one new line will be created (which is what I need):
I’m not quite good at coding so sorry if causing trouble to you.
Thanks for your patience. I’m not sure what I did different compared to the last time I tried to reproduce this (maybe I wasn’t starting with a blank document), but I was able to reproduce this now. This patch should fix it:
I’ve updated the website to use the current code. If you still see issues, please open a github issue with more information.
Thanks for your patience. I’m not sure what I did different compared to the last time I tried to reproduce this (maybe I wasn’t starting with a blank document), but I was able to reproduce this now. This patch should fix it: