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

Stop sending text to framework #33892

Merged
merged 1 commit into from
Jun 9, 2022
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 @@ -27,9 +27,8 @@
* <p>Once the spell check results are received by the {@link
* io.flutter.plugin.editing.SpellCheckPlugin}, it will send back to the framework the {@code
* ArrayList<String>} of encoded spell check results (see {@link
* io.flutter.plugin.editing.SpellCheckPlugin#onGetSentenceSuggestions} for details) with the text
* that these results correspond to appended to the front as an argument. For example, the argument
* may look like: {@code {"Hello, wrold!", "7.11.world\nword\nold"}}. The {@link
* io.flutter.plugin.editing.SpellCheckPlugin#onGetSentenceSuggestions} for details). For example,
* the argument may look like: {@code {"7.11.world\nword\nold"}}. The {@link
* io.flutter.plugin.editing.SpellCheckPlugin} only handles one request to fetch spell check results
* at a time; see {@link io.flutter.plugin.editing.SpellCheckPlugin#initiateSpellCheck} for details.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.localization.LocalizationPlugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;

/**
Expand All @@ -36,7 +35,6 @@ public class SpellCheckPlugin
private SpellCheckerSession mSpellCheckerSession;

@VisibleForTesting MethodChannel.Result pendingResult;
@VisibleForTesting String pendingResultText;

// The maximum number of suggestions that the Android spell check service is allowed to provide
// per word. Same number that is used by default for Android's TextViews.
Expand Down Expand Up @@ -80,7 +78,6 @@ public void initiateSpellCheck(
}

pendingResult = result;
pendingResultText = text;

performSpellCheck(locale, text);
}
Expand Down Expand Up @@ -115,7 +112,7 @@ public void performSpellCheck(@NonNull String locale, @NonNull String text) {
@Override
public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
if (results.length == 0) {
pendingResult.success(new ArrayList<>(Arrays.asList(pendingResultText, "")));
pendingResult.success(new ArrayList<String>());
pendingResult = null;
return;
}
Expand Down Expand Up @@ -146,7 +143,6 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
spellCheckerSuggestionSpan.substring(0, spellCheckerSuggestionSpan.length() - 1));
}

spellCheckerSuggestionSpans.add(0, pendingResultText);
pendingResult.success(spellCheckerSuggestionSpans);
pendingResult = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsProperly() {
spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
spellCheckPlugin.pendingResult = mockResult;
spellCheckPlugin.pendingResultText = "Hello, world!";

spellCheckPlugin.onGetSentenceSuggestions(new SentenceSuggestionsInfo[] {});

verify(mockResult).success(new ArrayList<String>(Arrays.asList("Hello, world!", "")));
verify(mockResult).success(new ArrayList<String>());
}

@Test
Expand All @@ -197,7 +196,6 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndResultsProperly() {
spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
spellCheckPlugin.pendingResult = mockResult;
spellCheckPlugin.pendingResultText = "Hello, wrold!";

spellCheckPlugin.onGetSentenceSuggestions(
new SentenceSuggestionsInfo[] {
Expand All @@ -211,7 +209,6 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndResultsProperly() {
new int[] {5})
});

verify(mockResult)
.success(new ArrayList<String>(Arrays.asList("Hello, wrold!", "7.11.world\nword\nold")));
verify(mockResult).success(new ArrayList<String>(Arrays.asList("7.11.world\nword\nold")));
}
}