Skip to content

Commit

Permalink
Fix display of special characters in finder popups
Browse files Browse the repository at this point in the history
Previously len( desc ) and len( path ) counted bytes, which was wrong
for non-ascii characters. A string like `čđš` should have the length of
3 when calculating the number of spaces between the identifier and the
file path.

That brings us to choosing the right string length function. The choices
are:

- strcharlen - counts grapheme clusters. `čđš` is 3, `čđ\tš` is 4.
- strdisplaywidth - counts character width on screen. `čđš` is 3 and
  `čđ\tš` is 9 (assuming `tabstop` is 8).

Tabs do not appear in identifier names, but double width emojis might?
Tabs *can* appear in file names though. If there's more than one tab in
the file name, using `strcharlen` will push the file path text off
screen.
  • Loading branch information
bstaletic committed Jan 9, 2024
1 parent 79c850b commit 9dee4c4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions autoload/youcompleteme/finder.vim
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function! s:RedrawFinderPopup() abort
\ .. line_num
let path_includes_line = 1

let spaces = available_width - len( desc ) - len( path )
let spaces = available_width - strdisplaywidth( desc ) - strdisplaywidth( path )
let spacing = 4
if spaces < spacing
let spaces = spacing
Expand All @@ -524,16 +524,16 @@ function! s:RedrawFinderPopup() abort
if len( path ) > 0
if path_includes_line
let props += [
\ { 'col': available_width - len( path ) + 1,
\ { 'col': len( desc ) + spaces + 1,
\ 'length': len( path ) - len( line_num ),
\ 'type': 'YCM-symbol-file' },
\ { 'col': available_width - len( line_num ) + 1,
\ { 'col': len( desc ) + spaces + 1 + len( path ) - len( line_num ),
\ 'length': len( line_num ),
\ 'type': 'YCM-symbol-line-num' },
\ ]
else
let props += [
\ { 'col': available_width - len( path ) + 1,
\ { 'col': len( desc ) + spaces + 1,
\ 'length': len( path ),
\ 'type': 'YCM-symbol-file' },
\ ]
Expand Down

0 comments on commit 9dee4c4

Please sign in to comment.