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 3 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,29 @@ | ||
| import AppKit | ||
|
|
||
| extension GhosttyNSView { | ||
| 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) | ||
| } | ||
|
|
||
| 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) | ||
| } | ||
| } |
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
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,83 @@ | ||
| import XCTest | ||
| import AppKit | ||
|
|
||
| #if canImport(cmux_DEV) | ||
| @testable import cmux_DEV | ||
| #elseif canImport(cmux) | ||
| @testable import cmux | ||
| #endif | ||
|
|
||
| final class CJKIMEMarkedSelectionTests: XCTestCase { | ||
|
austinywang marked this conversation as resolved.
Resolved
|
||
| func testSelectedRangeReturnsEmptyRangeWithoutSelectionOrMarkedText() { | ||
| let view = GhosttyNSView(frame: .zero) | ||
| let range = view.selectedRange() | ||
| XCTAssertEqual(range, NSRange(location: 0, length: 0)) | ||
| } | ||
|
|
||
| func testSelectedRangeTracksMarkedTextSelection() { | ||
| let view = GhosttyNSView(frame: .zero) | ||
|
|
||
| view.setMarkedText( | ||
| "にほんご", | ||
| selectedRange: NSRange(location: 2, length: 1), | ||
| replacementRange: NSRange(location: NSNotFound, length: 0) | ||
| ) | ||
|
|
||
| XCTAssertEqual( | ||
| view.selectedRange(), | ||
| NSRange(location: 2, length: 1), | ||
| "selectedRange should mirror the IME caret/selection inside marked text" | ||
| ) | ||
| } | ||
|
|
||
| func testSelectedRangeReturnsEmptyRangeAfterCompositionEnds() { | ||
| let view = GhosttyNSView(frame: .zero) | ||
|
|
||
| view.setMarkedText( | ||
| "東京", | ||
| selectedRange: NSRange(location: 1, length: 0), | ||
| replacementRange: NSRange(location: NSNotFound, length: 0) | ||
| ) | ||
| view.unmarkText() | ||
|
|
||
| XCTAssertEqual(view.selectedRange(), NSRange(location: 0, length: 0)) | ||
| } | ||
|
|
||
| func testAttributedSubstringReturnsMarkedTextSegment() { | ||
| let view = GhosttyNSView(frame: .zero) | ||
| view.setMarkedText( | ||
| "とうきょう", | ||
| selectedRange: NSRange(location: 3, length: 0), | ||
| replacementRange: NSRange(location: NSNotFound, length: 0) | ||
| ) | ||
|
|
||
| var actualRange = NSRange(location: NSNotFound, length: 0) | ||
| let substring = view.attributedSubstring( | ||
| forProposedRange: NSRange(location: 2, length: 2), | ||
| actualRange: &actualRange | ||
| ) | ||
|
|
||
| XCTAssertEqual(actualRange, NSRange(location: 2, length: 2)) | ||
| XCTAssertEqual(substring?.string, "きょ") | ||
| } | ||
|
|
||
| func testTraditionalChineseZhuyinMarkedTextSelectionAndSubstring() { | ||
| let view = GhosttyNSView(frame: .zero) | ||
| view.setMarkedText( | ||
| "ㄓㄨ", | ||
| selectedRange: NSRange(location: 2, length: 0), | ||
| replacementRange: NSRange(location: NSNotFound, length: 0) | ||
| ) | ||
|
|
||
| XCTAssertEqual(view.selectedRange(), NSRange(location: 2, length: 0)) | ||
|
|
||
| var actualRange = NSRange(location: NSNotFound, length: 0) | ||
| let substring = view.attributedSubstring( | ||
| forProposedRange: NSRange(location: 0, length: 2), | ||
| actualRange: &actualRange | ||
| ) | ||
|
|
||
| XCTAssertEqual(actualRange, NSRange(location: 0, length: 2)) | ||
| XCTAssertEqual(substring?.string, "ㄓㄨ") | ||
| } | ||
| } | ||
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.