5#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSpellCheckPlugin.h"
7#import <Foundation/Foundation.h>
10#import "flutter/fml/logging.h"
24- (instancetype)initWithMisspelledRange:(NSRange)range
25 suggestions:(NSArray<NSString*>*)suggestions NS_DESIGNATED_INITIALIZER;
39 if (!
self.textChecker) {
43 self.textChecker = [[UITextChecker alloc] init];
45 NSString* method =
call.method;
49 id language =
args[0];
51 if (language == [NSNull null] ||
text == [NSNull null]) {
57 NSArray<NSDictionary<NSString*, id>*>* spellCheckResult =
76- (NSArray<NSDictionary<NSString*,
id>*>*)findAllSpellCheckSuggestionsForText:(NSString*)text
77 inLanguage:(NSString*)language {
79 if ([language containsString:
@"-"]) {
80 NSArray<NSString*>* languageCodes = [language componentsSeparatedByString:@"-"];
82 NSString* lastCode = [[languageCodes lastObject] uppercaseString];
83 language = [NSString stringWithFormat:@"%@_%@", [languageCodes firstObject], lastCode];
86 if (![UITextChecker.availableLanguages containsObject:language]) {
90 NSMutableArray<FlutterSpellCheckResult*>* allSpellSuggestions = [[NSMutableArray alloc] init];
93 NSUInteger nextOffset = 0;
95 nextSpellSuggestion = [
self findSpellCheckSuggestionsForText:text
97 startingOffset:nextOffset];
98 if (nextSpellSuggestion != nil) {
99 [allSpellSuggestions addObject:nextSpellSuggestion];
103 }
while (nextSpellSuggestion != nil && nextOffset <
text.length);
105 NSMutableArray* methodChannelResult =
106 [[NSMutableArray alloc] initWithCapacity:allSpellSuggestions.count];
109 [methodChannelResult addObject:[result toDictionary]];
112 return methodChannelResult;
119 inLanguage:(NSString*)language
120 startingOffset:(NSInteger)startingOffset {
121 FML_DCHECK([UITextChecker.availableLanguages containsObject:language]);
123 [
self.textChecker rangeOfMisspelledWordInString:text
124 range:NSMakeRange(0, text.length)
125 startingAt:startingOffset
135 NSArray<NSString*>*
suggestions = [
self.textChecker guessesForWordRange:misspelledRange
139 suggestions:suggestions];
146- (instancetype)initWithMisspelledRange:(NSRange)range
147 suggestions:(NSArray<NSString*>*)suggestions {
150 _suggestions = [suggestions copy];
151 _misspelledRange = range;
158 @"startIndex" : @(_misspelledRange.location),
162 @"endIndex" : @(_misspelledRange.location + _misspelledRange.length),
163 @"suggestions" : _suggestions,
void(^ FlutterResult)(id _Nullable result)
static FLUTTER_ASSERT_ARC NSString *const kInitiateSpellCheck
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define FML_DCHECK(condition)
UITextChecker * textChecker
NSArray< NSDictionary< NSString *, id > * > * findAllSpellCheckSuggestionsForText:inLanguage:(NSString *text, [inLanguage] NSString *language)
NSArray< NSString * > * suggestions
instancetype NS_UNAVAILABLE()
NSDictionary< NSString *, NSObject * > * toDictionary()