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

Truncate the starts of file paths instead of the ends in picker #951

Merged
merged 5 commits into from
Nov 4, 2021

Conversation

Omnikar
Copy link
Contributor

@Omnikar Omnikar commented Nov 1, 2021

Fixes #945.

self.content[i].reset();
} else {
let mut truncated = false;
let mut end = Vec::new();
Copy link
Contributor

@pickfire pickfire Nov 2, 2021

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.

Copy link
Contributor Author

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.

Copy link
Member

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:

UnicodeWidthStr::width(g).max(1)

We re-export the library as helix_core::unicode::width

Copy link
Member

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)

Copy link
Member

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.

Copy link
Contributor Author

@Omnikar Omnikar Nov 4, 2021

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

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.

@Omnikar
Copy link
Contributor Author

Omnikar commented Nov 4, 2021

Wait a minute, it stopped working before I pushed it? I tested it and it worked before I deleted let mut x_offset = max_offset; because it was no longer being used. But after I deleted it, it started subtract overflowing? I am very confused.

@Omnikar
Copy link
Contributor Author

Omnikar commented Nov 4, 2021

Ohhhh, it was because x_offset shadowed another x_offset variable… which means that the compiler was wrong in warning me that the new x_offset is unused? 🤔

@Omnikar
Copy link
Contributor Author

Omnikar commented Nov 4, 2021

Oh… it wasn't a compiler bug. x_offset is actually just never read.

@Omnikar
Copy link
Contributor Author

Omnikar commented Nov 4, 2021

OK, now it should work.

@Omnikar Omnikar requested a review from archseer November 4, 2021 01:14
@archseer archseer merged commit 5b5d1b9 into helix-editor:master Nov 4, 2021
@Omnikar Omnikar deleted the truncate-path-start branch November 4, 2021 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File Picker: File names are trimmed if the path is too long
3 participants