am b2212464: Merge "Ensure the selection does not change in setTextAndKeepSelection." into froyo
Merge commit 'b2212464a3bc4103a9e5e88602d1097c835d7949' into froyo-plus-aosp * commit 'b2212464a3bc4103a9e5e88602d1097c835d7949': Ensure the selection does not change in setTextAndKeepSelection.
This commit is contained in:
@@ -343,6 +343,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSelectionChanged(int selStart, int selEnd) {
|
protected void onSelectionChanged(int selStart, int selEnd) {
|
||||||
|
if (mInSetTextAndKeepSelection) return;
|
||||||
// This code is copied from TextView.onDraw(). That code does not get
|
// This code is copied from TextView.onDraw(). That code does not get
|
||||||
// executed, however, because the WebTextView does not draw, allowing
|
// executed, however, because the WebTextView does not draw, allowing
|
||||||
// webkit's drawing to show through.
|
// webkit's drawing to show through.
|
||||||
@@ -799,8 +800,14 @@ import java.util.ArrayList;
|
|||||||
/* package */ void setTextAndKeepSelection(String text) {
|
/* package */ void setTextAndKeepSelection(String text) {
|
||||||
mPreChange = text.toString();
|
mPreChange = text.toString();
|
||||||
Editable edit = (Editable) getText();
|
Editable edit = (Editable) getText();
|
||||||
|
int selStart = Selection.getSelectionStart(edit);
|
||||||
|
int selEnd = Selection.getSelectionEnd(edit);
|
||||||
mInSetTextAndKeepSelection = true;
|
mInSetTextAndKeepSelection = true;
|
||||||
edit.replace(0, edit.length(), text);
|
edit.replace(0, edit.length(), text);
|
||||||
|
int newLength = edit.length();
|
||||||
|
if (selStart > newLength) selStart = newLength;
|
||||||
|
if (selEnd > newLength) selEnd = newLength;
|
||||||
|
Selection.setSelection(edit, selStart, selEnd);
|
||||||
mInSetTextAndKeepSelection = false;
|
mInSetTextAndKeepSelection = false;
|
||||||
updateCachedTextfield();
|
updateCachedTextfield();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user