aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-10-04 15:33:41 +0900
committerJean Chalard <jchalard@google.com>2012-10-04 20:54:28 +0900
commit2699b45dbc22b56d57690fcc8b4592e0371b8710 (patch)
tree72c2dee5efe98d6621ce2726344121e5d89ed6ed
parent01d9b1f17a2c4aeb281e05a1390447a76cb3d013 (diff)
downloadlatinime-2699b45dbc22b56d57690fcc8b4592e0371b8710.tar.gz
latinime-2699b45dbc22b56d57690fcc8b4592e0371b8710.tar.xz
latinime-2699b45dbc22b56d57690fcc8b4592e0371b8710.zip
Always consider a new line the start of a sentence
Bug: 7282523 Change-Id: I10a73e99efdfe6acb9a16819694b98c6714fd451
-rw-r--r--java/src/com/android/inputmethod/latin/StringUtils.java14
-rw-r--r--tests/src/com/android/inputmethod/latin/StringUtilsTests.java8
2 files changed, 17 insertions, 5 deletions
diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java
index 7b65b7343..df7709892 100644
--- a/java/src/com/android/inputmethod/latin/StringUtils.java
+++ b/java/src/com/android/inputmethod/latin/StringUtils.java
@@ -250,15 +250,19 @@ public final class StringUtils {
// Step 3 : Search for the start of a paragraph. From the starting point computed in step 2,
// we go back over any space or tab char sitting there. We find the start of a paragraph
- // if the first char that's not a space or tab is a start of line (as in, either \n or
- // start of text).
+ // if the first char that's not a space or tab is a start of line (as in \n, start of text,
+ // or some other similar characters).
int j = i;
+ char prevChar = Keyboard.CODE_SPACE;
if (hasSpaceBefore) --j;
- while (j > 0 && Character.isWhitespace(cs.charAt(j - 1))) {
+ while (j > 0) {
+ prevChar = cs.charAt(j - 1);
+ if (!Character.isSpaceChar(prevChar) && prevChar != Keyboard.CODE_TAB) break;
j--;
}
- if (j == 0) {
- // There is only whitespace between the start of the text and the cursor. Both
+ if (j <= 0 || Character.isWhitespace(prevChar)) {
+ // There are only spacing chars between the start of the paragraph and the cursor,
+ // defined as a isWhitespace() char that is neither a isSpaceChar() nor a tab. Both
// MODE_WORDS and MODE_SENTENCES should be active.
return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS
| TextUtils.CAP_MODE_SENTENCES) & reqModes;
diff --git a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
index be3494dc7..3142bd602 100644
--- a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
@@ -140,6 +140,14 @@ public class StringUtilsTests extends AndroidTestCase {
allPathsForCaps("Word", c | w, l, true);
allPathsForCaps("Word.", c | w | s, l, true);
+ // Tests after some whitespace
+ allPathsForCaps("Word\n", c | w | s, l, false);
+ allPathsForCaps("Word\n", c | w | s, l, true);
+ allPathsForCaps("Word\n ", c | w | s, l, true);
+ allPathsForCaps("Word.\n", c | w | s, l, false);
+ allPathsForCaps("Word.\n", c | w | s, l, true);
+ allPathsForCaps("Word.\n ", c | w | s, l, true);
+
l = Locale.FRENCH;
allPathsForCaps("\"Word.\" ", c | w, l, false);
allPathsForCaps("\"Word\". ", c | w | s, l, false);