Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of special characters in finder popups #4215

Merged
merged 1 commit into from
Jan 14, 2024

Conversation

bstaletic
Copy link
Collaborator

@bstaletic bstaletic commented Jan 10, 2024

PR Prelude

Thank you for working on YCM! :)

Please complete these steps and check these boxes (by putting an x inside
the brackets) before filing your PR:

  • I have read and understood YCM's CONTRIBUTING document.
  • I have read and understood YCM's CODE_OF_CONDUCT document.
  • I have included tests for the changes in my PR. If not, I have included a
    rationale for why I haven't.
  • I understand my PR may be closed if it becomes obvious I didn't
    actually perform all of these steps.

Why this change is necessary and useful

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 characters. čđš is 3, čđ\tš is 4. Not sure what happens in the face of zero width joiners.
  • 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.

I do not know if there's a performance penalty for using strdisplaywidth over strcharlen.


This change is Reviewable

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.
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Merging #4215 (9dee4c4) into master (79c850b) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4215      +/-   ##
==========================================
+ Coverage   89.70%   89.72%   +0.02%     
==========================================
  Files          34       34              
  Lines        4420     4420              
==========================================
+ Hits         3965     3966       +1     
+ Misses        455      454       -1     

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (waiting on @bstaletic)

@bstaletic bstaletic added the Ship It! Manual override to merge a PR by maintainer label Jan 14, 2024
Copy link
Contributor

mergify bot commented Jan 14, 2024

Thanks for sending a PR!

@mergify mergify bot merged commit 2b33bf3 into ycm-core:master Jan 14, 2024
11 of 13 checks passed
@bstaletic bstaletic deleted the finder-special-characters branch January 14, 2024 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ship It! Manual override to merge a PR by maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants