codemirror / dev

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

iOS: text selection after input confirmation inside parentheses #1443

Open ina-yuzen opened 2 months ago

ina-yuzen commented 2 months ago

Describe the issue

When using iOS, if the cursor is placed inside parentheses and a character with composition is entered just before the closing parenthesis, upon confirming the input, the entered character becomes selected. As a result, when typing the next character, the previously entered text gets deleted.

https://github.com/user-attachments/assets/3adb1ec5-39f7-4e8a-b342-487add4a9f96

This seems to happen when bracketMatching extension is enabled.

Browser and platform

iPad Pro 3rd gen, iOS 16.6, Safari/Chrome 129.0.6668.46

Reproduction link

https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge2JyYWNrZXRNYXRjaGluZ30gZnJvbSAiQGNvZGVtaXJyb3IvbGFuZ3VhZ2UiCgppbXBvcnQge2phdmFzY3JpcHR9IGZyb20gIkBjb2RlbWlycm9yL2xhbmctamF2YXNjcmlwdCIKCm5ldyBFZGl0b3JWaWV3KHsKICBkb2M6ICIoKVxuIiwKICBleHRlbnNpb25zOiBbYnJhY2tldE1hdGNoaW5nKCldLAogIHBhcmVudDogZG9jdW1lbnQuYm9keQp9KQo=

ina-yuzen commented 3 days ago

After testing the demo for a while, I noticed the following behavior on iOS when entering Japanese text:

  1. When typing Japanese, the input string is first highlighted (selected), and then the cursor moves to the position immediately after the entered text.
  2. Additionally, I observed that when the decoration immediately following the input text disappears, the behavior of the selection range changes.

Since the bracketMatching feature relies on the selection range to determine whether to highlight brackets, this sequence of events causes a brief flicker in the bracket highlighting. Specifically, when the entered text is initially selected, the bracket highlighting disappears, but it reappears once the cursor moves to the position after the text.

It seems this appearance and disappearance of the decoration is causing the selection range to behave inconsistently. While I'm still unsure what exactly happens when the input string is finalized, I hope these observations are helpful.