From 7daf6a07b0f2634376c6d1145862d13701d8c270 Mon Sep 17 00:00:00 2001 From: Core Date: Tue, 26 Feb 2019 18:18:48 +0700 Subject: [PATCH 1/9] Handle deleteBackward when _selectedTextRange isEmpty but text.length > 0 --- .../framework/Source/FlutterTextInputPlugin.mm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index d6b8873adc6bc..7dc23e8eb58c7 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -621,8 +621,19 @@ - (void)insertText:(NSString*)text { - (void)deleteBackward { _selectionAffinity = _kTextAffinityDownstream; - if (!_selectedTextRange.isEmpty) - [self replaceRange:_selectedTextRange withText:@""]; + if([self hasText]) { + if(!_selectedTextRange.isEmpty){ + [self replaceRange:_selectedTextRange withText:@""]; + }else{ + NSRange oldRange = ((FlutterTextRange*) _selectedTextRange).range; + if(oldRange.location > 0){ + [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(oldRange.location - 1, 1)] updateEditingState:false]; + }else{ + [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)] updateEditingState:false]; + } + [self replaceRange:_selectedTextRange withText:@""]; + } + } } @end From 6616cc1db363df7b8795274f83b18c8f800210d0 Mon Sep 17 00:00:00 2001 From: Core Date: Tue, 26 Feb 2019 19:22:04 +0700 Subject: [PATCH 2/9] Format file --- .../Source/FlutterTextInputPlugin.mm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 7dc23e8eb58c7..18c8cef441cd0 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -621,15 +621,18 @@ - (void)insertText:(NSString*)text { - (void)deleteBackward { _selectionAffinity = _kTextAffinityDownstream; - if([self hasText]) { - if(!_selectedTextRange.isEmpty){ + if ([self hasText]) { + if (!_selectedTextRange.isEmpty) { [self replaceRange:_selectedTextRange withText:@""]; - }else{ - NSRange oldRange = ((FlutterTextRange*) _selectedTextRange).range; - if(oldRange.location > 0){ - [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(oldRange.location - 1, 1)] updateEditingState:false]; - }else{ - [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)] updateEditingState:false]; + } else { + NSRange oldRange = ((FlutterTextRange*)_selectedTextRange).range; + if (oldRange.location > 0) { + [self setSelectedTextRange:[FlutterTextRange + rangeWithNSRange:NSMakeRange(oldRange.location - 1, 1)] + updateEditingState:false]; + } else { + [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)] + updateEditingState:false]; } [self replaceRange:_selectedTextRange withText:@""]; } From ba85b8f9d0a4315efa0c53f42466d73554d9431c Mon Sep 17 00:00:00 2001 From: Mechin Date: Thu, 28 Feb 2019 21:54:40 +0700 Subject: [PATCH 3/9] Rewrite logic --- .../Source/FlutterTextInputPlugin.mm | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 18c8cef441cd0..9b4721218162a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -622,20 +622,16 @@ - (void)insertText:(NSString*)text { - (void)deleteBackward { _selectionAffinity = _kTextAffinityDownstream; if ([self hasText]) { - if (!_selectedTextRange.isEmpty) { - [self replaceRange:_selectedTextRange withText:@""]; - } else { + if (_selectedTextRange.isEmpty) { + // When deleting combining characters, + // _selectedTextRange oftens empty, so we have to manually set it. NSRange oldRange = ((FlutterTextRange*)_selectedTextRange).range; - if (oldRange.location > 0) { - [self setSelectedTextRange:[FlutterTextRange - rangeWithNSRange:NSMakeRange(oldRange.location - 1, 1)] - updateEditingState:false]; - } else { - [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)] - updateEditingState:false]; - } - [self replaceRange:_selectedTextRange withText:@""]; + NSUInteger newLocation = oldRange.location > 0 ? oldRange.location - 1 : 0; + NSRange newRange = NSMakeRange(newLocation, 1); + [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:newRange] + updateEditingState:false]; } + [self replaceRange:_selectedTextRange withText:@""]; } } From d80e968f4479251ab43224ec37edad74a9501db8 Mon Sep 17 00:00:00 2001 From: Core Date: Fri, 1 Mar 2019 10:42:44 +0700 Subject: [PATCH 4/9] Update FlutterTextInputPlugin.mm --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 9b4721218162a..a2a23314a08d2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -624,7 +624,7 @@ - (void)deleteBackward { if ([self hasText]) { if (_selectedTextRange.isEmpty) { // When deleting combining characters, - // _selectedTextRange oftens empty, so we have to manually set it. + // _selectedTextRange is oftens empty, so we have to manually set it. NSRange oldRange = ((FlutterTextRange*)_selectedTextRange).range; NSUInteger newLocation = oldRange.location > 0 ? oldRange.location - 1 : 0; NSRange newRange = NSMakeRange(newLocation, 1); From 96b9516dd7155adcabbcddc5a84242df1ff0e502 Mon Sep 17 00:00:00 2001 From: Core Date: Fri, 1 Mar 2019 14:21:15 +0700 Subject: [PATCH 5/9] Optimize logic --- .../ios/framework/Source/FlutterTextInputPlugin.mm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index a2a23314a08d2..e4b054b41e8a0 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -623,13 +623,14 @@ - (void)deleteBackward { _selectionAffinity = _kTextAffinityDownstream; if ([self hasText]) { if (_selectedTextRange.isEmpty) { - // When deleting combining characters, - // _selectedTextRange is oftens empty, so we have to manually set it. + // When delete a combining character, _selectedTextRange has location + // but does not have length, so we have to manually set it. NSRange oldRange = ((FlutterTextRange*)_selectedTextRange).range; - NSUInteger newLocation = oldRange.location > 0 ? oldRange.location - 1 : 0; - NSRange newRange = NSMakeRange(newLocation, 1); - [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:newRange] - updateEditingState:false]; + if (oldRange.location > 0) { + NSRange newRange = NSMakeRange(oldRange.location - 1, 1); + [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:newRange] + updateEditingState:false]; + } } [self replaceRange:_selectedTextRange withText:@""]; } From 7315a77a91767b4a7baf1b9e7cc183648430155e Mon Sep 17 00:00:00 2001 From: Core Date: Fri, 1 Mar 2019 14:29:16 +0700 Subject: [PATCH 6/9] Merge condition and simplify logic --- .../Source/FlutterTextInputPlugin.mm | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index e4b054b41e8a0..68f888fcf7a25 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -621,19 +621,20 @@ - (void)insertText:(NSString*)text { - (void)deleteBackward { _selectionAffinity = _kTextAffinityDownstream; - if ([self hasText]) { - if (_selectedTextRange.isEmpty) { - // When delete a combining character, _selectedTextRange has location - // but does not have length, so we have to manually set it. - NSRange oldRange = ((FlutterTextRange*)_selectedTextRange).range; - if (oldRange.location > 0) { - NSRange newRange = NSMakeRange(oldRange.location - 1, 1); - [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:newRange] - updateEditingState:false]; - } + + // When delete a combining character, _selectedTextRange has location + // but does not have length, so we have to manually set it. + if (_selectedTextRange.isEmpty && [self hasText]) { + NSRange oldRange = ((FlutterTextRange*)_selectedTextRange).range; + if (oldRange.location > 0) { + NSRange newRange = NSMakeRange(oldRange.location - 1, 1); + [self setSelectedTextRange:[FlutterTextRange rangeWithNSRange:newRange] + updateEditingState:false]; } - [self replaceRange:_selectedTextRange withText:@""]; } + + if (!_selectedTextRange.isEmpty) + [self replaceRange:_selectedTextRange withText:@""]; } @end From b5c11f4ac1da9b9b5cd47358628f23bb2e2b4d4a Mon Sep 17 00:00:00 2001 From: Core Date: Tue, 5 Mar 2019 09:33:10 +0700 Subject: [PATCH 7/9] Update FlutterTextInputPlugin.mm --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 68f888fcf7a25..f9006718ae1d9 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -622,7 +622,7 @@ - (void)insertText:(NSString*)text { - (void)deleteBackward { _selectionAffinity = _kTextAffinityDownstream; - // When delete a combining character, _selectedTextRange has location + // When deleting a combining character, _selectedTextRange has location // but does not have length, so we have to manually set it. if (_selectedTextRange.isEmpty && [self hasText]) { NSRange oldRange = ((FlutterTextRange*)_selectedTextRange).range; From 42f4ef839310e766d428d062464544c4dcc2fa37 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 6 Mar 2019 14:19:21 -0800 Subject: [PATCH 8/9] Add details about Thai input to backspace handling --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index f9006718ae1d9..65dc6510da949 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -624,6 +624,11 @@ - (void)deleteBackward { // When deleting a combining character, _selectedTextRange has location // but does not have length, so we have to manually set it. + // + // This is needed for correct handling of the deletion of Thai vowel input. + // TODO(cbracken): Get a good understanding of expected behaviour of Thai + // input and ensure that this is the correct solution. + // https://github.com/flutter/flutter/issues/28962 if (_selectedTextRange.isEmpty && [self hasText]) { NSRange oldRange = ((FlutterTextRange*)_selectedTextRange).range; if (oldRange.location > 0) { From 70816eca46116b949d68858c73d225c8d8b1e69c Mon Sep 17 00:00:00 2001 From: Core Date: Thu, 7 Mar 2019 11:58:44 +0700 Subject: [PATCH 9/9] Add a comment and links. --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 65dc6510da949..dd8971f402e58 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -622,8 +622,12 @@ - (void)insertText:(NSString*)text { - (void)deleteBackward { _selectionAffinity = _kTextAffinityDownstream; - // When deleting a combining character, _selectedTextRange has location + // When deleting Thai vowel, _selectedTextRange has location // but does not have length, so we have to manually set it. + // In addition, we needed to delete only a part of grapheme cluster + // because it is the expected behavior of Thai input. + // https://github.com/flutter/flutter/issues/24203 + // https://github.com/flutter/flutter/issues/21745 // // This is needed for correct handling of the deletion of Thai vowel input. // TODO(cbracken): Get a good understanding of expected behaviour of Thai