From 9dee4c4ba4c1b057bde571a6f74754006b6b46d0 Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Wed, 10 Jan 2024 00:59:05 +0100 Subject: [PATCH] Fix display of special characters in finder popups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- autoload/youcompleteme/finder.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/youcompleteme/finder.vim b/autoload/youcompleteme/finder.vim index 1406312db7..bab8c6e24d 100644 --- a/autoload/youcompleteme/finder.vim +++ b/autoload/youcompleteme/finder.vim @@ -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 @@ -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' }, \ ]