yo1dog / vscode-cursor-align

Visual Studio Code Extension that aligns all cursors using spaces.
MIT License
21 stars 6 forks source link

chinese char align #4

Open midgithub opened 6 years ago

midgithub commented 6 years ago

when exist chinese char . the align result is not correct. Is that can support in a later version. thanks very much.

yo1dog commented 3 years ago

Good catch. I am probably not handling UTF-16 characters. Replacing str.length with a string iterator to count code units instead of code points would solve this. I’ll make this change.

You touch on an underlying issue: how VSCode (and the selected font) visually displays the width of a given character. It’s incorrect to assume that any given character takes up exactly 1 column. However, even if we tried to account for the complexities of Unicode character representation (ex: grapheme clustering), there is simply no way to predict the display width of a given character in a monospaced environment as there is no standardization on this yet. Not to mention font-specific ligatures.

That said, if VSCode does have its own set of explicit rules regarding character display width, it could be possible to predict and account for these characters. I’ll do some research, but I’m skeptical based on my observations of how VSCode handles emojis.

Further, I assume using non-standard characters while coding, especially in use cases for vertical alignment, is rare and this edge case may not warrant the effort and potential adverse side effects. Though I’ll admit my ignorance of many programming languages and non-English coding styles and also acknowledge VSCode is used as an editor for many things besides just code.