Skip to content

Commit 39d0455

Browse files
committed
fix: count unicode codepoints instead of bytes
1 parent 630305c commit 39d0455

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lua/nvim-tree/view.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@ local function grow()
211211
local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false)
212212
local max_length = M.View.initial_width
213213
for _, l in pairs(lines) do
214-
if max_length < #l then
215-
max_length = #l
214+
-- count of unicode codepoints.
215+
-- (#l counts the bytes in the string which is not desirable)
216+
local _, count = string.gsub(l, "[^\128-\193]", "")
217+
count = count + 3 -- add padding
218+
if max_length < count then
219+
max_length = count
216220
end
217221
end
218222
M.resize(max_length)

0 commit comments

Comments
 (0)