Commit 2b5dbdac authored by Dan Beam's avatar Dan Beam Committed by Commit Bot

Local NTP: preserve focus when removing suggestions

R=hcarmona@chromium.org

Fixed: 1012997
Change-Id: I6b5c1cf5b740777b521034920fd56455f85e4293
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1851285
Auto-Submit: Dan Beam <dbeam@chromium.org>
Commit-Queue: Hector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704871}
parent 1fede15c
...@@ -1083,15 +1083,28 @@ function onDeleteAutocompleteMatch(result) { ...@@ -1083,15 +1083,28 @@ function onDeleteAutocompleteMatch(result) {
return matchEl.classList.contains(CLASSES.SELECTED); return matchEl.classList.contains(CLASSES.SELECTED);
}); });
const wasFocused = matchEls[selected].contains(document.activeElement);
populateAutocompleteMatches(result.matches); populateAutocompleteMatches(result.matches);
if (result.matches.length === 0) { if (result.matches.length === 0) {
if (wasFocused) {
$(IDS.REALBOX).focus();
}
return; return;
} }
const newMatchEls = Array.from($(IDS.REALBOX_MATCHES).children); const newMatchEls = Array.from($(IDS.REALBOX_MATCHES).children);
const newSelected = Math.min(newMatchEls.length - 1, selected); const newSelected = Math.min(newMatchEls.length - 1, selected);
selectMatchEl(newMatchEls[newSelected]); const newSelectedEl = newMatchEls[newSelected];
selectMatchEl(newSelectedEl);
if (wasFocused) {
const removeIcon = newSelectedEl.querySelector(`.${CLASSES.REMOVE_ICON}`);
assert(removeIcon || newSelectedEl).focus();
}
updateRealboxOutput({ updateRealboxOutput({
moveCursorToEnd: true, moveCursorToEnd: true,
inline: '', inline: '',
......
...@@ -564,10 +564,15 @@ test.realbox.testSupportedDeletion = function() { ...@@ -564,10 +564,15 @@ test.realbox.testSupportedDeletion = function() {
assertEquals(1, test.realbox.deletedLines.length); assertEquals(1, test.realbox.deletedLines.length);
assertEquals(1, test.realbox.deletedLines[0]); assertEquals(1, test.realbox.deletedLines[0]);
matchesEl.children[1].focus();
assertEquals(matchesEl.children[1], document.activeElement);
chrome.embeddedSearch.searchBox.ondeleteautocompletematch( chrome.embeddedSearch.searchBox.ondeleteautocompletematch(
{success: true, matches: [test.realbox.getSearchMatch()]}); {success: true, matches: [test.realbox.getSearchMatch()]});
assertEquals(1, $(test.realbox.IDS.REALBOX_MATCHES).children.length); const newMatchesEl = $(test.realbox.IDS.REALBOX_MATCHES);
assertEquals(1, newMatchesEl.children.length);
assertEquals(newMatchesEl.children[0], document.activeElement);
}; };
test.realbox.testRemoveIcon = function() { test.realbox.testRemoveIcon = function() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment