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