From 2648035bda58b95dfe6c9c01da2c47027aac0f1d Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Fri, 21 May 2021 17:37:00 +0800 Subject: [PATCH] Fix a bug in sentence detection when input is too long. When the unchecked length of the current sentence is too long, the spell checker should check the first MAX_SENTENCE_LGNTH characters of the unchecked part. In this case, detectSentenceBOundary should return [textChangesStart, textChangeStart + MAX_SENTENCE_LENGTH) Fix: 188875278 Test: manual test Change-Id: I31847aed2d564f7bc1ff43c83adae3bb7c99c0d1 --- core/java/android/widget/SpellChecker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/SpellChecker.java b/core/java/android/widget/SpellChecker.java index 7c04b1cc195b0..2280d7cfd11c3 100644 --- a/core/java/android/widget/SpellChecker.java +++ b/core/java/android/widget/SpellChecker.java @@ -821,7 +821,7 @@ public class SpellChecker implements SpellCheckerSessionListener { // The offset should be rounded up to word boundary. int uncheckedLength = sentenceEnd - textChangeStart; if (uncheckedLength > MAX_SENTENCE_LENGTH) { - sentenceEnd = findSeparator(sequence, sentenceStart + MAX_SENTENCE_LENGTH, + sentenceEnd = findSeparator(sequence, textChangeStart + MAX_SENTENCE_LENGTH, sentenceEnd); sentenceStart = roundUpToWordStart(sequence, textChangeStart, sentenceStart); } else { @@ -829,7 +829,7 @@ public class SpellChecker implements SpellCheckerSessionListener { sentenceStart); } } - return new Range(sentenceStart, sentenceEnd); + return new Range<>(sentenceStart, Math.max(sentenceStart, sentenceEnd)); } private int roundUpToWordStart(CharSequence sequence, int position, int frontBoundary) {