Skip to content

Commit

Permalink
Fix wrong path truncation can happen
Browse files Browse the repository at this point in the history
Fix #4
  • Loading branch information
mityu committed Dec 17, 2024
1 parent 104d8a2 commit bff0996
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 7 additions & 9 deletions autoload/wispath.vim
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@ export def GetCompletion(target_path: string, cursor_col: number, in_cmdline: bo
truncate_len = 0
truncate_len_buffer = 0
else
var dir_buffer = fnamemodify(target_path, ':h')
var dir = ExpandEnviron(dir_buffer, in_cmdline)
var dir_buffer = fnamemodify(target_path, ':h') # Directory path as is on buffer.
var dir = ExpandEnviron(dir_buffer, in_cmdline) # Expanded directory path.
while true
if stridx(completions[0], dir) == 0
if dir == '/'
truncate_len = 1
truncate_len_buffer = 1
else
truncate_len = strchars(dir) + 1
truncate_len_buffer = strlen(dir_buffer) + 1
endif
# Additinonal truncation length for path separator.
const addition = fnamemodify(dir, ':t') ==# '' ? 0 : 1

truncate_len = strchars(dir) + addition
truncate_len_buffer = strlen(dir_buffer) + addition
break
elseif fnamemodify(dir_buffer, ':t') ==# dir_buffer
truncate_len = 0
Expand Down
2 changes: 2 additions & 0 deletions test/wispath.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ Describe wispath#GetCompletion()
endif
endfor
call CompareCandidates(GetCompletion('/'), [2, candidates])
call CompareCandidates(GetCompletion('//'), [3, candidates])
call CompareCandidates(GetCompletion('///'), [4, candidates])
End

It lists completions with multibyte file/dir name 1
Expand Down

0 comments on commit bff0996

Please sign in to comment.