gpui: Trim trailing whitespace and punctuation before ellipsis (#57106)

When truncating text at the end with an ellipsis, the truncation point
can land right after a space or punctuation character, producing results
like `"some text …"` or `"some text-…"`.

This trims trailing whitespace and ASCII punctuation from the truncated
prefix before appending the ellipsis affix, so you get clean results
like `"some text…"` instead.

Release Notes:

- Improved text truncation to avoid trailing spaces or punctuation
before the ellipsis.
This commit is contained in:
Conrad Irwin 2026-05-19 05:46:05 -06:00 committed by GitHub
parent 4557ad7ad1
commit 46b08f9d7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -201,9 +201,11 @@ impl LineWrapper {
"{truncation_affix}{}", "{truncation_affix}{}",
&line[line.ceil_char_boundary(truncate_ix + 1)..] &line[line.ceil_char_boundary(truncate_ix + 1)..]
)), )),
TruncateFrom::End => { TruncateFrom::End => SharedString::from(format!(
SharedString::from(format!("{}{truncation_affix}", &line[..truncate_ix])) "{}{truncation_affix}",
} line[..truncate_ix]
.trim_end_matches(|c: char| c.is_whitespace() || c.is_ascii_punctuation())
)),
}; };
let mut runs = runs.to_vec(); let mut runs = runs.to_vec();
update_runs_after_truncation(&result, truncation_affix, &mut runs, truncate_from); update_runs_after_truncation(&result, truncation_affix, &mut runs, truncate_from);