Defer macOS arrow and backspace handling to framework (flutter/engine#22063)
The Flutter framework now has handling for arrow keys and backspace in its editable text, so they no longer need to be handled in the embedding. This not only avoids duplicate work, but improves the handling of complex unicode (surrogate pairs, grapheme clusters) which are currently correctly handled in the framework but not the macOS embedding. Fixes https://github.com/flutter/flutter/issues/68497
This commit is contained in:
@@ -142,56 +142,6 @@ static NSString* const kMultilineInputType = @"TextInputType.multiline";
|
||||
[_textInputContext handleEvent:event];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark NSStandardKeyBindingMethods
|
||||
|
||||
/**
|
||||
* Note, experimentation indicates that moveRight and moveLeft are called rather
|
||||
* than the supposedly more RTL-friendly moveForward and moveBackward.
|
||||
*/
|
||||
- (void)moveLeft:(nullable id)sender {
|
||||
NSRange selection = self.activeModel.selectedRange;
|
||||
if (selection.length == 0) {
|
||||
if (selection.location > 0) {
|
||||
// Move to previous location
|
||||
self.activeModel.selectedRange = NSMakeRange(selection.location - 1, 0);
|
||||
[self updateEditState];
|
||||
}
|
||||
} else {
|
||||
// Collapse current selection
|
||||
self.activeModel.selectedRange = NSMakeRange(selection.location, 0);
|
||||
[self updateEditState];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)moveRight:(nullable id)sender {
|
||||
NSRange selection = self.activeModel.selectedRange;
|
||||
if (selection.length == 0) {
|
||||
if (selection.location < self.activeModel.text.length) {
|
||||
// Move to next location
|
||||
self.activeModel.selectedRange = NSMakeRange(selection.location + 1, 0);
|
||||
[self updateEditState];
|
||||
}
|
||||
} else {
|
||||
// Collapse current selection
|
||||
self.activeModel.selectedRange = NSMakeRange(selection.location + selection.length, 0);
|
||||
[self updateEditState];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deleteBackward:(id)sender {
|
||||
NSRange selection = self.activeModel.selectedRange;
|
||||
NSRange range = selection;
|
||||
if (selection.length == 0) {
|
||||
if (selection.location == 0)
|
||||
return;
|
||||
NSUInteger location = (selection.location == NSNotFound) ? self.activeModel.text.length - 1
|
||||
: selection.location - 1;
|
||||
range = NSMakeRange(location, 1);
|
||||
}
|
||||
[self insertText:@"" replacementRange:range]; // Updates edit state
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark NSTextInputClient
|
||||
|
||||
|
||||
Reference in New Issue
Block a user