From 7b636c06c8ac429e8087eb865039cd21795cddab Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 6 Aug 2025 21:12:09 +0800 Subject: [PATCH 1/6] gpui: Fix text wrap for slash in URL. --- crates/gpui/examples/text_wrapper.rs | 2 +- crates/gpui/src/text_system/line_wrapper.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/gpui/examples/text_wrapper.rs b/crates/gpui/examples/text_wrapper.rs index 4c6e5e2ac8..370d535303 100644 --- a/crates/gpui/examples/text_wrapper.rs +++ b/crates/gpui/examples/text_wrapper.rs @@ -7,7 +7,7 @@ struct HelloWorld {} impl Render for HelloWorld { fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { - let text = "The longest word 你好世界这段是中文,こんにちはこの段落は日本語です in any of the major English language dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis, a word that refers to a lung disease contracted from the inhalation of very fine silica particles, specifically from a volcano; medically, it is the same as silicosis."; + let text = "The longest word 你好世界这段是中文,こんにちはこの段落は日本語です in any of the major English language dictionaries is thisisalonglongpart/ofslash/thisshould/wrap/pneumonoultramicroscopicsilicovolcanoconiosis, a word that refers to a lung disease contracted from the inhalation of very fine silica particles, specifically from a volcano; medically, it is the same as silicosis."; div() .id("page") .size_full() diff --git a/crates/gpui/src/text_system/line_wrapper.rs b/crates/gpui/src/text_system/line_wrapper.rs index 5de26511d3..e5bf7be34e 100644 --- a/crates/gpui/src/text_system/line_wrapper.rs +++ b/crates/gpui/src/text_system/line_wrapper.rs @@ -163,6 +163,8 @@ impl LineWrapper { line } + /// Any character in this list should be treated as a word character, + /// meaning it can be part of a word that should not be wrapped. pub(crate) fn is_word_char(c: char) -> bool { // ASCII alphanumeric characters, for English, numbers: `Hello123`, etc. c.is_ascii_alphanumeric() || @@ -183,7 +185,8 @@ impl LineWrapper { // e.g. `a-b`, `var_name`, `I'm`, '@mention`, `#hashtag`, `100%`, `3.1415`, `2^3`, `a~b`, etc. matches!(c, '-' | '_' | '.' | '\'' | '$' | '%' | '@' | '#' | '^' | '~' | ',') || // Characters that used in URL, e.g. `https://github.com/zed-industries/zed?a=1&b=2` for better wrapping a long URL. - matches!(c, '/' | ':' | '?' | '&' | '=') || + // But `/` or `\` should wrap. + matches!(c, ':' | '?' | '&' | '=') || // `⋯` character is special used in Zed, to keep this at the end of the line. matches!(c, '⋯') } From 263fc186e681cd5cfc391a2c187ea9ef2630a8c8 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 6 Aug 2025 21:19:41 +0800 Subject: [PATCH 2/6] remove some urls char. --- crates/gpui/src/text_system/line_wrapper.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/gpui/src/text_system/line_wrapper.rs b/crates/gpui/src/text_system/line_wrapper.rs index e5bf7be34e..4f6229bf2a 100644 --- a/crates/gpui/src/text_system/line_wrapper.rs +++ b/crates/gpui/src/text_system/line_wrapper.rs @@ -182,11 +182,8 @@ impl LineWrapper { // https://en.wikipedia.org/wiki/Cyrillic_script_in_Unicode matches!(c, '\u{0400}'..='\u{04FF}') || // Some other known special characters that should be treated as word characters, - // e.g. `a-b`, `var_name`, `I'm`, '@mention`, `#hashtag`, `100%`, `3.1415`, `2^3`, `a~b`, etc. - matches!(c, '-' | '_' | '.' | '\'' | '$' | '%' | '@' | '#' | '^' | '~' | ',') || - // Characters that used in URL, e.g. `https://github.com/zed-industries/zed?a=1&b=2` for better wrapping a long URL. - // But `/` or `\` should wrap. - matches!(c, ':' | '?' | '&' | '=') || + // e.g. `a-b`, `var_name`, `I'm`, '@mention`, `#hashtag`, `100%`, `3.1415`, `2^3`, `a~b`, `a=1`, etc. + matches!(c, '-' | '_' | '.' | '\'' | '$' | '%' | '@' | '#' | '^' | '~' | ',' | '=') || // `⋯` character is special used in Zed, to keep this at the end of the line. matches!(c, '⋯') } From b668657e4eeeca39d3d25190bb3b404e105ce6d6 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 6 Aug 2025 21:30:45 +0800 Subject: [PATCH 3/6] Update test --- crates/gpui/src/text_system/line_wrapper.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/text_system/line_wrapper.rs b/crates/gpui/src/text_system/line_wrapper.rs index 4f6229bf2a..a2ab860bdc 100644 --- a/crates/gpui/src/text_system/line_wrapper.rs +++ b/crates/gpui/src/text_system/line_wrapper.rs @@ -648,15 +648,18 @@ mod tests { assert_word("@mention"); assert_word("#hashtag"); assert_word("$variable"); + assert_word("a=1"); assert_word("more⋯"); // Space assert_not_word("foo bar"); // URL case - assert_word("https://github.com/zed-industries/zed/"); assert_word("github.com"); - assert_word("a=1&b=2"); + assert_not_word("zed-industries/zed"); + assert_not_word("zed-industries\\zed"); + assert_not_word("a=1&b=2"); + assert_not_word("foo?b=2"); // Latin-1 Supplement assert_word("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ"); From 9f383523ed09d510a71a7a349c1c6cc8baa5a189 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 6 Aug 2025 21:49:33 +0800 Subject: [PATCH 4/6] keep `:` to fix editor test. --- crates/gpui/src/text_system/line_wrapper.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/text_system/line_wrapper.rs b/crates/gpui/src/text_system/line_wrapper.rs index a2ab860bdc..69fbc23b8e 100644 --- a/crates/gpui/src/text_system/line_wrapper.rs +++ b/crates/gpui/src/text_system/line_wrapper.rs @@ -183,7 +183,7 @@ impl LineWrapper { matches!(c, '\u{0400}'..='\u{04FF}') || // Some other known special characters that should be treated as word characters, // e.g. `a-b`, `var_name`, `I'm`, '@mention`, `#hashtag`, `100%`, `3.1415`, `2^3`, `a~b`, `a=1`, etc. - matches!(c, '-' | '_' | '.' | '\'' | '$' | '%' | '@' | '#' | '^' | '~' | ',' | '=') || + matches!(c, '-' | '_' | '.' | '\'' | '$' | '%' | '@' | '#' | '^' | '~' | ',' | '=' | ':') || // `⋯` character is special used in Zed, to keep this at the end of the line. matches!(c, '⋯') } @@ -649,6 +649,7 @@ mod tests { assert_word("#hashtag"); assert_word("$variable"); assert_word("a=1"); + assert_word("Self::is_word_char"); assert_word("more⋯"); // Space From baa94c2f6f47bf1f37043099211d1bd219198502 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 6 Aug 2025 21:50:26 +0800 Subject: [PATCH 5/6] update doc --- crates/gpui/src/text_system/line_wrapper.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/text_system/line_wrapper.rs b/crates/gpui/src/text_system/line_wrapper.rs index 69fbc23b8e..151be866e5 100644 --- a/crates/gpui/src/text_system/line_wrapper.rs +++ b/crates/gpui/src/text_system/line_wrapper.rs @@ -182,7 +182,8 @@ impl LineWrapper { // https://en.wikipedia.org/wiki/Cyrillic_script_in_Unicode matches!(c, '\u{0400}'..='\u{04FF}') || // Some other known special characters that should be treated as word characters, - // e.g. `a-b`, `var_name`, `I'm`, '@mention`, `#hashtag`, `100%`, `3.1415`, `2^3`, `a~b`, `a=1`, etc. + // e.g. `a-b`, `var_name`, `I'm`, '@mention`, `#hashtag`, `100%`, `3.1415`, + // `2^3`, `a~b`, `a=1`, `Self::new`, etc. matches!(c, '-' | '_' | '.' | '\'' | '$' | '%' | '@' | '#' | '^' | '~' | ',' | '=' | ':') || // `⋯` character is special used in Zed, to keep this at the end of the line. matches!(c, '⋯') From fff84ab363ddc2831bec94771e4d0c403e535e2e Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 6 Aug 2025 21:53:21 +0800 Subject: [PATCH 6/6] better example case. --- crates/gpui/examples/text_wrapper.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/gpui/examples/text_wrapper.rs b/crates/gpui/examples/text_wrapper.rs index 370d535303..18372ea9e1 100644 --- a/crates/gpui/examples/text_wrapper.rs +++ b/crates/gpui/examples/text_wrapper.rs @@ -7,7 +7,11 @@ struct HelloWorld {} impl Render for HelloWorld { fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { - let text = "The longest word 你好世界这段是中文,こんにちはこの段落は日本語です in any of the major English language dictionaries is thisisalonglongpart/ofslash/thisshould/wrap/pneumonoultramicroscopicsilicovolcanoconiosis, a word that refers to a lung disease contracted from the inhalation of very fine silica particles, specifically from a volcano; medically, it is the same as silicosis."; + let text = "The longest word 你好世界这段是中文,こんにちはこの段落は日本語です in any of the major \ + English language dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis, a word that \ + refers to a lung disease contracted from the inhalation of very fine silica particles, \ + a url https://github.com/zed-industries/zed/pull/35724?query=foo&bar=2, \ + specifically from a volcano; medically, it is the same as silicosis."; div() .id("page") .size_full()