[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.

<!-- Links -->
[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
This commit is contained in:
Camille Simon
2023-04-05 15:16:37 -07:00
committed by GitHub
parent 647ad5e49e
commit c109f78ae5
2 changed files with 36 additions and 1 deletions

View File

@@ -149,10 +149,20 @@ public class SpellCheckPlugin
spellCheckerSuggestionSpan.put(END_INDEX_KEY, end);
ArrayList<String> suggestions = new ArrayList<String>();
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);
}

View File

@@ -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<HashMap<String, Object>>());
}
}