keyboard: show Hangul final after a lone vowel
- Commit
496032c361fc0a8db79f05310d608b079ab64dd0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 20:03 UTC (28 days ago)
- Parents
c83cac7
Symptom: typing a vowel first and then a consonant (e.g. ㅏ then ㄱ) showed only the vowel in the composing region; the consonant keystroke was invisible, the next backspace appeared to do nothing, and when a following vowel stole a compound final the kept half of that final was committed nowhere and lost (ㅏㄱㅅㅏ produced ㅏ사 instead of ㅏㄱ사). Root cause: HangulComposer.acceptConsonant parks a consonant typed after a lone medial in the final slot even though there is no initial to form a syllable with, but render() only ever rendered the medial in that state, so the final never reached the field. Fix: render() now renders a trailing final as its lone compatibility jamo beside the medial when there is no initial. Valid syllable assembly, vowel stealing and backspace decomposition are unchanged. Verification: new ComposerTest cases for the lone-vowel-plus-final render, its backspace, and the compound-final steal; targeted :keyboard:testDevUnitTest --tests ComposerTest passes.
Diff
keyboard/src/main/java/com/vayunmathur/keyboard/ime/HangulComposer.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/HangulComposer.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/HangulComposer.ktindex c243b9d0ec..bb93964f32 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/HangulComposer.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/HangulComposer.kt@@ -122,7 +122,13 @@ class HangulComposer : Composer { (SYLLABLE_BASE + (initial * MEDIALS.length + medial) * FINALS.length + final) .toChar().toString() initial >= 0 -> INITIALS[initial].toString()- medial >= 0 -> MEDIALS[medial].toString()+ // A vowel typed first has no initial to form a syllable with, so a final+ // consonant after it stays a lone jamo beside it. Dropping it from the+ // render would hide the keystroke (and lose the kept half of a compound+ // final entirely when a following vowel steals the other half).+ medial >= 0 ->+ if (final != 0) MEDIALS[medial].toString() + FINALS[final].toString()+ else MEDIALS[medial].toString() else -> "" }
keyboard/src/test/java/com/vayunmathur/keyboard/ime/ComposerTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ComposerTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ComposerTest.ktindex 8a9208c6c1..9e294a4489 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ComposerTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ComposerTest.kt@@ -91,6 +91,15 @@ class ComposerTest { assertEquals("아이", hangul().type("ㅇㅏㅇㅣ").finish().text) } + /** A final after a lone vowel has no syllable to live in, but it is still typed text. */+ @Test+ fun `a final consonant after a lone vowel stays visible`() {+ assertEquals("ㅏㄱ", hangul().type("ㅏㄱ").finish().text)+ assertEquals("ㅏ", hangul().type("ㅏㄱ").backspace().finish().text)+ // The kept half of a compound final survives when a vowel steals the rest.+ assertEquals("ㅏㄱ사", hangul().type("ㅏㄱㅅㅏ").finish().text)+ }+ /** Backspace takes the block apart jamo by jamo instead of deleting the whole syllable. */ @Test fun `backspace decomposes`() {