-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Truncate the starts of file paths instead of the ends in picker #951
Conversation
helix-tui/src/buffer.rs
Outdated
self.content[i].reset(); | ||
} else { | ||
let mut truncated = false; | ||
let mut end = Vec::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do better than collecting iterating over this twice and having a separate allocation.
I think probably can just get the index and display the rest. Didn't look closely.
Good idea but I think for files it might be better to truncate the directories, like single character for each directory in path. How fish truncate the directory may be a better idea. But that would probably require separate allocation.
This is a good start and should be fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since individual graphemes can have different widths, I'm not sure how to do this without iterating over it in reverse and checking the total width.
single character for each directory in path
Ah, that's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to just calculate the total width using unicode_width::UnicodeWidthStr
, no need to segment it into graphemes:
helix/helix-core/src/graphemes.rs
Line 30 in e505bf2
UnicodeWidthStr::width(g).max(1) |
We re-export the library as helix_core::unicode::width
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, it's the same method you're already using (.width()
). Should be enough to call string.width()
, then if it's larger than width
we iterate graphemes from reverse, rendering them into content
(without using the end
vector)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a rewrite with ^ but it's untested. Probably needs more work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it panics when the paths are long enough to actually need to be truncated. Or rather, panics when compiling in debug mode, since it's a subtract overflow panic, which just rolls over in release mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, addressing this fixes the panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I guess that codepath always gets called even if the string is shorter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd preferably use the original code under !truncate_start
if the width is shorter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've figured out what to do.
Wait a minute, it stopped working before I pushed it? I tested it and it worked before I deleted |
Ohhhh, it was because |
Oh… it wasn't a compiler bug. |
91c5dce
to
ccfef8e
Compare
ccfef8e
to
b547531
Compare
OK, now it should work. |
Fixes #945.