Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | Properties | List of all members
FlutterSpellCheckPlugin Class Reference

#include <FlutterSpellCheckPlugin.h>

Inheritance diagram for FlutterSpellCheckPlugin:

Instance Methods

(void) - handleMethodCall:result:
 
(NSArray< NSDictionary< NSString *, id > * > *) - findAllSpellCheckSuggestionsForText:inLanguage: [implementation]
 
(FlutterSpellCheckResult *) - findSpellCheckSuggestionsForText:inLanguage:startingOffset: [implementation]
 
(UITextChecker *) - textChecker [implementation]
 

Properties

UITextChecker * textChecker [implementation]
 

Detailed Description

Definition at line 11 of file FlutterSpellCheckPlugin.h.

Method Documentation

◆ findAllSpellCheckSuggestionsForText:inLanguage:

- (NSArray< NSDictionary< NSString *, id > * > *) findAllSpellCheckSuggestionsForText: (NSString*)  text
inLanguage: (NSString*)  language 
implementation

Definition at line 32 of file FlutterSpellCheckPlugin.mm.

76 :(NSString*)text
77 inLanguage:(NSString*)language {
78 // Transform Dart Locale format to iOS language format if necessary.
79 if ([language containsString:@"-"]) {
80 NSArray<NSString*>* languageCodes = [language componentsSeparatedByString:@"-"];
81 FML_DCHECK(languageCodes.count == 2);
82 NSString* lastCode = [[languageCodes lastObject] uppercaseString];
83 language = [NSString stringWithFormat:@"%@_%@", [languageCodes firstObject], lastCode];
84 }
85
86 if (![UITextChecker.availableLanguages containsObject:language]) {
87 return nil;
88 }
89
90 NSMutableArray<FlutterSpellCheckResult*>* allSpellSuggestions = [[NSMutableArray alloc] init];
91
92 FlutterSpellCheckResult* nextSpellSuggestion;
93 NSUInteger nextOffset = 0;
94 do {
95 nextSpellSuggestion = [self findSpellCheckSuggestionsForText:text
96 inLanguage:language
97 startingOffset:nextOffset];
98 if (nextSpellSuggestion != nil) {
99 [allSpellSuggestions addObject:nextSpellSuggestion];
100 nextOffset =
101 nextSpellSuggestion.misspelledRange.location + nextSpellSuggestion.misspelledRange.length;
102 }
103 } while (nextSpellSuggestion != nil && nextOffset < text.length);
104
105 NSMutableArray* methodChannelResult =
106 [[NSMutableArray alloc] initWithCapacity:allSpellSuggestions.count];
107
108 for (FlutterSpellCheckResult* result in allSpellSuggestions) {
109 [methodChannelResult addObject:[result toDictionary]];
110 }
111
112 return methodChannelResult;
113}
if(end==-1)
GAsyncResult * result
#define FML_DCHECK(condition)
Definition logging.h:103
size_t length
std::u16string text

◆ findSpellCheckSuggestionsForText:inLanguage:startingOffset:

- (FlutterSpellCheckResult *) findSpellCheckSuggestionsForText: (NSString*)  text
inLanguage: (NSString*)  language
startingOffset: (NSInteger)  startingOffset 
implementation

Definition at line 32 of file FlutterSpellCheckPlugin.mm.

118 :(NSString*)text
119 inLanguage:(NSString*)language
120 startingOffset:(NSInteger)startingOffset {
121 FML_DCHECK([UITextChecker.availableLanguages containsObject:language]);
122 NSRange misspelledRange =
123 [self.textChecker rangeOfMisspelledWordInString:text
124 range:NSMakeRange(0, text.length)
125 startingAt:startingOffset
126 wrap:NO
127 language:language];
128 if (misspelledRange.location == NSNotFound) {
129 // No misspelled word found
130 return nil;
131 }
132
133 // If no possible guesses, the API returns an empty array:
134 // https://developer.apple.com/documentation/uikit/uitextchecker/1621037-guessesforwordrange?language=objc
135 NSArray<NSString*>* suggestions = [self.textChecker guessesForWordRange:misspelledRange
136 inString:text
137 language:language];
138 return [[FlutterSpellCheckResult alloc] initWithMisspelledRange:misspelledRange
139 suggestions:suggestions];
140}

◆ handleMethodCall:result:

- (void) handleMethodCall: (FlutterMethodCall*)  call
result: (FlutterResult result 

Definition at line 32 of file FlutterSpellCheckPlugin.mm.

40 // UITextChecker is an expensive object to initiate, see:
41 // https://github.com/flutter/flutter/issues/104454. Lazily initialate the UITextChecker object
42 // until at first method channel call. We avoid using lazy getter for testing.
43 self.textChecker = [[UITextChecker alloc] init];
44 }
45 NSString* method = call.method;
46 NSArray* args = call.arguments;
47 if ([method isEqualToString:kInitiateSpellCheck]) {
48 FML_DCHECK(args.count == 2);
49 id language = args[0];
50 id text = args[1];
51 if (language == [NSNull null] || text == [NSNull null]) {
52 // Bail if null arguments are passed from dart.
53 result(nil);
54 return;
55 }
56
57 NSArray<NSDictionary<NSString*, id>*>* spellCheckResult =
58 [self findAllSpellCheckSuggestionsForText:text inLanguage:language];
59 result(spellCheckResult);
60 }
61}
void(^ FlutterResult)(id _Nullable result)
static FLUTTER_ASSERT_ARC NSString *const kInitiateSpellCheck
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
call(args)
Definition dom.py:159

◆ textChecker

- (UITextChecker *) textChecker
implementation

Provided by category FlutterSpellCheckPlugin().

Property Documentation

◆ textChecker

- (UITextChecker*) textChecker
readwritenonatomicassignimplementation

Provided by category FlutterSpellCheckPlugin().

Definition at line 32 of file FlutterSpellCheckPlugin.mm.


The documentation for this class was generated from the following files: