replit / codemirror-vim

Vim keybindings for CM6
https://www.npmjs.com/package/@replit/codemirror-vim
MIT License
314 stars 30 forks source link

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

Open diminutivesloop opened 1 year ago

diminutivesloop commented 1 year ago

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

RyotaUshio commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

firai commented 1 year ago

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?

RyotaUshio commented 1 year ago

@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 commented 11 months ago

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

diminutivesloop commented 11 months ago

@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.