Color highlighting at wrong position in lines with characters requiring UTF-16 surrogate pairs
FallenWarrior2k opened this issue ยท 3 comments
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:
function getCharacterLength(str) {
return [...str].length;
}
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.
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 neoclide/coc.nvim@c019fd7