From f0f09665d39a5e46422cc5ada3be0e183fe2a2b4 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 27 Apr 2017 16:04:30 -0700 Subject: [PATCH] Clamp iOS selection to 0 < pos < length (flutter/engine#3636) --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 83c1a88f99..5624173d4e 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -169,8 +169,8 @@ static UIKeyboardType ToUIKeyboardType(NSString* inputType) { NSInteger selectionBase = [state[@"selectionBase"] intValue]; NSInteger selectionExtent = [state[@"selectionExtent"] intValue]; - NSUInteger start = MAX(0, MIN(selectionBase, selectionExtent)); - NSUInteger end = MAX(0, MAX(selectionBase, selectionExtent)); + NSUInteger start = MIN(MAX(0, MIN(selectionBase, selectionExtent)), (NSInteger)self.text.length); + NSUInteger end = MIN(MAX(0, MAX(selectionBase, selectionExtent)), (NSInteger)self.text.length); NSRange selectedRange = NSMakeRange(start, end - start); [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:selectedRange] updateEditingState:NO];