Skip to content

Commit c218444

Browse files
committed
[mv3] Improve handling of manual editing of custom filters
This fixes the creation/removal of spurious intermediate custom filters when manually editing.
1 parent d05b100 commit c218444

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

platform/mv3/extension/js/filter-manager-ui.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ async function removeSelectorsFromHostname(node) {
9696
qsa$(hostnameNode, 'li.selector.removed:not([data-ugly=""])')
9797
).map(a => a.dataset.ugly);
9898
if ( selectors.length === 0 ) { return; }
99+
dom.cl.add(dom.body, 'committing');
99100
updateContentEditability(false);
100101
await sendMessage({ what: 'removeCustomFilters', hostname, selectors });
101102
await debounceRenderCustomFilters();
102103
updateContentEditability(true);
104+
dom.cl.remove(dom.body, 'committing');
103105
}
104106

105107
async function unremoveSelectorsFromHostname(node) {
@@ -109,10 +111,12 @@ async function unremoveSelectorsFromHostname(node) {
109111
if ( hostname === undefined ) { return; }
110112
const selectors = selectorsFromNode(hostnameNode);
111113
if ( selectors.length === 0 ) { return; }
114+
dom.cl.add(dom.body, 'committing');
112115
updateContentEditability(false);
113116
await sendMessage({ what: 'addCustomFilters', hostname, selectors });
114117
await debounceRenderCustomFilters();
115118
updateContentEditability(true);
119+
dom.cl.remove(dom.body, 'committing');
116120
}
117121

118122
/******************************************************************************/
@@ -281,22 +285,22 @@ async function onHostnameChanged(target, before, after) {
281285
return;
282286
}
283287

288+
dom.cl.add(dom.body, 'committing');
284289
// Remove old hostname from storage
285290
if ( hostnameNode.dataset.ugly ) {
286291
await sendMessage({ what: 'removeAllCustomFilters',
287292
hostname: hostnameNode.dataset.ugly,
288293
});
289294
}
290-
291295
// Add selectors under new hostname to storage
292296
hostnameNode.dataset.ugly = uglyAfter;
293297
hostnameNode.dataset.pretty = after;
294298
await sendMessage({ what: 'addCustomFilters',
295299
hostname: hostnameFromNode(target),
296300
selectors: selectorsFromNode(target),
297301
});
298-
299302
await debounceRenderCustomFilters();
303+
dom.cl.remove(dom.body, 'committing');
300304
}
301305

302306
async function onSelectorChanged(target, before, after) {
@@ -312,23 +316,22 @@ async function onSelectorChanged(target, before, after) {
312316
return;
313317
}
314318

319+
dom.cl.add(dom.body, 'committing');
315320
const hostname = hostnameFromNode(target);
316-
317321
// Remove old selector from storage
318322
await sendMessage({ what: 'removeCustomFilters',
319323
hostname,
320324
selectors: [ selectorNode.dataset.ugly ],
321325
});
322-
323326
// Add new selector to storage
324327
selectorNode.dataset.ugly = ugly;
325328
selectorNode.dataset.pretty = pretty;
326329
await sendMessage({ what: 'addCustomFilters',
327330
hostname,
328331
selectors: [ ugly ],
329332
});
330-
331333
await debounceRenderCustomFilters();
334+
dom.cl.remove(dom.body, 'committing');
332335
}
333336

334337
async function onTextChanged(target) {
@@ -601,6 +604,7 @@ async function start() {
601604
dom.on('section[data-pane="filters"] [data-i18n="exportButton"]', 'click', exportToFile);
602605

603606
browser.storage.local.onChanged.addListener((changes, area) => {
607+
if ( dom.cl.has(dom.body, 'committing') ) { return; }
604608
if ( area !== undefined && area !== 'local' ) { return; }
605609
if ( Object.keys(changes).some(a => a.startsWith('site.')) ) {
606610
debounceRenderCustomFilters();

0 commit comments

Comments
 (0)