Bug 1453589 - Select next item in list when removing items in Site Data Manager. r=johannh

Select next item in list when removing items in Site Data Manager. When there
are multiple selected sites, it will select the next item after the last
previously selected item.

Differential Revision: https://phabricator.services.mozilla.com/D965
This commit is contained in:
Michael Kohler 2018-04-19 09:35:31 -04:00
Родитель 632711f514
Коммит 0b7144da8b
4 изменённых файлов: 19 добавлений и 7 удалений

Просмотреть файл

@ -210,14 +210,16 @@ add_task(async function() {
function removeSelectedSite(hosts) {
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
let removeBtn = frameDoc.getElementById("removeSelected");
is(removeBtn.disabled, true, "Should start with disabled removeSelected button");
let sitesList = frameDoc.getElementById("sitesList");
hosts.forEach(host => {
let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
if (site) {
site.click();
let currentSelectedIndex = sitesList.selectedIndex;
is(removeBtn.disabled, false, "Should enable the removeSelected button");
removeBtn.doCommand();
is(removeBtn.disabled, true, "Should disable the removeSelected button");
is(sitesList.selectedIndex, currentSelectedIndex);
} else {
ok(false, `Should not select and remove inexistent site of ${host}`);
}

Просмотреть файл

@ -50,13 +50,14 @@ add_task(async function() {
// Test the initial state
assertSitesListed(doc, fakeHosts);
let win = gBrowser.selectedBrowser.contentWindow;
let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
let removeBtn = frameDoc.getElementById("removeSelected");
is(removeBtn.disabled, true, "Should start with disabled removeSelected button");
let removeDialogOpenPromise = BrowserTestUtils.promiseAlertDialogOpen("accept", REMOVE_DIALOG_URL);
let settingsDialogClosePromise = promiseSettingsDialogClose();
let win = gBrowser.selectedBrowser.contentWindow;
let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
// Select some sites to remove.
let sitesList = frameDoc.getElementById("sitesList");
fakeHosts.slice(0, 2).forEach(host => {
@ -64,10 +65,9 @@ add_task(async function() {
sitesList.addItemToSelection(site);
});
let removeBtn = frameDoc.getElementById("removeSelected");
is(removeBtn.disabled, false, "Should enable the removeSelected button");
removeBtn.doCommand();
is(removeBtn.disabled, true, "Should disable the removeSelected button");
is(sitesList.selectedIndex, 0, "Should select next item");
let saveBtn = frameDoc.getElementById("save");
assertSitesListed(doc, fakeHosts.slice(2));

Просмотреть файл

@ -140,7 +140,6 @@ function assertSitesListed(doc, hosts) {
let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
ok(site, `Should list the site of ${host}`);
});
is(removeBtn.disabled, true, "Should disable the removeSelected button");
is(removeAllBtn.disabled, false, "Should enable the removeAllBtn button");
}

Просмотреть файл

@ -259,8 +259,19 @@ let gSiteDataSettings = {
},
onClickRemoveSelected() {
let lastIndex = this._list.selectedItems.length - 1;
let lastSelectedItem = this._list.selectedItems[lastIndex];
let lastSelectedItemPosition = this._list.getIndexOfItem(lastSelectedItem);
let nextSelectedItem = this._list.getItemAtIndex(lastSelectedItemPosition + 1);
this._removeSiteItems(this._list.selectedItems);
this._list.clearSelection();
if (nextSelectedItem) {
this._list.selectedItem = nextSelectedItem;
} else {
this._list.selectedIndex = this._list.itemCount - 1;
}
},
onClickRemoveAll() {