Repository navigation
[Cocoa] Commit the IME composition on a click or a focus change - #3876
Open
Jm6CnDDXBwFTakS wants to merge 2 commits into
Open
Jm6CnDDXBwFTakS wants to merge 2 commits into
Jm6CnDDXBwFTakS wants to merge 2 commits into
Conversation
The input method asks a Canvas with an IME for the selected range as soon as it starts composing. IME.selectedRange and IME.attributedSubstringFromRange send a COMPOSITION_SELECTION event and then read event.text. When the IME has no ImeComposition listener, or the listener leaves the text unset, that is null, and typing with an input method such as Japanese Romaji throws a NullPointerException. Treat a missing text as empty. Assisted-by: Claude Opus 5.5 <[email protected]>
A Canvas with an inline IME, StyledText among them, never ended an input method composition when the user clicked elsewhere or moved the focus to another control. The input method (for example Japanese Romaji) does not commit by itself, and unmarkText was a stub, so the marked text stayed and the next keystroke joined the old composition, wherever the caret had moved to. Do what NSTextView does: - unmarkText commits the marked text through a COMPOSITION_CHANGED event with a full commit count, then sends the text as KeyDown events, as Control.insertText does for text that a key commits. StyledText inserts the committed text from these. They carry no key code, so that the key that made the input method commit is not taken for its own action. - A left mouse down outside the composition commits it and makes the input method discard its marked text, so that the next keystroke starts a new composition. A click inside the composition is left to the input method, as on Windows. Where the click lies comes from COMPOSITION_OFFSET. - When the canvas resigns as first responder, the composition is committed the same way. Deactivating the window or the application keeps the composition, as in TextEdit. NSView.inputContext and NSTextInputContext.discardMarkedText are generated with MacGenerator. Fixes eclipse-platform#3875 Assisted-by: Claude Opus 5.5 <[email protected]>
Contributor
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.
Fixes #3875.
On macOS, an input-method composition in a
StyledText, or in anyCanvaswith an inlineIME, now ends the way it does in a native text view (TextEdit):IME.WM_LBUTTONDOWNon Windows.COMPOSITION_OFFSETtells where the click lies.unmarkTextis no longer a stub. It commits the marked text through aCOMPOSITION_CHANGEDevent with a full commit count, then sends the text asKeyDownevents, asControl.insertTextdoes for text that a key commits.StyledTextinserts the committed text from these. They carry the character only, with no key code, so that a key which made the input method commit is not taken for its own action.IME.selectedRangeandIME.attributedSubstringFromRangeno longer throw aNullPointerExceptionwhen noImeCompositionlistener setsevent.text. This is the first commit.NSView.inputContextandNSTextInputContext.discardMarkedTextare generated with MacGenerator. They are new entries inAppKitFull.bridgesupport.extras, and no native code changes.How it was tested
By hand on macOS 27.2 (Apple Silicon), with the snippet from #3875 and a test canvas whose IME listener logs every event:
Textcommits it;KeyDowns.KeyDown: no exception.mvn verifyfororg.eclipse.swt.testswith theCanvas,Composite,Caret,TextandStyledTexttests: 637 tests run. OnlyTest_org_eclipse_swt_widgets_Text.test_backspaceAndDeleteandTest_org_eclipse_swt_custom_StyledText.test_backspaceAndDeletefail. They fail the same way on unchanged master on this machine, becauseDisplay.postkeys do not arrive without the Accessibility permission.Not covered
Two guards that no tested input method reached.
unmarkTextduring a keystroke,Shell.keyInputHappenedkeepsComposite.keyDownfrom sending that key a second time.discardMarkedTextwithinsertText:, the text is not inserted again.Japanese, Korean and Pinyin do neither, so these paths are defensive.
A click inside the composition is not forwarded to the input method. SWT still uses the deprecated
NSInputManagerfor mouse events, not-[NSTextInputContext handleEvent:].Clicks on controls that do not take the focus do not commit, for example a toolbar or a button with full keyboard access off. Nothing makes the canvas resign as first responder then.
Two related problems are left for separate changes:
StyledTextruns the arrow key's action instead of inserting the committed Korean syllable.insertText:during a flags-changed event, andControl.insertTextsends noKeyDowns for it, soStyledTextloses the text.🤖 Generated with Claude Code