editor: Preserve grapheme identity during rewrap (#39223)

Closes #39207

Release Notes:

- N/A
This commit is contained in:
Miao 2025-10-01 15:37:23 +08:00 committed by GitHub
parent e111acad33
commit 01dbc68f82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22400,7 +22400,14 @@ fn wrap_with_prefix(
continue;
}
if !preserve_existing_whitespace {
token = " ";
// Keep a single whitespace grapheme as-is
if let Some(first) =
unicode_segmentation::UnicodeSegmentation::graphemes(token, true).next()
{
token = first;
} else {
token = " ";
}
grapheme_len = 1;
}
let current_prefix_len = if is_first_line {
@ -22502,6 +22509,17 @@ fn test_wrap_with_prefix() {
),
"这是什\n么 钢\n"
);
assert_eq!(
wrap_with_prefix(
String::new(),
String::new(),
format!("foo{}bar", '\u{2009}'), // thin space
80,
NonZeroU32::new(4).unwrap(),
false,
),
format!("foo{}bar", '\u{2009}')
);
}
pub trait CollaborationHub {