Bug 810821 - Only change focus if awesomebar text field responded to key press; r=cpeterson

This commit is contained in:
Jim Chen 2012-12-14 13:21:58 -05:00
parent 64955d76e9
commit 8e3ba6c3fa

View File

@ -413,28 +413,20 @@ public class AwesomeBar extends GeckoActivity {
imm.showSoftInput(mText, InputMethodManager.SHOW_IMPLICIT);
return true;
} else {
int selStart = -1;
int selEnd = -1;
if (mText.hasSelection()) {
selStart = mText.getSelectionStart();
selEnd = mText.getSelectionEnd();
}
int prevSelStart = mText.getSelectionStart();
int prevSelEnd = mText.getSelectionEnd();
if (selStart >= 0) {
// Restore the selection, which gets lost due to the focus switch
mText.setSelection(selStart, selEnd);
}
// Manually dispatch the key event to the AwesomeBar before restoring (default) input
// focus. dispatchKeyEvent() will update AwesomeBar's cursor position.
// Manually dispatch the key event to the AwesomeBar. If selection changed as
// a result of the key event, then give focus back to mText
mText.dispatchKeyEvent(event);
int newCursorPos = mText.getSelectionEnd();
// requestFocusFromTouch() will select all AwesomeBar text, so we must restore cursor
// position so subsequent typing does not overwrite all text.
mText.requestFocusFromTouch();
mText.setSelection(newCursorPos);
int curSelStart = mText.getSelectionStart();
int curSelEnd = mText.getSelectionEnd();
if (prevSelStart != curSelStart || prevSelEnd != curSelEnd) {
mText.requestFocusFromTouch();
// Restore the selection, which gets lost due to the focus switch
mText.setSelection(curSelStart, curSelEnd);
}
return true;
}
}