neoclide / coc-highlight

Document highlight and document colors LSP support for coc.nvim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Color highlighting at wrong position in lines with characters requiring UTF-16 surrogate pairs

FallenWarrior2k opened this issue Β· comments

A basic example to repro: pasting πŸ—Ž red into an empty buffer with coc-highlight enabled will result in the following.
image

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