From b1fef1114e31e35c90bc885fd9e8f9381895846f Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 25 Sep 2014 12:50:16 -0700 Subject: [PATCH] Defer spelling correction with apostrophe When typing a contraction (such as "doesn't") we don't want a spell right after the apostrophe, as this will create a false temporary red underline, and the span split also breaks a kern pair causing text to shift. This patch detects the case where the cursor is immediately after such a word and suppresses correction in that case. Bug: 17641350 Change-Id: I4d09576a31df551c96f820242fd2cbc675506dae --- core/java/android/widget/SpellChecker.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/SpellChecker.java b/core/java/android/widget/SpellChecker.java index f64177d4388cf..3592687d1f102 100644 --- a/core/java/android/widget/SpellChecker.java +++ b/core/java/android/widget/SpellChecker.java @@ -276,13 +276,19 @@ public class SpellChecker implements SpellCheckerSessionListener { // Do not check this word if the user is currently editing it final boolean isEditing; + + // Defer spell check when typing a word with an interior apostrophe. + // TODO: a better solution to this would be to make the word + // iterator locale-sensitive and include the apostrophe in + // languages that use it (such as English). + final boolean apostrophe = (selectionStart == end + 1 && editable.charAt(end) == '\''); if (mIsSentenceSpellCheckSupported) { // Allow the overlap of the cursor and the first boundary of the spell check span // no to skip the spell check of the following word because the // following word will never be spell-checked even if the user finishes composing - isEditing = selectionEnd <= start || selectionStart > end; + isEditing = !apostrophe && (selectionEnd <= start || selectionStart > end); } else { - isEditing = selectionEnd < start || selectionStart > end; + isEditing = !apostrophe && (selectionEnd < start || selectionStart > end); } if (start >= 0 && end > start && isEditing) { spellCheckSpan.setSpellCheckInProgress(true);