From 5a67d926da06f8658102130676884d368ec4d32a Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 4 Jun 2017 12:22:51 +0300 Subject: [PATCH] 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. --- manage.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/manage.js b/manage.js index d1f3149e..c5485367 100644 --- a/manage.js +++ b/manage.js @@ -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); } }