Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Preserve grapheme identity during rewrap (#39223)

Miao01dbc68f822e
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index ebea090f804..79bad1d319f 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -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 {