Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 12dff9a

Browse files
author
Chris Yang
committed
draft fix
format fix fix fix delete multiple
1 parent c67b332 commit 12dff9a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ source_set("flutter_framework_source") {
174174
frameworks = [
175175
"AudioToolbox.framework",
176176
"CoreMedia.framework",
177+
"CoreText.framework",
177178
"CoreVideo.framework",
178179
"QuartzCore.framework",
179180
"UIKit.framework",

shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
66

7+
#import <CoreText/CoreText.h>
78
#import <Foundation/Foundation.h>
89
#import <UIKit/UIKit.h>
910

@@ -74,6 +75,28 @@
7475

7576
#pragma mark - Static Functions
7677

78+
// static CFMutableCharacterSetRef EmojiCharacterSet() {
79+
// static CFMutableCharacterSetRef set = nil;
80+
// static dispatch_once_t onceToken;
81+
// dispatch_once(&onceToken, ^{
82+
// set = CFCharacterSetCreateMutableCopy(
83+
// kCFAllocatorDefault,
84+
// CTFontCopyCharacterSet(CTFontCreateWithName(CFSTR("AppleColorEmoji"), 0.0, NULL)));
85+
// CFCharacterSetRemoveCharactersInString(set, CFSTR(" 0123456789#*"));
86+
// });
87+
// return set;
88+
// }
89+
90+
// static NSString* GetEmoji(NSString* string) {
91+
// CFRange result;
92+
// BOOL found = CFStringFindCharacterFromSet((CFStringRef)string, EmojiCharacterSet(),
93+
// CFRangeMake(0, string.length), 0, &result);
94+
// if (!found) {
95+
// return nil;
96+
// }
97+
// return [string substringWithRange:NSMakeRange(result.location, result.length)];
98+
// }
99+
77100
// "TextInputType.none" is a made-up input type that's typically
78101
// used when there's an in-app virtual keyboard. If
79102
// "TextInputType.none" is specified, disable the system
@@ -702,6 +725,7 @@ @interface FlutterTextInputView ()
702725
@property(nonatomic, assign) CGRect markedRect;
703726
@property(nonatomic) BOOL isVisibleToAutofill;
704727
@property(nonatomic, assign) BOOL accessibilityEnabled;
728+
@property(nonatomic, copy) NSString* lastComposedCharacters;
705729

706730
- (void)setEditableTransform:(NSArray*)matrix;
707731
@end
@@ -880,6 +904,8 @@ - (void)dealloc {
880904
[_markedTextStyle release];
881905
[_textContentType release];
882906
[_textInteraction release];
907+
[_lastComposedCharacters release];
908+
_lastComposedCharacters = nil;
883909
[super dealloc];
884910
}
885911

@@ -1848,6 +1874,10 @@ - (BOOL)hasText {
18481874
}
18491875

18501876
- (void)insertText:(NSString*)text {
1877+
if (!text.UTF8String && text.length > 0 && text.length == 1 &&
1878+
[text characterAtIndex:0] == [self.lastComposedCharacters characterAtIndex:0]) {
1879+
text = self.lastComposedCharacters;
1880+
}
18511881
NSMutableArray<FlutterTextSelectionRect*>* copiedRects =
18521882
[[NSMutableArray alloc] initWithCapacity:[_selectionRects count]];
18531883
NSAssert([_selectedTextRange.start isKindOfClass:[FlutterTextPosition class]],
@@ -1936,6 +1966,12 @@ - (void)deleteBackward {
19361966
}
19371967

19381968
if (!_selectedTextRange.isEmpty) {
1969+
NSString* deletedText = [self.text substringWithRange:_selectedTextRange.range];
1970+
CFRange range =
1971+
CFStringGetRangeOfComposedCharactersAtIndex((__bridge CFStringRef)deletedText, 0);
1972+
self.lastComposedCharacters =
1973+
[deletedText substringWithRange:NSMakeRange(range.location, range.length)];
1974+
19391975
[self replaceRange:_selectedTextRange withText:@""];
19401976
}
19411977
}

0 commit comments

Comments
 (0)