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

Commit 682a3de

Browse files
committed
reuse FlutterTextPosition/Range
1 parent 3c3a4df commit 682a3de

File tree

3 files changed

+23
-88
lines changed

3 files changed

+23
-88
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,23 @@
2525

2626
@end
2727

28+
/** An indexed position in the buffer of a Flutter text editing widget. */
29+
@interface FlutterTextPosition : UITextPosition
30+
31+
@property(nonatomic, readonly) NSUInteger index;
32+
33+
+ (instancetype)positionWithIndex:(NSUInteger)index;
34+
- (instancetype)initWithIndex:(NSUInteger)index;
35+
36+
@end
37+
38+
/** A range of text in the buffer of a Flutter text editing widget. */
39+
@interface FlutterTextRange : UITextRange<NSCopying>
40+
41+
@property(nonatomic, readonly) NSRange range;
42+
43+
+ (instancetype)rangeWithNSRange:(NSRange)range;
44+
45+
@end
46+
2847
#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ static UITextAutocapitalizationType ToUITextAutocapitalizationType(NSString* inp
4141

4242
#pragma mark - FlutterTextPosition
4343

44-
/** An indexed position in the buffer of a Flutter text editing widget. */
45-
@interface FlutterTextPosition : UITextPosition
46-
47-
@property(nonatomic, readonly) NSUInteger index;
48-
49-
+ (instancetype)positionWithIndex:(NSUInteger)index;
50-
- (instancetype)initWithIndex:(NSUInteger)index;
51-
52-
@end
53-
5444
@implementation FlutterTextPosition
5545

5646
+ (instancetype)positionWithIndex:(NSUInteger)index {
@@ -69,15 +59,6 @@ - (instancetype)initWithIndex:(NSUInteger)index {
6959

7060
#pragma mark - FlutterTextRange
7161

72-
/** A range of text in the buffer of a Flutter text editing widget. */
73-
@interface FlutterTextRange : UITextRange<NSCopying>
74-
75-
@property(nonatomic, readonly) NSRange range;
76-
77-
+ (instancetype)rangeWithNSRange:(NSRange)range;
78-
79-
@end
80-
8162
@implementation FlutterTextRange
8263

8364
+ (instancetype)rangeWithNSRange:(NSRange)range {

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

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,6 @@
77
#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
88
#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h"
99

10-
@interface InactiveTextPosition : UITextPosition
11-
12-
@property(nonatomic, readonly) NSUInteger index;
13-
14-
+ (instancetype)positionWithIndex:(NSUInteger)index;
15-
- (instancetype)initWithIndex:(NSUInteger)index;
16-
17-
@end
18-
19-
@implementation InactiveTextPosition
20-
21-
+ (instancetype)positionWithIndex:(NSUInteger)index {
22-
return [[[InactiveTextPosition alloc] initWithIndex:index] autorelease];
23-
}
24-
25-
- (instancetype)initWithIndex:(NSUInteger)index {
26-
self = [super init];
27-
if (self) {
28-
_index = index;
29-
}
30-
return self;
31-
}
32-
33-
@end
34-
35-
@interface InactiveTextRange : UITextRange<NSCopying>
36-
37-
@property(nonatomic, readonly) NSRange range;
38-
39-
+ (instancetype)rangeWithNSRange:(NSRange)range;
40-
41-
@end
42-
43-
@implementation InactiveTextRange
44-
45-
+ (instancetype)rangeWithNSRange:(NSRange)range {
46-
return [[[InactiveTextRange alloc] initWithNSRange:range] autorelease];
47-
}
48-
49-
- (instancetype)initWithNSRange:(NSRange)range {
50-
self = [super init];
51-
if (self) {
52-
_range = range;
53-
}
54-
return self;
55-
}
56-
57-
- (UITextPosition*)start {
58-
return [InactiveTextPosition positionWithIndex:self.range.location];
59-
}
60-
61-
- (UITextPosition*)end {
62-
return [InactiveTextPosition positionWithIndex:self.range.location + self.range.length];
63-
}
64-
65-
- (BOOL)isEmpty {
66-
return self.range.length == 0;
67-
}
68-
69-
- (id)copyWithZone:(NSZone*)zone {
70-
return [[InactiveTextRange allocWithZone:zone] initWithNSRange:self.range];
71-
}
72-
73-
@end
74-
7510
@implementation FlutterInactiveTextInput {
7611
}
7712

@@ -88,7 +23,7 @@ - (BOOL)hasText {
8823
}
8924

9025
- (NSString*)textInRange:(UITextRange*)range {
91-
NSRange textRange = ((InactiveTextRange*)range).range;
26+
NSRange textRange = ((FlutterTextRange*)range).range;
9227
return [self.text substringWithRange:textRange];
9328
}
9429

@@ -112,9 +47,9 @@ - (void)unmarkText {
11247

11348
- (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
11449
toPosition:(UITextPosition*)toPosition {
115-
NSUInteger fromIndex = ((InactiveTextPosition*)fromPosition).index;
116-
NSUInteger toIndex = ((InactiveTextPosition*)toPosition).index;
117-
return [InactiveTextRange rangeWithNSRange:NSMakeRange(fromIndex, toIndex - fromIndex)];
50+
NSUInteger fromIndex = ((FlutterTextPosition*)fromPosition).index;
51+
NSUInteger toIndex = ((FlutterTextPosition*)toPosition).index;
52+
return [FlutterTextRange rangeWithNSRange:NSMakeRange(fromIndex, toIndex - fromIndex)];
11853
}
11954

12055
- (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {

0 commit comments

Comments
 (0)