fixed a rare problem where Predictive mode would crash while determining the text case at the beginning of a text field
This commit is contained in:
parent
a88250d634
commit
0421578517
2 changed files with 36 additions and 14 deletions
|
|
@ -581,7 +581,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
||||||
mInputMode.determineNextWordTextCase(
|
mInputMode.determineNextWordTextCase(
|
||||||
settings,
|
settings,
|
||||||
InputFieldHelper.isThereText(currentInputConnection),
|
InputFieldHelper.isThereText(currentInputConnection),
|
||||||
(String) currentInputConnection.getTextBeforeCursor(50, 0)
|
InputFieldHelper.getTextBeforeCursor(currentInputConnection)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,21 +200,43 @@ public class InputFieldHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getTextBeforeCursor
|
||||||
|
* A simplified helper that return up to 50 characters before the cursor and "just works".
|
||||||
|
*/
|
||||||
|
public static String getTextBeforeCursor(InputConnection inputConnection) {
|
||||||
|
if (inputConnection == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
CharSequence before = inputConnection.getTextBeforeCursor(50, 0);
|
||||||
|
return before != null ? before.toString() : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getTextBeforeCursor
|
||||||
|
* A simplified helper that return up to 50 characters after the cursor and "just works".
|
||||||
|
*/
|
||||||
|
public static String getTextAfterCursor(InputConnection inputConnection) {
|
||||||
|
if (inputConnection == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
CharSequence before = inputConnection.getTextAfterCursor(50, 0);
|
||||||
|
return before != null ? before.toString() : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getSurroundingWord
|
||||||
|
* Returns the word next or around the cursor. Scanning length is up to 50 chars in each direction.
|
||||||
|
*/
|
||||||
public static String getSurroundingWord(InputConnection currentInputConnection) {
|
public static String getSurroundingWord(InputConnection currentInputConnection) {
|
||||||
if (currentInputConnection == null) {
|
Matcher before = beforeCursorWordRegex.matcher(getTextBeforeCursor(currentInputConnection));
|
||||||
return "";
|
Matcher after = afterCursorWordRegex.matcher(getTextAfterCursor(currentInputConnection));
|
||||||
}
|
|
||||||
|
|
||||||
CharSequence before = currentInputConnection.getTextBeforeCursor(50, 0);
|
return (before.find() ? before.group(1) : "") + (after.find() ? after.group(1) : "");
|
||||||
CharSequence after = currentInputConnection.getTextAfterCursor(50, 0);
|
|
||||||
if (before == null || after == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
Matcher beforeMatch = beforeCursorWordRegex.matcher(before);
|
|
||||||
Matcher afterMatch = afterCursorWordRegex.matcher(after);
|
|
||||||
|
|
||||||
return (beforeMatch.find() ? beforeMatch.group(1) : "") + (afterMatch.find() ? afterMatch.group(1) : "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue