From c109f78ae5118cafad1480a59a77ded8b97ffa80 Mon Sep 17 00:00:00 2001 From: Camille Simon <43054281+camsim99@users.noreply.github.com> Date: Wed, 5 Apr 2023 15:16:37 -0700 Subject: [PATCH] [Android] Make temporary fix for Samsung spell checker giving blank results for all words (flutter/engine#40924) Temporarily filters out invalid spell check results (""/ " ") received from the Samsung spell checker, since this is the result that may be returned by all words (correctly spelled and misspelled) from observation. Temporary fix for [#120608](https://github.com/flutter/flutter/issues/120608). ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [ ] All existing and new tests are passing. [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat --- .../plugin/editing/SpellCheckPlugin.java | 12 ++++++++- .../plugin/editing/SpellCheckPluginTest.java | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java index f74076c7af..5688e4fd59 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java @@ -149,10 +149,20 @@ public class SpellCheckPlugin 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.equals("")) { + validSuggestionsFound = true; + suggestions.add(suggestion); + } } + if (!validSuggestionsFound) { + continue; + } spellCheckerSuggestionSpan.put(SUGGESTIONS_KEY, suggestions); spellCheckerSuggestionSpans.add(spellCheckerSuggestionSpan); } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java index 559ebcbae2..97a28a0ca2 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java @@ -222,4 +222,29 @@ public class SpellCheckPluginTest { 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, + // This is the suggestion that may be provided by the Samsung spell checker: + new String[] {""}) + }), + new int[] {7}, + new int[] {5}) + }); + + verify(mockResult).success(new ArrayList>()); + } }