Repository navigation
fix(mobile): recompose iOS NFD Hangul before terminal send #11246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| buildTerminalLiveMirrorPayload, | ||
| computeTerminalLiveMirrorStep | ||
| } from './terminal-live-hangul-mirror' | ||
| import { normalizeTerminalTextInput } from './terminal-text-input-normalization' | ||
|
|
||
| // 두벌식 (2-set) composition states for 안녕하세요, as the field shows them | ||
| // keystroke by keystroke: ㅇ ㅏ ㄴ ㄴ ㅕ ㅇ ㅎ ㅏ ㅅ ㅔ ㅇ ㅛ. | ||
| const DUBEOLSIK_FIELD_STATES = [ | ||
| 'ㅇ', | ||
| '아', | ||
| '안', | ||
| '안ㄴ', | ||
| '안녀', | ||
| '안녕', | ||
| '안녕ㅎ', | ||
| '안녕하', | ||
| '안녕핫', | ||
| '안녕하세', | ||
| '안녕하셍', | ||
| '안녕하세요' | ||
| ] as const | ||
|
|
||
| const DEL = '\x7f' | ||
|
|
||
| // Minimal PTY line model: DEL erases one code point, everything else appends. | ||
| function applyToPty(pty: string, payload: string): string { | ||
| let next = Array.from(pty) | ||
| for (const codePoint of Array.from(payload)) { | ||
| if (codePoint === DEL) { | ||
| next = next.slice(0, -1) | ||
| continue | ||
| } | ||
| next.push(codePoint) | ||
| } | ||
| return next.join('') | ||
| } | ||
|
|
||
| // Replays handleLiveInputChange → applyLiveInputMirror, then the settle-timer | ||
| // commit that flushes the last held syllable. | ||
| function replayLiveInput(fieldStates: readonly string[]): string { | ||
| let sentText = '' | ||
| let heldText = '' | ||
| let pty = '' | ||
|
|
||
| const step = (fieldText: string, commitHeld: boolean): void => { | ||
| const mirror = computeTerminalLiveMirrorStep(sentText, normalizeTerminalTextInput(fieldText), { | ||
| commitHeld | ||
| }) | ||
| pty = applyToPty(pty, buildTerminalLiveMirrorPayload(mirror)) | ||
| sentText = mirror.nextSentText | ||
| heldText = mirror.heldText | ||
| } | ||
|
|
||
| for (const fieldText of fieldStates) { | ||
| step(fieldText, false) | ||
| } | ||
| step(sentText + heldText, true) | ||
| return pty | ||
| } | ||
|
|
||
| describe('iOS decomposed (NFD) Hangul live input', () => { | ||
| it('Given an NFD field (iOS) When the user types 안녕하세요 Then the PTY receives composed syllables, not jamo', () => { | ||
| // Given: Apple text input hands React Native decomposed conjoining jamo, so | ||
| // one syllable arrives as 2-3 code points instead of one. | ||
| const nfdStates = DUBEOLSIK_FIELD_STATES.map((state) => state.normalize('NFD')) | ||
| expect(Array.from(nfdStates.at(-1) ?? '')).toHaveLength(12) | ||
|
|
||
| // When | ||
| const pty = replayLiveInput(nfdStates) | ||
|
|
||
| // Then: the mirror holds only the trailing code point, so without | ||
| // recomposition every leading jamo is committed on its own (#6995 iOS). | ||
| expect(Array.from(pty)).toHaveLength(5) | ||
| expect(pty).toBe('안녕하세요') | ||
| }) | ||
|
|
||
| it('Given a precomposed NFC field (Android/Gboard) When the same keys are typed Then the PTY result is unchanged', () => { | ||
| // Given / When | ||
| const pty = replayLiveInput(DUBEOLSIK_FIELD_STATES) | ||
|
|
||
| // Then | ||
| expect(pty).toBe('안녕하세요') | ||
| }) | ||
|
|
||
| it('Given NFD Latin diacritics When mirrored Then combining marks reach the PTY already composed', () => { | ||
| // Given / When: iOS also hands back NFD for Vietnamese/European accents. | ||
| const pty = replayLiveInput(['tie', 'tiế', 'tiếng'].map((state) => state.normalize('NFD'))) | ||
|
|
||
| // Then | ||
| expect(pty).toBe('tiếng') | ||
| expect(Array.from(pty)).toHaveLength(5) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct and shorten this rationale comment.
Line 9 references
#6995, but the PR objective identifies the affected issue as#11235. Reduce this to one concise rationale line while correcting or removing the ticket reference.Proposed fix
As per coding guidelines, “Comments must be concise, limited to non-obvious information, and preferably one line.”
📝 Committable suggestion
Source: Coding guidelines