@@ -84,7 +84,7 @@ class LanguageToolController extends TextEditingController {
8484 _isEnabled = value;
8585
8686 if (_isEnabled) {
87- _handleTextChange (text, force : true );
87+ _handleTextChange (text, spellCheckSameText : true );
8888 } else {
8989 _mistakes = [];
9090 for (final recognizer in _recognizers) {
@@ -184,33 +184,38 @@ class LanguageToolController extends TextEditingController {
184184
185185 /// Clear mistakes list when text mas modified and get a new list of mistakes
186186 /// via API
187- Future <void > _handleTextChange (String newText, {bool force = false }) async {
187+ Future <void > _handleTextChange (
188+ String newText, {
189+ bool spellCheckSameText = false ,
190+ }) async {
188191 ///set value triggers each time, even when cursor changes its location
189192 ///so this check avoid cleaning Mistake list when text wasn't really changed
190- if (! force && (newText == text || newText.isEmpty)) return ;
193+ if (spellCheckSameText || newText != text && newText.isNotEmpty) {
194+ final filteredMistakes = _filterMistakesOnChanged (newText);
195+ _mistakes = filteredMistakes.toList ();
191196
192- final filteredMistakes = _filterMistakesOnChanged (newText);
193- _mistakes = filteredMistakes.toList ();
197+ // If we have a text change and we have a popup on hold
198+ // it will close the popup
199+ _closePopup ();
194200
195- // If we have a text change and we have a popup on hold
196- // it will close the popup
197- _closePopup ();
198-
199- for (final recognizer in _recognizers) {
200- recognizer.dispose ();
201- }
202- _recognizers.clear ();
201+ for (final recognizer in _recognizers) {
202+ recognizer.dispose ();
203+ }
204+ _recognizers.clear ();
203205
204- final mistakesWrapper = await _latestResponseService.processLatestOperation (
205- () => _languageCheckService? .findMistakes (newText) ?? Future (() => null ),
206- );
207- if (mistakesWrapper == null || ! mistakesWrapper.hasResult) return ;
206+ final mistakesWrapper =
207+ await _latestResponseService.processLatestOperation (
208+ () =>
209+ _languageCheckService? .findMistakes (newText) ?? Future (() => null ),
210+ );
211+ if (mistakesWrapper == null || ! mistakesWrapper.hasResult) return ;
208212
209- final mistakes = mistakesWrapper.result ();
210- _fetchError = mistakesWrapper.error;
213+ final mistakes = mistakesWrapper.result ();
214+ _fetchError = mistakesWrapper.error;
211215
212- _mistakes = mistakes;
213- notifyListeners ();
216+ _mistakes = mistakes;
217+ notifyListeners ();
218+ }
214219 }
215220
216221 /// Generator function to create TextSpan instances
0 commit comments