Unnamed repository; edit this file 'description' to name the repository.
Use the first char in a grapheme for classification (#12483)
Co-authored-by: Rose Hogenson <[email protected]>
rhogenson 2025-02-02
parent c3620b7 · commit 17ffa38
-rw-r--r--helix-core/src/doc_formatter/test.rs8
-rw-r--r--helix-core/src/graphemes.rs4
2 files changed, 10 insertions, 2 deletions
diff --git a/helix-core/src/doc_formatter/test.rs b/helix-core/src/doc_formatter/test.rs
index 415ce8f6..21be2e53 100644
--- a/helix-core/src/doc_formatter/test.rs
+++ b/helix-core/src/doc_formatter/test.rs
@@ -102,6 +102,14 @@ fn long_word_softwrap() {
);
}
+#[test]
+fn softwrap_multichar_grapheme() {
+ assert_eq!(
+ softwrap_text("xxxx xxxx xxx a\u{0301}bc\n"),
+ "xxxx xxxx xxx \n.ábc \n "
+ )
+}
+
fn softwrap_text_at_text_width(text: &str) -> String {
let mut text_fmt = TextFormat::new_test(true);
text_fmt.soft_wrap_at_text_width = true;
diff --git a/helix-core/src/graphemes.rs b/helix-core/src/graphemes.rs
index e6adeee9..33d237cb 100644
--- a/helix-core/src/graphemes.rs
+++ b/helix-core/src/graphemes.rs
@@ -64,7 +64,7 @@ impl<'a> Grapheme<'a> {
}
pub fn is_whitespace(&self) -> bool {
- !matches!(&self, Grapheme::Other { g } if !g.chars().all(char_is_whitespace))
+ !matches!(&self, Grapheme::Other { g } if !g.chars().next().is_some_and(char_is_whitespace))
}
// TODO currently word boundaries are used for softwrapping.
@@ -72,7 +72,7 @@ impl<'a> Grapheme<'a> {
// This could however be improved in the future by considering unicode
// character classes but
pub fn is_word_boundary(&self) -> bool {
- !matches!(&self, Grapheme::Other { g,.. } if g.chars().all(char_is_word))
+ !matches!(&self, Grapheme::Other { g,.. } if g.chars().next().is_some_and(char_is_word))
}
}