Hold ambiguous English words (up = 因) until the next word decides

"up " also reads as ㄧㄣ (因). Instead of committing English on space, keep the
word composing: "up jo4" becomes 因為, "up the" stays English. Only applies when
the reading is a common single syllable (lexicon score >= -3.5): up, url.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 16:10:47 +08:00
co-authored by Claude Opus 5.5
parent 1dacb8f164
commit ef9f91a6b7
4 changed files with 126 additions and 2 deletions
+16
View File
@@ -279,5 +279,21 @@ class FirstToneAfterEnglishTests(unittest.TestCase):
self.assertEqual(len(e.marked_text), 1, keys)
class HeldWordTests(unittest.TestCase):
def test_next_word_decides(self):
cases = {"up jo4 ": "因為", "up the ": "up the ", "pick up the ": "pick up the ",
"up\n": "up", "i love ": "i love "}
for keys, want in cases.items():
self.assertEqual(type_keys(keys, make_engine()), want, keys)
def test_held_word_stays_composing(self):
e = make_engine()
self.assertEqual(type_keys("up ", e), "")
self.assertEqual(e.marked_text, "up ")
e.handle(BACKSPACE)
self.assertEqual(e.marked_text, "up")
self.assertEqual(type_keys(" the ", e), "up the ")
if __name__ == "__main__":
unittest.main()