tui-input-word-motionレビュー・半角カナに関する修正

This commit is contained in:
2026-04-29 21:41:24 +09:00
parent b79747bd0c
commit b0db02da6d
3 changed files with 69 additions and 2 deletions
+20 -1
View File
@@ -71,7 +71,9 @@ fn char_class(c: char) -> AtomClass {
let cp = c as u32;
match cp {
0x3040..=0x309F => AtomClass::Word(WordKind::Hiragana),
0x30A0..=0x30FF | 0x31F0..=0x31FF => AtomClass::Word(WordKind::Katakana),
0x30A0..=0x30FF | 0x31F0..=0x31FF | 0xFF65..=0xFF9F => {
AtomClass::Word(WordKind::Katakana)
}
0x3400..=0x4DBF | 0x4E00..=0x9FFF | 0xF900..=0xFAFF | 0x20000..=0x2FFFF => {
AtomClass::Word(WordKind::Han)
}
@@ -719,6 +721,23 @@ mod word_motion_tests {
assert_eq!(cursor(&buf), 0); // start of "日本語"
}
#[test]
fn halfwidth_katakana_is_treated_as_katakana() {
// 半角カナ「アイウエオ」は5 atom、すべて Katakana 種別。
let mut buf = buf_from("アイウエオfoo");
buf.cursor = 0;
buf.move_word_right();
assert_eq!(cursor(&buf), 5); // after "アイウエオ"
buf.move_word_right();
assert_eq!(cursor(&buf), 8); // after "foo"
// 全角と半角のカタカナは同じ Katakana 種別なので1単語につながる。
let mut buf2 = buf_from("カタカナ");
buf2.cursor = 0;
buf2.move_word_right();
assert_eq!(cursor(&buf2), 4);
}
#[test]
fn katakana_separates_from_ascii() {
let mut buf = buf_from("カタカナsecret");