From f68fe7a9c9262a3591eeba61f34a91855a34c930 Mon Sep 17 00:00:00 2001
From: Jean Chalard <jchalard@google.com>
Date: Sat, 28 Jul 2012 00:49:43 +0900
Subject: [PATCH] Don't forward phantom space state on stripper input

Bug: 6890540
Change-Id: I923b24e3bc17e7b923be4940ad739b58dca24a1f
---
 .../src/com/android/inputmethod/latin/LatinIME.java |  7 ++++++-
 .../android/inputmethod/latin/InputLogicTests.java  | 13 +++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 95d75ebb79..30edd2052e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1651,13 +1651,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
             if (swapWeakSpace) {
                 swapSwapperAndSpace();
                 mSpaceState = SPACE_STATE_SWAP_PUNCTUATION;
-            } else if (SPACE_STATE_PHANTOM == spaceState) {
+            } else if (SPACE_STATE_PHANTOM == spaceState
+                    && !mCurrentSettings.isWeakSpaceStripper(primaryCode)) {
                 // If we are in phantom space state, and the user presses a separator, we want to
                 // stay in phantom space state so that the next keypress has a chance to add the
                 // space. For example, if I type "Good dat", pick "day" from the suggestion strip
                 // then insert a comma and go on to typing the next word, I want the space to be
                 // inserted automatically before the next word, the same way it is when I don't
                 // input the comma.
+                // The case is a little different if the separator is a space stripper. Such a
+                // separator does not normally need a space on the right (that's the difference
+                // between swappers and strippers), so we should not stay in phantom space state if
+                // the separator is a stripper. Hence the additional test above.
                 mSpaceState = SPACE_STATE_PHANTOM;
             }
 
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index 7790299b03..38e57aaedf 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -216,6 +216,19 @@ public class InputLogicTests extends InputTestsBase {
         assertEquals("manual pick then separator", EXPECTED_RESULT, mTextView.getText().toString());
     }
 
+    public void testManualPickThenStripperThenPick() {
+        final String WORD_TO_TYPE = "this";
+        final String STRIPPER = "\n";
+        final String EXPECTED_RESULT = "this\nthis";
+        type(WORD_TO_TYPE);
+        pickSuggestionManually(0, WORD_TO_TYPE);
+        type(STRIPPER);
+        type(WORD_TO_TYPE);
+        pickSuggestionManually(0, WORD_TO_TYPE);
+        assertEquals("manual pick then \\n then manual pick", EXPECTED_RESULT,
+                mTextView.getText().toString());
+    }
+
     public void testManualPickThenSpaceThenType() {
         final String WORD1_TO_TYPE = "this";
         final String WORD2_TO_TYPE = " is";
-- 
GitLab