Skip to content

fix: count unicode codepoints instead of bytes #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

FotiadisM
Copy link
Contributor

When using adaptive_size = true there is some extra padding (usually around 4-6 spaces). This is happening due to the unicode characters such as file or folder icon. For example string.len("  .hooks") (equivalent with #string ) will return 14, but this string only needs 10 spaces to be printed.

This commit fixes this issue and sets the width of the window to the true max_length + 1 space for padding.

local _, count = string.gsub(l, "[^\128-\193]", "")
count = count + 3 -- add padding
if max_length < count then
max_length = count
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use the vim.fn.strchars instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't aware this function existed, I just amended my commit.

@kyazdani42 kyazdani42 merged commit 1e3c578 into nvim-tree:master Jul 20, 2022
@kyazdani42
Copy link
Member

thanks for the contribution !

Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants