mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
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:
parent
4557ad7ad1
commit
46b08f9d7d
1 changed files with 5 additions and 3 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue