Commit 7d65f21
committed
fix: handle Unicode properly when computing string lengths
When drawing icons (which are Unicode codepoints with multi-byte
representations), we were running afoul of the fact that all of these
Lua string operations operate on bytes instead of codepoints:
- `#` to determine length
- `string.len`
- `string.format` with the `%-99s` format marker
- `string.sub`
This would cause us to not make full use of the available space: we
would truncate strings too aggressively when inserting a middle
ellipsis, and we wouldn't draw the selected line highlight all the way
to the end of the line.
The fix is to use `vim.str_utfindex` to determine width by counting
codepoints, and `vim.str_byteindex` to figure out the byte index of a
particular codepoint (so that we can truncate the string with
`string.sub`, passing it that byte index).1 parent 45b9b01 commit 7d65f21
1 file changed
+12
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | | - | |
| 72 | + | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| |||
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
82 | | - | |
| 86 | + | |
83 | 87 | | |
84 | | - | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
92 | | - | |
| 96 | + | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
98 | | - | |
| 102 | + | |
99 | 103 | | |
100 | 104 | | |
101 | | - | |
102 | | - | |
103 | 105 | | |
104 | | - | |
105 | | - | |
106 | | - | |
| 106 | + | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
0 commit comments