This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[macOS] Clear IME mark text on clear input client #31849
Merged
cbracken
merged 1 commit into
flutter:main
from
cbracken:cancel-compose-on-switch-textfields
Mar 7, 2022
Merged
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
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 |
|---|---|---|
|
|
@@ -275,6 +275,13 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { | |
| _shown = FALSE; | ||
| [_textInputContext deactivate]; | ||
| } else if ([method isEqualToString:kClearClientMethod]) { | ||
| // If there's an active mark region, commit it, end composing, and clear the IME's mark text. | ||
| if (_activeModel && _activeModel->composing()) { | ||
| _activeModel->CommitComposing(); | ||
| _activeModel->EndComposing(); | ||
| } | ||
| [_textInputContext discardMarkedText]; | ||
|
|
||
| _clientID = nil; | ||
| _inputAction = nil; | ||
| _enableDeltaModel = NO; | ||
|
|
@@ -360,22 +367,28 @@ - (void)setEditingState:(NSDictionary*)state { | |
| flutter::TextRange composing_range = RangeFromBaseExtent( | ||
| state[kComposingBaseKey], state[kComposingExtentKey], _activeModel->composing_range()); | ||
| size_t cursor_offset = selected_range.base() - composing_range.start(); | ||
| if (!composing_range.collapsed() && !_activeModel->composing()) { | ||
| _activeModel->BeginComposing(); | ||
|
Comment on lines
+370
to
+371
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this let you resume composing after unfocusing the field and coming back? Or maybe it's just cleanup.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is technically unrelated cleanup. This just ensures that if the framework tells us we have composing text, but the engine wasn't already composing, we set it to composing mode. Adding the test uncovered this bug. |
||
| } else if (composing_range.collapsed() && _activeModel->composing()) { | ||
| _activeModel->EndComposing(); | ||
| [_textInputContext discardMarkedText]; | ||
| } | ||
| _activeModel->SetComposingRange(composing_range, cursor_offset); | ||
| [_client becomeFirstResponder]; | ||
| [self updateTextAndSelection]; | ||
| } | ||
|
|
||
| - (void)updateEditState { | ||
| - (NSDictionary*)editingState { | ||
| if (_activeModel == nullptr) { | ||
| return; | ||
| return nil; | ||
| } | ||
|
|
||
| NSString* const textAffinity = [self textAffinityString]; | ||
|
|
||
| int composingBase = _activeModel->composing() ? _activeModel->composing_range().base() : -1; | ||
| int composingExtent = _activeModel->composing() ? _activeModel->composing_range().extent() : -1; | ||
|
|
||
| NSDictionary* state = @{ | ||
| return @{ | ||
| kSelectionBaseKey : @(_activeModel->selection().base()), | ||
| kSelectionExtentKey : @(_activeModel->selection().extent()), | ||
| kSelectionAffinityKey : textAffinity, | ||
|
|
@@ -384,7 +397,14 @@ - (void)updateEditState { | |
| kComposingExtentKey : @(composingExtent), | ||
| kTextKey : [NSString stringWithUTF8String:_activeModel->GetText().c_str()] | ||
| }; | ||
| } | ||
|
|
||
| - (void)updateEditState { | ||
| if (_activeModel == nullptr) { | ||
| return; | ||
| } | ||
|
|
||
| NSDictionary* state = [self editingState]; | ||
| [_channel invokeMethod:kUpdateEditStateResponseMethod arguments:@[ self.clientID, state ]]; | ||
| [self updateTextAndSelection]; | ||
| } | ||
|
|
||
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
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.
Is the end result that the composing text (e.g. "nihao") is in the field or the first choice characters ("你好")? If I try this on non-Flutter web or Mac, it seems to keep the composing text.
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.
Yep the end result is that we commit the current composing text and it remains in the field. Then we clear it from the IME's buffer.
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.
Cool that matches what I see on native then 👍