From 8a1279e2995d6abf0e3c6596f81925266223aa66 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 4 Apr 2023 13:44:25 -0700 Subject: [PATCH 1/2] Make fix --- .../plugin/editing/SpellCheckPlugin.java | 12 ++++++++- .../plugin/editing/SpellCheckPluginTest.java | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java b/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java index f74076c7af45b..cf4cf3bf2f93c 100644 --- a/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java @@ -149,10 +149,20 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) { spellCheckerSuggestionSpan.put(END_INDEX_KEY, end); ArrayList suggestions = new ArrayList(); + boolean validSuggestionsFound = false; for (int j = 0; j < suggestionsCount; j++) { - suggestions.add(suggestionsInfo.getSuggestionAt(j)); + String suggestion = suggestionsInfo.getSuggestionAt(j); + // TODO(camsim99): Support spell check on Samsung by retrieving accurate spell check + // results, then remove this check: https://github.com/flutter/flutter/issues/120608. + if (suggestion != "" && suggestion != " ") { + validSuggestionsFound = true; + suggestions.add(suggestion); + } } + if (!validSuggestionsFound) { + continue; + } spellCheckerSuggestionSpan.put(SUGGESTIONS_KEY, suggestions); spellCheckerSuggestionSpans.add(spellCheckerSuggestionSpan); } diff --git a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java index 559ebcbae2a7a..bba47da426998 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java @@ -222,4 +222,29 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndResultsProperly() { verify(mockResult).success(expectedResults); } + + @Test + public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid() { + TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class); + SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class); + SpellCheckPlugin spellCheckPlugin = + spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel)); + MethodChannel.Result mockResult = mock(MethodChannel.Result.class); + spellCheckPlugin.pendingResult = mockResult; + + spellCheckPlugin.onGetSentenceSuggestions( + new SentenceSuggestionsInfo[] { + new SentenceSuggestionsInfo( + (new SuggestionsInfo[] { + new SuggestionsInfo( + SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO, + // These are the suggestions that may be provided by the Samsung spell checker: + new String[] {"", " "}) + }), + new int[] {7}, + new int[] {5}) + }); + + verify(mockResult).success(new ArrayList>()); + } } From 244005cf54bd55aee71cb0fecf0f4155e536f559 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 4 Apr 2023 16:48:11 -0700 Subject: [PATCH 2/2] Make small fix --- .../android/io/flutter/plugin/editing/SpellCheckPlugin.java | 2 +- .../test/io/flutter/plugin/editing/SpellCheckPluginTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java b/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java index cf4cf3bf2f93c..5688e4fd597ae 100644 --- a/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java @@ -154,7 +154,7 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) { String suggestion = suggestionsInfo.getSuggestionAt(j); // TODO(camsim99): Support spell check on Samsung by retrieving accurate spell check // results, then remove this check: https://github.com/flutter/flutter/issues/120608. - if (suggestion != "" && suggestion != " ") { + if (!suggestion.equals("")) { validSuggestionsFound = true; suggestions.add(suggestion); } diff --git a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java index bba47da426998..97a28a0ca22d7 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java @@ -238,8 +238,8 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestion (new SuggestionsInfo[] { new SuggestionsInfo( SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO, - // These are the suggestions that may be provided by the Samsung spell checker: - new String[] {"", " "}) + // This is the suggestion that may be provided by the Samsung spell checker: + new String[] {""}) }), new int[] {7}, new int[] {5})