From 330d2720bb3b0b6333ec2f61f056a4f46cbfa106 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 13 Dec 2013 22:13:25 +0900 Subject: [PATCH] Instead of ignoring PARAGRAPH spans, fix them. I don't know what or when this flag is set, but it's only bad news. Luckily, we can just remove it. Bug: 12119393 Change-Id: I2952138c8ce517535b91e0fe25d2cf4960e02862 --- .../inputmethod/latin/utils/SpannableStringUtils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java b/java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java index b51fd9377..be0955456 100644 --- a/java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java @@ -40,12 +40,17 @@ public final class SpannableStringUtils { * are out of range in dest. */ public static void copyNonParagraphSuggestionSpansFrom(Spanned source, int start, int end, - Spannable dest, int destoff) { + Spannable dest, int destoff) { Object[] spans = source.getSpans(start, end, SuggestionSpan.class); for (int i = 0; i < spans.length; i++) { int fl = source.getSpanFlags(spans[i]); - if (0 != (fl & Spannable.SPAN_PARAGRAPH)) continue; + // We don't care about the PARAGRAPH flag in LatinIME code. However, if this flag + // is set, Spannable#setSpan will throw an exception unless the span is on the edge + // of a word. But the spans have been split into two by the getText{Before,After}Cursor + // methods, so after concatenation they may end in the middle of a word. + // Since we don't use them, we can just remove them and avoid crashing. + fl &= ~Spannable.SPAN_PARAGRAPH; int st = source.getSpanStart(spans[i]); int en = source.getSpanEnd(spans[i]);