Bug 1544195 - Support wildcard on about:config r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D35981

--HG--
extra : moz-landing-system : lando
This commit is contained in:
YUKI "Piro" Hiroshi 2019-06-27 15:23:22 +00:00
parent 32899fcfad
commit a41b01fed5
2 changed files with 37 additions and 1 deletions

View File

@ -49,6 +49,11 @@ let gPrefInEdit = null;
*/
let gFilterString = null;
/**
* RegExp that should be matched to the preference name.
*/
let gFilterPattern = null;
/**
* True if we were requested to show all preferences.
*/
@ -121,6 +126,7 @@ class PrefRow {
get matchesFilter() {
return gFilterShowAll ||
(gFilterPattern && gFilterPattern.test(this.name)) ||
(gFilterString && this.name.toLowerCase().includes(gFilterString));
}
@ -452,7 +458,13 @@ function filterPrefs(options = {}) {
gFilterString = searchName.toLowerCase();
gFilterShowAll = !!options.showAll;
let showResults = gFilterString || gFilterShowAll;
gFilterPattern = null;
if (gFilterString.includes("*")) {
gFilterPattern = new RegExp(gFilterString.replace(/\*+/g, ".*"), "i");
gFilterString = "";
}
let showResults = gFilterString || gFilterPattern || gFilterShowAll;
document.getElementById("show-all").classList.toggle("hidden", showResults);
let prefArray = [];

View File

@ -81,6 +81,30 @@ add_task(async function test_search() {
});
});
add_task(async function test_search_wildcard() {
await AboutConfigTest.withNewTab(async function() {
const extra = 1; // "Add" row
// A trailing wildcard
this.search("test.about*");
Assert.equal(this.rows.length, 3 + extra);
// A wildcard in middle
this.search("test.about*a");
Assert.equal(this.rows.length, 2 + extra);
this.search("test.about*ab");
Assert.equal(this.rows.length, 1 + extra);
this.search("test.aboutcon*fig");
Assert.equal(this.rows.length, 3 + extra);
// Multiple wildcards in middle
this.search("test.about*fig*ab");
Assert.equal(this.rows.length, 1 + extra);
this.search("test.about*config*ab");
Assert.equal(this.rows.length, 1 + extra);
});
});
add_task(async function test_search_delayed() {
await AboutConfigTest.withNewTab(async function() {
// Start with the initial empty page.