Repository navigation
Restore Zhuyin IME candidate marked-text handling #3574
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db7382b
Restore marked-text ownership for IME composition
austinywang 096655f
Merge remote-tracking branch 'origin/main' into issue-3571-zhuyin-ime…
austinywang ff641de
Keep IME regression coverage reviewable
austinywang 79bf2b4
Satisfy IME test lint contract
austinywang 0bdca4a
Prevent duplicate terminal dispatch while IME owns marked text
austinywang 75869e9
Incorporate current main before IME validation
austinywang 4e68127
Keep IME bridge inside file-budget guardrails
austinywang 50cb0ff
Merge remote-tracking branch 'origin/main' into issue-3571-zhuyin-ime…
austinywang 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
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,66 @@ | ||
| import AppKit | ||
|
|
||
| extension GhosttyNSView { | ||
| /// Clamps AppKit's marked-text selection into the active preedit buffer. | ||
| func normalizedMarkedSelectionRange(_ range: NSRange, markedLength: Int) -> NSRange { | ||
| guard markedLength > 0 else { | ||
| return NSRange(location: NSNotFound, length: 0) | ||
| } | ||
| guard range.location != NSNotFound else { | ||
| return NSRange(location: markedLength, length: 0) | ||
| } | ||
|
|
||
| let clampedLocation = min(max(range.location, 0), markedLength) | ||
| let clampedLength = min(max(range.length, 0), markedLength - clampedLocation) | ||
| return NSRange(location: clampedLocation, length: clampedLength) | ||
| } | ||
|
|
||
| /// Clamps an AppKit substring query so it can be served from marked text. | ||
| func clampedMarkedTextRange(_ range: NSRange, markedLength: Int) -> NSRange? { | ||
| guard range.length > 0, range.location != NSNotFound else { return nil } | ||
| guard markedLength > 0 else { return nil } | ||
|
|
||
| let location = min(max(range.location, 0), markedLength) | ||
| let maxLength = markedLength - location | ||
| guard maxLength > 0 else { return nil } | ||
|
|
||
| let length = min(max(range.length, 0), maxLength) | ||
| guard length > 0 else { return nil } | ||
| return NSRange(location: location, length: length) | ||
| } | ||
|
|
||
| /// Returns true when AppKit consumed the key by changing IME composition state. | ||
| func shouldSuppressGhosttyKeyForwardingAfterIMEHandling( | ||
| before: (text: String, selection: NSRange), | ||
| after: (text: String, selection: NSRange), | ||
| accumulatedText: [String] | ||
| ) -> Bool { | ||
| guard accumulatedText.isEmpty else { return false } | ||
|
|
||
| let hadMarkedTextBefore = !before.text.isEmpty | ||
| let hasMarkedTextAfter = !after.text.isEmpty | ||
| guard hadMarkedTextBefore || hasMarkedTextAfter else { return false } | ||
|
|
||
| if before.text != after.text { | ||
| return true | ||
| } | ||
|
|
||
| return before.selection != after.selection | ||
| } | ||
|
|
||
| #if DEBUG | ||
| func shouldSuppressGhosttyKeyForwardingAfterIMEHandlingForTesting( | ||
| markedTextBefore: String, | ||
| markedSelectionBefore: NSRange, | ||
| markedTextAfter: String, | ||
| markedSelectionAfter: NSRange, | ||
| accumulatedText: [String] | ||
| ) -> Bool { | ||
| shouldSuppressGhosttyKeyForwardingAfterIMEHandling( | ||
| before: (markedTextBefore, markedSelectionBefore), | ||
| after: (markedTextAfter, markedSelectionAfter), | ||
| accumulatedText: accumulatedText | ||
| ) | ||
| } | ||
| #endif | ||
| } |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.