manage: fix toggling a style when filtering by search

Previously a style entry would disappear when toggled on manage page with search filter applied because filterContainer() altered the original "container" parameter.
This commit is contained in:
tophf 2017-06-04 12:22:51 +03:00
parent 2b1d874236
commit 5a67d926da

View File

@ -764,8 +764,7 @@ function filterAndAppend({entry, container}) {
if (!filtersSelector.hide || !entry.matches(filtersSelector.hide)) {
entry.classList.add('hidden');
}
}
if ($('#search').value.trim()) {
} else if ($('#search').value.trim()) {
searchStyles({immediately: true, container});
}
reapplyFilter(container);
@ -774,14 +773,20 @@ function filterAndAppend({entry, container}) {
function reapplyFilter(container = installed) {
// A: show
let toUnhide = filtersSelector.hide ? filterContainer({hide: false}) : container;
let toHide = [];
let toUnhide = [];
if (filtersSelector.hide) {
filterContainer({hide: false});
} else {
toUnhide = container;
}
// showStyles() is building the page and no filters are active
if (toUnhide instanceof DocumentFragment) {
installed.appendChild(toUnhide);
return;
} else if (toUnhide.length && $('#search').value.trim()) {
searchStyles({immediately: true, container: toUnhide});
toUnhide = filterContainer({hide: false});
filterContainer({hide: false});
}
// filtering needed or a single-element job from handleUpdate()
const entries = installed.children;
@ -798,7 +803,9 @@ function reapplyFilter(container = installed) {
}
}
// B: hide
const toHide = filtersSelector.hide ? filterContainer({hide: true}) : [];
if (filtersSelector.hide) {
filterContainer({hide: true});
}
if (!toHide.length) {
return;
}
@ -831,16 +838,16 @@ function reapplyFilter(container = installed) {
if (container.filter) {
if (hide) {
// already filtered in previous invocation
return container;
return;
}
const toHide = [], toUnhide = [];
for (const el of container) {
(el.matches(selector) ? toUnhide : toHide).push(el);
}
container = toHide;
return toUnhide;
return;
} else if (hide) {
toHide = $$(selector, container);
} else {
return $$(selector, container);
toUnhide = $$(selector, container);
}
}