Bug 1131685, don't have the selection in the list interfere with caret movement in the search field, r=mak

This commit is contained in:
Neil Deakin 2015-02-26 09:14:19 -05:00
parent ff4e1de0a1
commit 655e83681c
2 changed files with 40 additions and 7 deletions

View File

@ -452,6 +452,28 @@ add_task(function* dont_rollup_oncaretmove() {
is(textbox.selectionEnd, 9, "Should have moved the caret (selectionEnd after right)");
is(searchPopup.state, "open", "Popup should still be open");
// Ensure caret movement works while a suggestion is selected.
is(textbox.popup.selectedIndex, -1, "No selected item in list");
EventUtils.synthesizeKey("VK_DOWN", {});
is(textbox.popup.selectedIndex, 0, "Selected item in list");
is(textbox.selectionStart, 9, "Should have moved the caret to the end (selectionStart after selection)");
is(textbox.selectionEnd, 9, "Should have moved the caret to the end (selectionEnd after selection)");
EventUtils.synthesizeKey("VK_LEFT", {});
is(textbox.selectionStart, 8, "Should have moved the caret again (selectionStart after left)");
is(textbox.selectionEnd, 8, "Should have moved the caret again (selectionEnd after left)");
is(searchPopup.state, "open", "Popup should still be open");
EventUtils.synthesizeKey("VK_LEFT", {});
is(textbox.selectionStart, 7, "Should have moved the caret (selectionStart after left)");
is(textbox.selectionEnd, 7, "Should have moved the caret (selectionEnd after left)");
is(searchPopup.state, "open", "Popup should still be open");
EventUtils.synthesizeKey("VK_RIGHT", {});
is(textbox.selectionStart, 8, "Should have moved the caret (selectionStart after right)");
is(textbox.selectionEnd, 8, "Should have moved the caret (selectionEnd after right)");
is(searchPopup.state, "open", "Popup should still be open");
if (navigator.platform.indexOf("Mac") == -1) {
EventUtils.synthesizeKey("VK_HOME", {});
is(textbox.selectionStart, 0, "Should have moved the caret (selectionStart after home)");

View File

@ -491,6 +491,21 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool *_retval)
uint32_t minResultsForPopup;
input->GetMinResultsForPopup(&minResultsForPopup);
if (isOpen || (mRowCount > 0 && mRowCount < minResultsForPopup)) {
// For completeSelectedIndex autocomplete fields, if the popup shouldn't
// close when the caret is moved, don't adjust the text value or caret
// position.
if (isOpen) {
bool noRollup;
input->GetNoRollupOnCaretMove(&noRollup);
if (noRollup) {
bool completeSelection;
input->GetCompleteSelectedIndex(&completeSelection);
if (completeSelection) {
return NS_OK;
}
}
}
int32_t selectedIndex;
popup->GetSelectedIndex(&selectedIndex);
bool shouldComplete;
@ -530,13 +545,9 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool *_retval)
}
}
bool noRollup;
input->GetNoRollupOnCaretMove(&noRollup);
if (!noRollup) {
// Close the pop-up even if nothing was selected
ClearSearchTimer();
ClosePopup();
}
// Close the pop-up even if nothing was selected
ClearSearchTimer();
ClosePopup();
}
// Update last-searched string to the current input, since the input may
// have changed. Without this, subsequent backspaces look like text