-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
330ece9
Truncate the starts of file paths in picker
Omnikar 439612e
Simplify the truncate implementation
archseer a2315a6
Break loop at appropriate point
Omnikar 70091f7
Fix alignment and ellipsis presence
Omnikar b547531
Remove extraneous usage of `x_offset`
Omnikar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -483,6 +483,7 @@ impl<T: 'static> Component for Picker<T> { | |
text_style | ||
}, | ||
true, | ||
true, | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
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 callstring.width()
, then if it's larger thanwidth
we iterate graphemes from reverse, rendering them intocontent
(without using theend
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 shorterThere 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.