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
Position accent popup window next to caret #24867
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,6 +137,16 @@ @implementation FlutterTextInputPlugin { | |
| * The currently active text input model. | ||
| */ | ||
| std::unique_ptr<flutter::TextInputModel> _activeModel; | ||
|
|
||
| /** | ||
| * Transform for current the editable. Used to determine position of accent selection menu. | ||
| */ | ||
| CATransform3D _editableTransform; | ||
|
|
||
| /** | ||
| * Current position of caret in local (editable) coordinates. | ||
| */ | ||
| CGRect _caretRect; | ||
| } | ||
|
|
||
| - (instancetype)initWithViewController:(FlutterViewController*)viewController { | ||
|
|
@@ -152,6 +162,11 @@ - (instancetype)initWithViewController:(FlutterViewController*)viewController { | |
| }]; | ||
| _textInputContext = [[NSTextInputContext alloc] initWithClient:self]; | ||
| _previouslyPressedFlags = 0; | ||
|
|
||
| // Initialize with the zero matrix which is not | ||
| // an affine transform. | ||
| _editableTransform = CATransform3D(); | ||
| _caretRect = CGRectNull; | ||
| } | ||
| return self; | ||
| } | ||
|
|
@@ -200,12 +215,50 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { | |
| // engine since it sent this update, and needs to now be made to match the | ||
| // engine's version of the state. | ||
| [self updateEditState]; | ||
| } else if ([method isEqualToString:@"TextInput.setEditableSizeAndTransform"]) { | ||
| NSDictionary* state = call.arguments; | ||
| [self setEditableTransform:state[@"transform"]]; | ||
| } else if ([method isEqualToString:@"TextInput.setCaretRect"]) { | ||
| NSDictionary* rect = call.arguments; | ||
| [self updateCaretRect:rect]; | ||
| } else { | ||
| handled = NO; | ||
| } | ||
| result(handled ? nil : FlutterMethodNotImplemented); | ||
| } | ||
|
|
||
| - (void)setEditableTransform:(NSArray*)matrix { | ||
| CATransform3D* transform = &_editableTransform; | ||
|
|
||
| transform->m11 = [matrix[0] doubleValue]; | ||
| transform->m12 = [matrix[1] doubleValue]; | ||
| transform->m13 = [matrix[2] doubleValue]; | ||
| transform->m14 = [matrix[3] doubleValue]; | ||
|
|
||
| transform->m21 = [matrix[4] doubleValue]; | ||
| transform->m22 = [matrix[5] doubleValue]; | ||
| transform->m23 = [matrix[6] doubleValue]; | ||
| transform->m24 = [matrix[7] doubleValue]; | ||
|
|
||
| transform->m31 = [matrix[8] doubleValue]; | ||
| transform->m32 = [matrix[9] doubleValue]; | ||
| transform->m33 = [matrix[10] doubleValue]; | ||
| transform->m34 = [matrix[11] doubleValue]; | ||
|
|
||
| transform->m41 = [matrix[12] doubleValue]; | ||
| transform->m42 = [matrix[13] doubleValue]; | ||
| transform->m43 = [matrix[14] doubleValue]; | ||
| transform->m44 = [matrix[15] doubleValue]; | ||
| } | ||
|
|
||
| - (void)updateCaretRect:(NSDictionary*)dictionary { | ||
| NSAssert(dictionary[@"x"] != nil && dictionary[@"y"] != nil && dictionary[@"width"] != nil && | ||
| dictionary[@"height"] != nil, | ||
| @"Expected a dictionary representing a CGRect, got %@", dictionary); | ||
| _caretRect = CGRectMake([dictionary[@"x"] doubleValue], [dictionary[@"y"] doubleValue], | ||
| [dictionary[@"width"] doubleValue], [dictionary[@"height"] doubleValue]); | ||
| } | ||
|
|
||
| - (void)setEditingState:(NSDictionary*)state { | ||
| NSString* selectionAffinity = state[kSelectionAffinityKey]; | ||
| if (selectionAffinity != nil) { | ||
|
|
@@ -403,9 +456,19 @@ - (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range | |
| } | ||
|
|
||
| - (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actualRange { | ||
| // TODO: Implement. | ||
| // Note: This function can't easily be implemented under the system-message architecture. | ||
| return CGRectZero; | ||
| // This only determines position of caret instead of any arbitrary range, but it's enough | ||
| // to properly position accent selection popup | ||
| if (CATransform3DIsAffine(_editableTransform) && !CGRectEqualToRect(_caretRect, CGRectNull)) { | ||
| CGRect rect = | ||
| CGRectApplyAffineTransform(_caretRect, CATransform3DGetAffineTransform(_editableTransform)); | ||
|
|
||
| // flip and convert to screen coordinates | ||
| double viewHeight = self.flutterViewController.view.bounds.size.height; | ||
|
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. self.flutterViewController will be null here ref https://github.com/flutter/engine/pull/23469/files#r612811988
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. I noticed that :) Should be fixed in #25524 . |
||
| rect.origin.y = viewHeight - rect.origin.y; | ||
| return [self.flutterViewController.view.window convertRectToScreen:rect]; | ||
| } else { | ||
| return CGRectZero; | ||
| } | ||
| } | ||
|
|
||
| - (NSUInteger)characterIndexForPoint:(NSPoint)point { | ||
|
|
||
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.
Added comments on flutter/flutter#77608. I'd have thought that
TextInput.setMarkedTextRectshould be sufficient here -- despite its name, it should emit the current caret rect when the composing range is empty.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.
As noted in flutter/flutter#77608,
TextInput.setMarkedTextRectonly works while compositing. So we need another method for caret position.