diff options
| author | Kohsuke Yatoh <kyatoh@google.com> | 2020-12-03 00:10:19 +0000 |
|---|---|---|
| committer | Kohsuke Yatoh <kyatoh@google.com> | 2020-12-15 22:48:47 +0000 |
| commit | e751e1036a0467e3aa2c8ecd23266b65eccea4d7 (patch) | |
| tree | b9e7231f7202f97ae08bfe8632fa40131da99433 /core/java/android/widget/SpellChecker.java | |
| parent | 0f04a2e670d1d27176bcd3e18e29cebea2dbf868 (diff) | |
Add InputConnection#performSpellCheck().
IME can use this method to redo spell checking after it has learned a
new user dictionary word.
Bug: 166304720
Test: atest CtsInputMethodTestCases:SpellCheckerTest
Change-Id: I956cd46f25bb77b7e1a6a3e1478c0d7efa1a056a
Diffstat (limited to 'core/java/android/widget/SpellChecker.java')
| -rw-r--r-- | core/java/android/widget/SpellChecker.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/java/android/widget/SpellChecker.java b/core/java/android/widget/SpellChecker.java index 0611bea7978d..0788635d1c68 100644 --- a/core/java/android/widget/SpellChecker.java +++ b/core/java/android/widget/SpellChecker.java @@ -215,6 +215,27 @@ public class SpellChecker implements SpellCheckerSessionListener { spellCheck(); } + void onPerformSpellCheck() { + final int selectionStart = mTextView.getSelectionStart(); + final int selectionEnd = mTextView.getSelectionEnd(); + final int selectionRangeStart; + final int selectionRangeEnd; + if (selectionStart < selectionEnd) { + selectionRangeStart = selectionStart; + selectionRangeEnd = selectionEnd; + } else { + selectionRangeStart = selectionEnd; + selectionRangeEnd = selectionStart; + } + // Expand the range so that it (hopefully) includes the current sentence. + final int start = Math.max(0, selectionRangeStart - MIN_SENTENCE_LENGTH); + final int end = Math.min(mTextView.length(), selectionRangeEnd + MIN_SENTENCE_LENGTH); + if (DBG) { + Log.d(TAG, "performSpellCheckAroundSelection: " + start + ", " + end); + } + spellCheck(start, end); + } + public void spellCheck(int start, int end) { if (DBG) { Log.d(TAG, "Start spell-checking: " + start + ", " + end); |
