fix(apply_icons): filename may be truncated #243
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Version: Neovim v0.9.4 and Vim 9.0 running on Linux and Windows
I am a long-time dirvish user, but only recently started using the dirvish#add_icon_fn() to add devicons to the dirvish display. However, I found that occasionally the filenames displayed by dirvish are truncated from the left when the icons are being applied.
To see the issue, create files 'abc-file.txt', 'defg-file.txt', and 'file.txt' in a directory and display them in a dirvish buffer. All filenames display as 'file.txt' as shown below.
This Neovim screenshot was taken on a Windows workstation, but the same behavior can be seen in Neovim and Vim on both Linux and Windows machines.
The problem seems to occur when the base name of one of the files in the directory matches the right-hand portion of one or more other filenames in the same directory. However, experimentation shows that it does not always happen in this case, so there must be more specific conditions contributing to it.
After some debugging, I found that the cause is in the syntax matching performed by the s:apply_icons() function in autoload/dirvish.vim. I am new to vim syntax matching, but believe that the problem is caused by the iteration of the match operation across all the files in the directory. When the common match pattern encounters multiple files whose names end in the same characters, it 'swallows up' the leading characters of the names that do not match, leaving identical filename suffixes shown in the dirvish display.
To fix it, I inserted a line counter into the match pattern inside the loop that iterates through the file list, forcing a unique pattern to be matched against each file. This fix has worked fine on my machines for several weeks now.