From a4618540260e8e8c4d2fa35ff30e5b1506ddfb0c Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 26 Oct 2020 12:56:30 -0700 Subject: [PATCH] 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 --- .../Source/FlutterTextInputPlugin.mm | 50 ------------------- 1 file changed, 50 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index 46af8dd395..515e3772e1 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -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