justinmk / vim-dirvish

Directory viewer for Vim :zap:
Other
1.18k stars 64 forks source link

fix(apply_icons): filename may be truncated #243

Closed fwy closed 8 months ago

fwy commented 8 months ago

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.

image

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.

justinmk commented 8 months ago

Thank you!