codemirror-vim icon indicating copy to clipboard operation
codemirror-vim copied to clipboard

Vim normal-mode cursor disappears when moving over multi-codepoint emoji

Open diminutivesloop opened this issue 2 years ago • 7 comments

Originally reported as an issue w/ Obsidian.

Steps to Reproduce

Using sandbox editor:

  1. Insert a multi-codepoint emoji such as ➡️ Right Arrow Emoji
  2. Place the cursor before the emoji
  3. In vim normal mode move the cursor until it is past the emoji

Expected result

The cursor moves over the emoji just like non-emoji text.

Actual result

After initially highlighting the emoji character, the cursor disappears on its next move (or next several depending on the number of codepoints) and eventually reappears once it is moved to the subsequent character.

https://github.com/replit/codemirror-vim/assets/121306735/62d95347-a2a4-499a-8895-f36ec20078b5

diminutivesloop avatar Oct 06 '23 18:10 diminutivesloop

I suspect this is related to the problem that atomic ranges does not work in the normal mode.

https://forum.obsidian.md/t/cm6-are-vim-mode-atomic-ranges-compatible/69667

RyotaUshio avatar Oct 22 '23 14:10 RyotaUshio

I think I figured out why it happens. CM6's moveByChar skips atoms (https://github.com/codemirror/view/blob/e6a55a6515521a84e709f02b4eb32e57aebbbfba/src/editorview.ts#L641), while codemirror-vim's moveByCharacters doesn't.

RyotaUshio avatar Oct 24 '23 11:10 RyotaUshio

I was able to fix this regarding cursor motions (h/l) by modifying the implementation of moveByCharacters() so that is uses CM6's moveByChar (which respects atomic ranges).

https://github.com/RyotaUshio/codemirror-vim/commit/e6eb8dbc18fb7e1175d370e0e3d7d163be2db998

But I'm not sure how I can fix this regarding deletion.

RyotaUshio avatar Oct 24 '23 12:10 RyotaUshio

Base CM forward deletes atomically, while backspace deletes the characters separately. I wonder if there's code from base CM that could be referenced to atomically delete.

@RyotaUshio, would it make sense to submit the motion patch as a PR ahead of figuring out the deletion part?

firai avatar Nov 10 '23 17:11 firai

@firai I might make sense, but to be honest, I currently can't find enough time to fill in the (a little bit strict) PR template.

RyotaUshio avatar Nov 12 '23 07:11 RyotaUshio

Obsidian has recently released v1.5.3, which includes the fix for this problem.

RyotaUshio avatar Dec 29 '23 05:12 RyotaUshio

@RyotaUshio I checked the latest version and it resolves the issue except in the case where the emoji is at the end of the line. In that case the cursor still moves twice over the emoji character and disappears when at the very end of the line.

diminutivesloop avatar Jan 02 '24 17:01 diminutivesloop