From 9dae8271c973926d79490fa640f73ca8c39588a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KEEP=5FDARK=20=5B-=E0=B8=AD=E0=B8=B2=E0=B8=A3=E0=B9=8C?= =?UTF-8?q?=E0=B8=95-=5D?= <52394228+mastel2@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:19:11 +0700 Subject: [PATCH] fix(engine): keep Thai vowels and tone marks in their word word_class walks back over combining marks to their base letter, but only for the combining-diacritics blocks. Thai vowels and tone marks written above and below a letter (U+0E31, U+0E34-0E3A, U+0E47-0E4E) aren't alphanumeric, so Alt+Arrow, Alt+Backspace/Delete and double-click stopped at them inside a word. They now go with their letter, as combining accents do. Closes #2744. --- crates/engine/src/canvas/textedit.rs | 17 ++++++++++++++++- crates/engine/src/canvas/textedit/tests.rs | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) 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");