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

Allow truncation of table row text #6410

Closed
wants to merge 5 commits into from

Conversation

mWalrus
Copy link
Contributor

@mWalrus mWalrus commented Mar 22, 2023

This fixes the regression mentioned in #6346 where paths in the file picker were no longer being truncated.
We now allow all pickers who have self.truncate_start set to true to render truncated rows.

Not sure if I'm going about this the right way, any feedback is appreciated :)

Here we assume that spans with content that is 1
in length will not need to be truncated.

This solves an issue with my previous commit that
made the buffer picker truncate the "prefix" cells.
This removes the need for `render_cell_truncated`.

We now check if we should truncate in `render_cell`
which allows us to skip the additional checks in
`Buffer::set_spans_truncated`.
@mWalrus mWalrus marked this pull request as ready for review March 22, 2023 18:34
@mWalrus mWalrus changed the title Truncate paths in the file picker Allow truncation of table row text Mar 22, 2023
@pascalkuthe
Copy link
Member

pascalkuthe commented Mar 25, 2023

I had the thaught of soft wrapping text here (based on #5420, the doc formatted is very general) instead of truncating. At least for some pickers like diagnostics, it would be really nice to be able the entire item (diagnostic) instead of truncating. I am not sure if soft wrapping is always preferable to truncation but I personally am not a fan of the way paths were truncated because there was no way to horizontally scroll a picker item so it was sometimes very hard to tell certain paths apart. If this needs a fix anyway this might be a good opportunity.

Although it's probably a bit more complex so maybe we try to get this PR in as a regression fix for the next release and look into soft wrapping later.

@pascalkuthe pascalkuthe added this to the 23.03 milestone Mar 29, 2023
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

I actually like this a lot more than the old truncation (uses ... Instead of shortening ). It keeps more screen realeaste available the shortened path components were never really that useful to me. Other tools like fzf and skim di the same thing. The implementation needs some fixes tough


for span in &spans.0 {
text.push_str(span.content.as_ref());
span.styled_graphemes(span.style)
Copy link
Member

Choose a reason for hiding this comment

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

Performing grapheme segmentation here is both slow and incorrect. The idx used below is not a grapheme index but a byte index. Instead you should create an iterator that is transversed whenever the current style range is exhausted.

The current implementation can easily lead to crashes

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 figured this was a slow solution.
Could you elaborate a bit about what you mean and how I could go about correcting this? I'm pretty new to this kind of thing.

buf.set_style(area, cell.style);
for (i, spans) in cell.content.lines.iter().enumerate() {
if i as u16 >= area.height {
break;
}
buf.set_spans(area.x, area.y + i as u16, spans, area.width);
if cell.content.width() > 1 && truncate {
Copy link
Member

Choose a reason for hiding this comment

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

I dont think the emptyness check is required here. Why did you add it?

In any case it should be using byte Len (or is_empty really) instead of grapheme width since it's O(1) and any non-empty string usually has a width (the cases where it doesn't can be negelagted IMO)

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 added this check to not truncate table cells that have a content length of 1. If we don't have this check and try to render the buffer picker you will see that the first two cells (the entry number and the you-are-here indicator) are being truncated as well since my current implementation doesn't distinguish between cells but applies to the entire row.
image

With that said, there are probably better ways of doing this, this was just the fix I could come up with without diving too deep into it.

pascalkuthe pushed a commit to pascalkuthe/helix that referenced this pull request Mar 30, 2023
pascalkuthe pushed a commit to pascalkuthe/helix that referenced this pull request Mar 30, 2023
pascalkuthe pushed a commit to pascalkuthe/helix that referenced this pull request Mar 30, 2023
pascalkuthe pushed a commit to pascalkuthe/helix that referenced this pull request Mar 30, 2023
pascalkuthe pushed a commit to pascalkuthe/helix that referenced this pull request Mar 31, 2023
pascalkuthe pushed a commit to pascalkuthe/helix that referenced this pull request Mar 31, 2023
@kirawi
Copy link
Member

kirawi commented Mar 31, 2023

Superseded by #6488

@kirawi kirawi closed this Mar 31, 2023
@pascalkuthe
Copy link
Member

pascalkuthe commented Mar 31, 2023

Thanks for working on this. Usually I would have given you more feedback here until this was ready but we wanted to get a fix in before the release (and there is not a lit.of.time left in March :D) so I just cherry picked your commit and implemented set_spans_truncated in a second commjt myself. Using the truncation here is actually really good ui so it was a great idea

archseer pushed a commit that referenced this pull request Mar 31, 2023
@mWalrus
Copy link
Contributor Author

mWalrus commented Mar 31, 2023

No worries! I'll look through the implementation for learning purposes :)
Thanks for looking at this!

Triton171 pushed a commit to Triton171/helix that referenced this pull request Jun 18, 2023
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
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.

3 participants