markdown.nvim icon indicating copy to clipboard operation
markdown.nvim copied to clipboard

[BUG]: The `table_style` setting incorrectly calculated the text length inside the table.

Open MasouShizuka opened this issue 1 year ago • 0 comments
trafficstars

After I tried the plugin, I found that when the cell text length of each column of the table is the same, the plugin will add lines above and below the table. For ascii characters, this calculation is correct.

But for other characters, such as Chinese, this is not so good. Because for Chinese characters, Lua will count the length of the character as 3, such as: . However, with a mono font, actually takes up 2 characters of width.

For example, the following table will add lines, but it actually doesn’t look good:

| 列1 | 列2 | 列3 |
| ---- | ---- | ---- |
| 行1 | 2    | 3    |
| 行2 | 2    | 3    |
| 行3 | 2    | 3    |

image

Although the following table has the same width, lines cannot be added:

| 列1 | 列2 | 列3 |
| --- | --- | --- |
| 行1 | 2   | 3   |
| 行2 | 2   | 3   |
| 行3 | 2   | 3   |

image

Perhaps should use the strwidth function to calculate text length:

vim.fn.strwidth("行") = 2

MasouShizuka avatar May 25 '24 08:05 MasouShizuka