summaryrefslogtreecommitdiff
path: root/core/java/android/widget/TextView.java
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2011-01-07 10:16:21 -0800
committerGilles Debunne <debunne@google.com>2011-01-07 11:59:26 -0800
commit79ff914f2183a5f0a4121ef06112409e1c699ae7 (patch)
tree7c083a2871059eb8fc52e2223597a6ff976ea5b1 /core/java/android/widget/TextView.java
parent60525c824ccf11302a9b8343e72eba259485edea (diff)
Added support for Unicode surrogate characters in word selection
Inspired by https://review.source.android.com/#change,16606 Change-Id: I896354f5aba83c1919c008f07b6d0b2abf0b8e01
Diffstat (limited to 'core/java/android/widget/TextView.java')
-rw-r--r--core/java/android/widget/TextView.java37
1 files changed, 16 insertions, 21 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index f0512f6328eb..6a2a09aff19d 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -7645,9 +7645,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
hasPrimaryClip());
}
- private boolean isWordCharacter(int position) {
- final char c = mTransformed.charAt(position);
- final int type = Character.getType(c);
+ private boolean isWordCharacter(int c, int type) {
return (c == '\'' || c == '"' ||
type == Character.UPPERCASE_LETTER ||
type == Character.LOWERCASE_LETTER ||
@@ -7696,35 +7694,32 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
int start = end;
for (; start > 0; start--) {
- if (start == end) {
+ final char c = mTransformed.charAt(start - 1);
+ final int type = Character.getType(c);
+ if (start == end && type == Character.OTHER_PUNCTUATION) {
// Cases where the text ends with a '.' and we select from the end of the line
// (right after the dot), or when we select from the space character in "aaa, bbb".
- final char c = mTransformed.charAt(start - 1);
- final int type = Character.getType(c);
- if (type == Character.OTHER_PUNCTUATION) continue;
+ continue;
+ }
+ if (type == Character.SURROGATE) { // Two Character codepoint
+ end = start - 1; // Recheck as a pair when scanning forward
+ continue;
}
- if (!isWordCharacter(start - 1)) break;
+ if (!isWordCharacter(c, type)) break;
if ((end - start) > MAX_LENGTH) return -1;
}
for (; end < len; end++) {
- if (!isWordCharacter(end)) break;
+ final int c = Character.codePointAt(mTransformed, end);
+ final int type = Character.getType(c);
+ if (!isWordCharacter(c, type)) break;
if ((end - start) > MAX_LENGTH) return -1;
- }
-
- if (start == end) {
- return -1;
- }
-
- boolean hasLetter = false;
- for (int i = start; i < end; i++) {
- if (Character.isLetter(mTransformed.charAt(i))) {
- hasLetter = true;
- break;
+ if (c > 0xFFFF) { // Two Character codepoint
+ end++;
}
}
- if (!hasLetter) {
+ if (start == end) {
return -1;
}