Merge pull request #2745 from mastel2/thai-word-marks

fix(engine): keep Thai vowels and tone marks in their word
This commit is contained in:
BFlat authored and GitHub committed 2026-11-29 22:12:42 +07:00
commit 4312dda983
2 files changed
+36 -1

No files matched your search

+16 -1
View File
@@ -496,7 +496,22 @@ fn reading_order(doc: &Document, ids: Vec<NodeId>) -> Vec<NodeId> {
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;
@@ -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");