Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Android] Make temporary fix for Samsung spell checker giving blank results for all words #40924

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,20 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
// 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>>());
}
}