Fix delete of entire selection in macOS text input (flutter/engine#16276)

Fixes a bug where deleteBackward was checking for being at the start of
the text before checking for a non-empty selection, breaking deletion
when the entire text field was selected.

Also removes an (incorrect) post-deletion position update that was
redundant with code in insertText:replacementRange:, and thus having no
effect.

Fixes https://github.com/flutter/flutter/issues/46150
This commit is contained in:
stuartmorgan 2020-02-03 15:22:44 -08:00 committed by GitHub
parent 950eb2447f
commit 3d5bb2ac20

View File

@ -181,15 +181,14 @@ static NSString* const kMultilineInputType = @"TextInputType.multiline";
- (void)deleteBackward:(id)sender {
NSRange selection = self.activeModel.selectedRange;
if (selection.location == 0)
return;
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.activeModel.selectedRange = NSMakeRange(range.location, 0);
[self insertText:@"" replacementRange:range]; // Updates edit state
}