am 35605db9
: Merge "Revert "[SD6] Inline a constant and remove logic become useless""
* commit '35605db9a4c2561c554f3fe3c5304ad544ad385a': Revert "[SD6] Inline a constant and remove logic become useless"
This commit is contained in:
commit
ce612a0689
1 changed files with 21 additions and 8 deletions
|
@ -626,6 +626,7 @@ public final class RichInputConnection {
|
||||||
* @return a range containing the text surrounding the cursor
|
* @return a range containing the text surrounding the cursor
|
||||||
*/
|
*/
|
||||||
public TextRange getWordRangeAtCursor(final int[] sortedSeparators) {
|
public TextRange getWordRangeAtCursor(final int[] sortedSeparators) {
|
||||||
|
final int additionalPrecedingWordsCount = 0;
|
||||||
mIC = mParent.getCurrentInputConnection();
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (mIC == null) {
|
if (mIC == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -638,17 +639,29 @@ public final class RichInputConnection {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Going backward, find the first breaking point (separator)
|
// Going backward, alternate skipping non-separators and separators until enough words
|
||||||
|
// have been read.
|
||||||
|
int count = additionalPrecedingWordsCount;
|
||||||
int startIndexInBefore = before.length();
|
int startIndexInBefore = before.length();
|
||||||
while (startIndexInBefore > 0) {
|
boolean isStoppingAtWhitespace = true; // toggles to indicate what to stop at
|
||||||
final int codePoint = Character.codePointBefore(before, startIndexInBefore);
|
while (true) { // see comments below for why this is guaranteed to halt
|
||||||
if (isSeparator(codePoint, sortedSeparators)) {
|
while (startIndexInBefore > 0) {
|
||||||
break;
|
final int codePoint = Character.codePointBefore(before, startIndexInBefore);
|
||||||
}
|
if (isStoppingAtWhitespace == isSeparator(codePoint, sortedSeparators)) {
|
||||||
--startIndexInBefore;
|
break; // inner loop
|
||||||
if (Character.isSupplementaryCodePoint(codePoint)) {
|
}
|
||||||
--startIndexInBefore;
|
--startIndexInBefore;
|
||||||
|
if (Character.isSupplementaryCodePoint(codePoint)) {
|
||||||
|
--startIndexInBefore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// isStoppingAtWhitespace is true every other time through the loop,
|
||||||
|
// so additionalPrecedingWordsCount is guaranteed to become < 0, which
|
||||||
|
// guarantees outer loop termination
|
||||||
|
if (isStoppingAtWhitespace && (--count < 0)) {
|
||||||
|
break; // outer loop
|
||||||
|
}
|
||||||
|
isStoppingAtWhitespace = !isStoppingAtWhitespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find last word separator after the cursor
|
// Find last word separator after the cursor
|
||||||
|
|
Loading…
Reference in a new issue