leodevbro / vscode-blockman

VSCode extension to highlight nested code blocks
https://github.com/leodevbro/vscode-blockman
MIT License
345 stars 16 forks source link

Bug in width calculation with multibyte characters. #109

Open n2naokun opened 1 year ago

n2naokun commented 1 year ago

Note: This text has been translated using DeepL.com. English When I use multibyte characters such as Japanese, the frame is not displayed correctly. Multibyte characters are displayed wider, but all of them seem to be calculated with the same width as alphabets and symbols.

If it is technically possible, we would appreciate it if you could fix this.

Japanese(original) 日本語などのマルチバイト文字を使用した場合枠が正しく表示されません。 マルチバイト文字は幅が広く表示されますが、全てアルファベットや記号と同じ幅で計算されているようです。

技術的に可能でしたら修正していただけると助かります。

blockman

leodevbro commented 1 year ago

Hi, I think we can make the situation better, but unfortunately it does not seem easy to fully fix it, because VS Code extension API does not expose width of each character or location of each character. So, blockman just calculates block width with 1 general character width times the count of characters in the line.

For now, please try this Blockman command: Press F1 and find: Blockman Toggle Try Support Double Width Chars (e.g. Chinese)

image

With this experimental feature, Blockman will try to find Chinese/Japanese/Korean characters and it will try to treat each of them as two characters, so it will look something like this. It is still not correct width, but at least the rectangle is bigger, so the text does not overflow and it feels more natural probably.

image

n2naokun commented 1 year ago

Thank you very much. It is now easier to read.

ChenZhouUC commented 1 month ago

Thank you a lot for your help. This is enough for me. Still confused for the one point, is this toggle command thing different from the extension settings since I couldn't find any changes on my VSCODE user settings?

leodevbro commented 1 month ago

Yeah, it does not change the settings. It just changes the current state in memory. So, probably you have to rerun the command every time you restart VS Code.

ChenZhouUC commented 1 month ago

Yeah, it does not change the settings. It just changes the current state in memory. So, probably you have to rerun the command every time you restart VS Code.

Thank you for your kind reply. Found a way to do this automatically. I would like to put it here in case anyone who has similar concern.

Using VSCode's Tasks: (ref: https://code.visualstudio.com/docs/editor/tasks)

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "blockman",
            "type": "process",
            "command": "${command:blockman.toggleTrySupportDoubleWidthChars}",
            "args": [],
            "group": "none",
            "runOptions": {
                "runOn": "folderOpen"
            }
        }
    ]
}
ChenZhouUC commented 1 month ago

Still Looking Forward to a formal Setting for this feature. This is indeed a good enough one! I consider wider is better though some outlier cases might occur.