Stop sending text to framework (flutter/engine#33892)

This commit is contained in:
Camille Simon
2022-06-08 17:13:01 -07:00
committed by GitHub
parent 45633ced2a
commit af20f79b0e
3 changed files with 5 additions and 13 deletions

View File

@@ -27,9 +27,8 @@ import org.json.JSONException;
* <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.
*

View File

@@ -15,7 +15,6 @@ import io.flutter.embedding.engine.systemchannels.SpellCheckChannel;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.localization.LocalizationPlugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
/**
@@ -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.
@@ -80,7 +78,6 @@ public class SpellCheckPlugin
}
pendingResult = result;
pendingResultText = text;
performSpellCheck(locale, text);
}
@@ -115,7 +112,7 @@ public class SpellCheckPlugin
@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;
}
@@ -146,7 +143,6 @@ public class SpellCheckPlugin
spellCheckerSuggestionSpan.substring(0, spellCheckerSuggestionSpan.length() - 1));
}
spellCheckerSuggestionSpans.add(0, pendingResultText);
pendingResult.success(spellCheckerSuggestionSpans);
pendingResult = null;
}

View File

@@ -182,11 +182,10 @@ public class SpellCheckPluginTest {
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
@@ -197,7 +196,6 @@ public class SpellCheckPluginTest {
spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
spellCheckPlugin.pendingResult = mockResult;
spellCheckPlugin.pendingResultText = "Hello, wrold!";
spellCheckPlugin.onGetSentenceSuggestions(
new SentenceSuggestionsInfo[] {
@@ -211,7 +209,6 @@ public class SpellCheckPluginTest {
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")));
}
}