diff --git a/crates/engine/src/canvas/textedit.rs b/crates/engine/src/canvas/textedit.rs index 2c41c7d13..224b2b8fb 100644 --- a/crates/engine/src/canvas/textedit.rs +++ b/crates/engine/src/canvas/textedit.rs @@ -496,7 +496,22 @@ fn reading_order(doc: &Document, ids: Vec) -> Vec { fn word_class(chars: &[char], mut i: usize) -> u8 { while i > 0 && chars.get(i).is_some_and( - |c| matches!(*c as u32, 0x0300..=0x036F | 0x1AB0..=0x1AFF | 0x1DC0..=0x1DFF | 0x20D0..=0x20FF | 0x3099..=0x309A | 0xFE20..=0xFE2F), + // Combining marks, and the Thai vowels and tone marks written above and below a + // letter (U+0E31, U+0E34–0E3A, U+0E47–0E4E), which aren't alphanumeric themselves. + |c| { + matches!( + *c as u32, + 0x0300..=0x036F + | 0x0E31 + | 0x0E34..=0x0E3A + | 0x0E47..=0x0E4E + | 0x1AB0..=0x1AFF + | 0x1DC0..=0x1DFF + | 0x20D0..=0x20FF + | 0x3099..=0x309A + | 0xFE20..=0xFE2F + ) + }, ) { i -= 1; diff --git a/crates/engine/src/canvas/textedit/tests.rs b/crates/engine/src/canvas/textedit/tests.rs index e8daa3bf9..6fa722a26 100644 --- a/crates/engine/src/canvas/textedit/tests.rs +++ b/crates/engine/src/canvas/textedit/tests.rs @@ -91,6 +91,26 @@ fn word_selection_classes() { assert_eq!(sel(&s), (19, 19), "carets clamp to the text"); } +/// Thai vowels and tone marks belong to their letter's word: Alt+Arrow, Alt+Backspace and +/// double-click don't stop at them. +#[test] +fn thai_marks_belong_to_their_word() { + let (mut s, id) = setup("กี่ปี น้ำ"); + begin(&mut s, id, Some(0), false).unwrap(); + key(&mut s, "Right", false, true, false).unwrap(); + assert_eq!(sel(&s), (5, 5), "past กี่ปี, not at its tone mark"); + select_word(&mut s, 1).unwrap(); + assert_eq!(sel(&s), (0, 5), "double-click on the vowel selects the word"); + select_word(&mut s, 8).unwrap(); + assert_eq!(sel(&s), (6, 9)); + set_caret(&mut s, 9, false).unwrap(); + key(&mut s, "Left", false, true, false).unwrap(); + assert_eq!(sel(&s), (6, 6)); + key(&mut s, "Backspace", false, true, false).unwrap(); + assert_eq!(data(&s, id).characters, "น้ำ", "the whole word before the caret goes, marks and all"); + end(&mut s).unwrap(); +} + #[test] fn keyboard_navigation_and_extension() { let (mut s, id) = setup("one two\nthree");