Skip to content

Commit 01ce693

Browse files
[Spellcheck][Android] - Fix empty paragraph platform error, and concurrent spell check platform error (Resolves #2640) (#2641)
1 parent ad81ebb commit 01ce693

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

super_editor_spellcheck/example/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818

1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21-
id "com.android.application" version "8.1.0" apply false
21+
id "com.android.application" version "8.2.1" apply false
2222
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
2323
}
2424

super_editor_spellcheck/example/pubspec.lock

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: attributed_text
40-
sha256: d16c10850371421a778474ac24c24b4ab8708e3e53f3796f8d9ea2a41a25a59a
40+
sha256: "9d8bdc6e54387f31e52d2dcc3d93d656072582a44bcaa855c9ea8b3b2fa7abd3"
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "0.4.2"
43+
version: "0.4.4"
4444
boolean_selector:
4545
dependency: transitive
4646
description:
@@ -147,6 +147,14 @@ packages:
147147
url: "https://pub.dev"
148148
source: hosted
149149
version: "3.0.2"
150+
flutter_plugin_android_lifecycle:
151+
dependency: transitive
152+
description:
153+
name: flutter_plugin_android_lifecycle
154+
sha256: "5a1e6fb2c0561958d7e4c33574674bda7b77caaca7a33b758876956f2902eea3"
155+
url: "https://pub.dev"
156+
source: hosted
157+
version: "2.0.27"
150158
flutter_test:
151159
dependency: "direct dev"
152160
description: flutter
@@ -498,7 +506,7 @@ packages:
498506
path: "../../super_editor"
499507
relative: true
500508
source: path
501-
version: "0.3.0-dev.15"
509+
version: "0.3.0-dev.23"
502510
super_editor_spellcheck:
503511
dependency: "direct main"
504512
description:
@@ -510,10 +518,10 @@ packages:
510518
dependency: transitive
511519
description:
512520
name: super_keyboard
513-
sha256: c8e303cd7bc1fc62732213f0f2660273a078be23eae7a4219d0ab3dd0b0ccb9a
521+
sha256: "06662d12c88f0d0f0979d1a27729007a9b5e389e3b9a8adf2531e4c562df2540"
514522
url: "https://pub.dev"
515523
source: hosted
516-
version: "0.1.0"
524+
version: "0.1.1"
517525
super_text_layout:
518526
dependency: transitive
519527
description:
@@ -707,5 +715,5 @@ packages:
707715
source: hosted
708716
version: "3.1.2"
709717
sdks:
710-
dart: ">=3.5.0 <4.0.0"
711-
flutter: ">=3.19.0"
718+
dart: ">=3.6.0 <4.0.0"
719+
flutter: ">=3.27.0"

super_editor_spellcheck/lib/src/super_editor/spelling_and_grammar_plugin.dart

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,36 @@ class SpellingAndGrammarReaction implements EditReaction {
400400
final textErrors = <TextError>{};
401401
final spellingSuggestions = <TextRange, SpellingError>{};
402402

403+
final plainText = _filterIgnoredRanges(textNode);
404+
if (plainText.isEmpty) {
405+
// On Android it appears that running spell check on an empty string breaks
406+
// spell check for the remainder of the app session, so don't even try.
407+
// https://github.com/superlistapp/super_editor/issues/2640
408+
return;
409+
}
410+
403411
// Track this spelling and grammar request to make sure we don't process
404412
// the response out of order with other requests.
405413
_asyncRequestIds[textNode.id] ??= 0;
406414
final requestId = _asyncRequestIds[textNode.id]! + 1;
407415
_asyncRequestIds[textNode.id] = requestId;
408416

409-
final plainText = _filterIgnoredRanges(textNode);
410-
411417
if (isSpellCheckEnabled) {
412-
final suggestions = await _spellCheckService.fetchSpellCheckSuggestions(
413-
PlatformDispatcher.instance.locale,
414-
plainText,
415-
);
418+
// Android can't execute concurrent spell checks and returns `null` when we try to run a 2nd+ spell check
419+
// at the same time. We'll retry our spell check up to this number of times before giving up.
420+
// https://github.com/superlistapp/super_editor/issues/2640
421+
const maxTryCount = 5;
422+
423+
List<SuggestionSpan>? suggestions;
424+
int tryCount = 0;
425+
do {
426+
suggestions = await _spellCheckService.fetchSpellCheckSuggestions(
427+
PlatformDispatcher.instance.locale,
428+
plainText,
429+
);
430+
tryCount += 1;
431+
} while (suggestions == null && tryCount < maxTryCount);
432+
416433
if (suggestions != null) {
417434
for (final suggestion in suggestions) {
418435
final misspelledWord = plainText.substring(suggestion.range.start, suggestion.range.end);

0 commit comments

Comments
 (0)