Commit fc3f25a1 authored by Andrea Giammarchi's avatar Andrea Giammarchi

Issue 7234 - Cumultive patches for io-filter-list

These changes are related to #288 #287 #286 #285 #284
parent 5f4291cf
......@@ -490,7 +490,7 @@ function updateFilter(filter)
}
else
{
customFilters.push(filter.text);
customFilters.push(filter);
}
filtersMap[filter.text] = filter;
......@@ -502,7 +502,7 @@ function loadCustomFilters(filters)
updateFilter(filter);
const cfTable = $("#custom-filters io-filter-table");
cfTable.filters = filters.filter(({text}) => customFilters.includes(text));
cfTable.filters = customFilters;
const toggle = $("#custom-filters io-toggle.io-filter-table-state");
cfTable.disabled = !toggle.checked;
toggle.addEventListener("change", toggleFiltersTable);
......@@ -516,7 +516,7 @@ function toggleFiltersTable(event)
function removeCustomFilter(text)
{
const index = customFilters.indexOf(text);
const index = customFilters.findIndex(filter => filter.text === text);
if (index >= 0)
customFilters.splice(index, 1);
}
......
......@@ -269,6 +269,23 @@ class IOFilterList extends IOElement
if (!filter)
return;
// in case of empty filter, remove it
if (!text)
{
browser.runtime.sendMessage({
type: "filters.remove",
text: filter.text
}).then(errors =>
{
if (!errors.length)
{
this.selected.delete(filter);
this.render();
}
});
return;
}
// update filter and title
filter.text = text;
currentTarget.title = text;
......@@ -561,6 +578,7 @@ const issues = new WeakMap();
// used to show warnings in the last column
const warnings = new WeakMap();
const warning = browser.i18n.getMessage("options_filterList_slow");
// relate either issues or warnings to a filter
const createImageFor = (weakMap, filter) =>
......@@ -570,6 +588,8 @@ const createImageFor = (weakMap, filter) =>
image.src = `skin/icons/${isIssue ? "error" : "alert"}.svg`;
if (isIssue)
image.title = filter.reason;
else
image.title = warning;
weakMap.set(filter, image);
return image;
};
......@@ -617,10 +637,12 @@ function getFilter(event)
// is higher than scrollHeight and other cases too
function getScrollTop(value, scrollHeight)
{
return Math.max(
const scrollTop = Math.max(
0,
Math.min(scrollHeight || Infinity, value)
);
// avoid division by zero gotchas
return isNaN(scrollTop) ? 0 : scrollTop;
}
function getWarning(filter)
......
......@@ -292,6 +292,10 @@
"description": "Update button in Advanced tab",
"message": "update all filter lists"
},
"options_filterList_slow": {
"description": "A slow filter highlighted through the warning icon",
"message": "The pattern you entered is too short and, therefore, will slow down Adblock Plus, hindering your browsing experience. Please enter a longer pattern."
},
"options_customFilters_title": {
"description": "Section title in Advanced tab",
"message": "Your custom filters"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment