Fix #35: Fix Korean input composition and marked text handling#44
Open
nova286 wants to merge 3 commits into
Open
Fix #35: Fix Korean input composition and marked text handling#44nova286 wants to merge 3 commits into
nova286 wants to merge 3 commits into
Conversation
- Merge dual markedTextRange properties into single source of truth (_markedTextRange was never written, causing all internal marked text checks to fail — caret clamping, magnifier switching, selection rendering) - Set default markedTextStyle background color so IME recognizes marked text support and uses setMarkedText instead of insertText per jamo - Guard insertText to unmark before inserting when marked text is active - Fix force-unwrap crash in setMarkedText/deleteBackward when _lastTypeRange is nil on first input - Add 10 unit tests covering Korean/Chinese/Japanese composition Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…tWindow - Line 426: mag.snapshot! -> mag.snapshot? with nil coalescing - Line 477: mag.snapshot! -> mag.snapshot? with optional chaining Prevents Fatal error: Unexpectedly found nil while unwrapping an Optional value at TextEffectWindow.swift:477
Root cause: During Korean IME composition, setMarkedText called _updateOuterProperties() which triggers KVO on attributedText. External observers may respond by resetting text/attributedText, breaking the composition state and causing jamo (ㅇㅏㄴ) to land as separate characters instead of composing into a single syllable (안). Fix: Skip _updateOuterProperties() in setMarkedText when markedTextRange is not nil (i.e. during active IME composition). The outer properties will be synced when unmarkText is called after composition completes. Also includes: - Added missing _inputDelegate notifications in unmarkText() - Skip emoji fix in position(from:offset:) during IME composition - Fixed tokenizer to use self instead of empty UITextView() Fixes #35
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix Korean (Hangul) input not composing jamo into syllables. When typing Korean, individual jamo (ㅇㅏㄴ) now compose into syllables (안).
Root Cause
Three related bugs in
BSTextView.swift:Dual
markedTextRangeproperties: Two separate stored properties existed — the publicmarkedTextRange: UITextRange?(written bysetMarkedText) and the private_markedTextRange: TextRange?(never written, always nil). All 12 internal checks read_markedTextRange, so caret clamping, magnifier switching, and selection rendering during composition were all broken.markedTextStylewas nil: The property was declared but never had a default value and was unused insetMarkedText. Korean IME may check this property; if nil, it falls back toinsertTextper jamo instead of usingsetMarkedTextfor composition.insertTextdidn't handle active marked text: If IME commits viainsertTextwhile marked text is active, the composition state was left dangling.Also fixed: Force-unwrap crash in
setMarkedText/deleteBackwardwhen_lastTypeRangeis nil on first input.Changes
BSText/BSTextView.swiftFramework/BSTextTests/BSTextTests.swiftPackage.swiftTest plan
Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com