diff options
| author | ruki <[email protected]> | 2026-01-21 00:40:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-21 00:40:01 +0800 |
| commit | b5a506803e4f3c8b11858be2a57c509d479683e1 (patch) | |
| tree | 9e5c628fdd225958c8fa0cc13bb14011a8bafeb1 /xmake/core/ui/label.lua | |
| parent | 4c08bae6d49e37102c0b889ff7afcc9f319435db (diff) | |
mark wcswidth deprecated
Diffstat (limited to 'xmake/core/ui/label.lua')
| -rw-r--r-- | xmake/core/ui/label.lua | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/xmake/core/ui/label.lua b/xmake/core/ui/label.lua index 33a35b16f..45330c80c 100644 --- a/xmake/core/ui/label.lua +++ b/xmake/core/ui/label.lua @@ -129,17 +129,20 @@ function label:splitext(text, width) local line = lines[idx] while #line > width do local size = 0 - for i = 1, #line do - if bit.band(line:byte(i), 0xc0) ~= 0x80 then - size = size + line:wcwidth(i) - if size > width then - table.insert(result, line:sub(1, i - 1)) - line = line:sub(i) - break - end + local split_idx = 0 + for p, c in utf8.codes(line) do + local w = utf8.width(c) + size = size + w + if size > width then + split_idx = p + break end end - if size <= width then + + if split_idx > 0 then + table.insert(result, line:sub(1, split_idx - 1)) + line = line:sub(split_idx) + else break end end |
