Closed FallenWarrior2k closed 1 year ago
Issue with coc.nvim, since I can't find vim's function to calculate utf16 offset
Ah well. Thanks for your quick response anyway and sorry if the way I wrote the issue came off as arrogant. I shouldn't have assumed it was something simple like string length. My bad.
Fixed on coc.nvim by https://github.com/neoclide/coc.nvim/commit/c019fd7002d5fe903389e9d2587e301a790f88f6
A basic example to repro: pasting
🗎 red
into an empty buffer with coc-highlight enabled will result in the following.Inspecting the character with
ga
, we find that we're dealing with U+1F5CE, which becomes 0xD83D 0xDDCE in UTF-16. My assumption here is that, due to"🗎".length === 2
, the highlighting gets applied to the wrong columns, as the code assumes there's two characters, even though they only take up one column of screen space.MDN's page on String.length suggests a function like the following to count the actual characters:
I am not familiar with the codebase, but I might contribute a fix myself if it seems easy enough.
Lastly, I want to note that a similar issue exists with the post-yank highlighting in coc-yank. If you want me to open an issue over there as well, I can do so, but I decided against it for now because I didn't want to open two issues with essentially the same body text.