Describe the bug
When the cursor is on a character encoded as a UTF-16 surrogate pair β emojis (π), rare CJK characters (π©Έ½), musical symbols (π), etc. β several character-level commands produce incorrect results.
| Command |
Broken behavior |
a (Append) |
Cursor lands before the character instead of after |
r (Replace) |
Only replaces half the character, corrupting the text |
s (Change char) |
Only deletes half the character before entering Insert mode |
~ (Toggle case) |
Corrupts the character into a lone surrogate |
ga (Unicode info) |
Shows the half-surrogate value instead of the full codepoint |
To Reproduce
- Open a file containing
πtext
- Place cursor on
π
- Press
a (append), type !, press Esc
- See
!πtext β ! inserted before the emoji instead of after
Expected behavior
π!text β ! should be inserted after the emoji.
Environment (please complete the following information):
- Extension (VsCodeVim) version: 1.32.4
- VSCode version: 1.109.0
- OS: Ubuntu 24.04
Additional context
position.getRight() increments by 1 UTF-16 code unit, but these characters are 2 code units (a surrogate pair). Moving by 1 lands between the pair, and VSCode's validatePosition clamps it back to the start.
x/X, l/h, and y already have surrogate boundary correction and work correctly.
Describe the bug
When the cursor is on a character encoded as a UTF-16 surrogate pair β emojis (
π), rare CJK characters (π©Έ½), musical symbols (π), etc. β several character-level commands produce incorrect results.a(Append)r(Replace)s(Change char)~(Toggle case)ga(Unicode info)To Reproduce
πtextπa(append), type!, pressEsc!πtextβ!inserted before the emoji instead of afterExpected behavior
π!textβ!should be inserted after the emoji.Environment (please complete the following information):
Additional context
position.getRight()increments by 1 UTF-16 code unit, but these characters are 2 code units (a surrogate pair). Moving by 1 lands between the pair, and VSCode'svalidatePositionclamps it back to the start.x/X,l/h, andyalready have surrogate boundary correction and work correctly.