aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/RichInputConnection.java
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-05-30 20:30:17 +0900
committerKeisuke Kuroyanagi <ksk@google.com>2014-05-30 20:30:17 +0900
commit8f71fab2ed619e34222a172a5004d7f91b4520a6 (patch)
treeef95ddbd77132cfae9d2ced327f28b159005458d /java/src/com/android/inputmethod/latin/RichInputConnection.java
parentfa0e76dde606c288e4df20b779995cbce3b187fb (diff)
downloadlatinime-8f71fab2ed619e34222a172a5004d7f91b4520a6.tar.gz
latinime-8f71fab2ed619e34222a172a5004d7f91b4520a6.tar.xz
latinime-8f71fab2ed619e34222a172a5004d7f91b4520a6.zip
Make prevWord = null if the next word starts from a connector.
This fixes PunctuationTests# testAutoCorrectionWithSingleQuotesAround. Bug: 14119293 Bug: 15334309 Change-Id: I604c21a21e89a5fc431fd56ab7b6ad03f4736b01
Diffstat (limited to 'java/src/com/android/inputmethod/latin/RichInputConnection.java')
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 46c015116..9d72c64fc 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -547,14 +547,17 @@ public final class RichInputConnection {
// Get information of the nth word before cursor. n = 1 retrieves the word immediately before
// the cursor, n = 2 retrieves the word before that, and so on. This splits on whitespace only.
// Also, it won't return words that end in a separator (if the nth word before the cursor
- // ends in a separator, it returns information represents beginning-of-sentence).
+ // ends in a separator, it returns information representing beginning-of-sentence).
// Example :
// (n = 1) "abc def|" -> def
// (n = 1) "abc def |" -> def
+ // (n = 1) "abc 'def|" -> 'def
// (n = 1) "abc def. |" -> beginning-of-sentence
// (n = 1) "abc def . |" -> beginning-of-sentence
// (n = 2) "abc def|" -> abc
// (n = 2) "abc def |" -> abc
+ // (n = 2) "abc 'def|" -> empty. The context is different from "abc def", but we cannot
+ // represent this situation using PrevWordsInfo. See TODO in the method.
// (n = 2) "abc def. |" -> abc
// (n = 2) "abc def . |" -> def
// (n = 2) "abc|" -> beginning-of-sentence
@@ -565,6 +568,19 @@ public final class RichInputConnection {
if (prev == null) return PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
final String[] w = spaceRegex.split(prev);
+ // Referring to the word after the nth word.
+ if ((n - 1) > 0 && (n - 1) <= w.length) {
+ final String wordFollowingTheNthPrevWord = w[w.length - n + 1];
+ if (!wordFollowingTheNthPrevWord.isEmpty()) {
+ final char firstChar = wordFollowingTheNthPrevWord.charAt(0);
+ if (spacingAndPunctuations.isWordConnector(firstChar)) {
+ // The word following the n-th prev word is starting with a word connector.
+ // TODO: Return meaningful context for this case.
+ return PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
+ }
+ }
+ }
+
// If we can't find n words, or we found an empty word, the context is
// beginning-of-sentence.
if (w.length < n) {