Diff
Modified: trunk/LayoutTests/inspector/unit-tests/css-query-controller-expected.txt (295059 => 295060)
--- trunk/LayoutTests/inspector/unit-tests/css-query-controller-expected.txt 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/LayoutTests/inspector/unit-tests/css-query-controller-expected.txt 2022-05-31 18:09:31 UTC (rev 295060)
@@ -3,19 +3,19 @@
== Running test suite: CSSQueryController
-- Running test case: FindSpecialCharacterIndices
-PASS: Result for margin should match expected special indices.
-PASS: Result for MARGIN should match expected special indices.
-PASS: Result for margin-right should match expected special indices.
-PASS: Result for -webkit-mask should match expected special indices.
-PASS: Result for --var-kebab-case should match expected special indices.
-PASS: Result for --varCamelCase should match expected special indices.
-PASS: Result for --varlowercase should match expected special indices.
-PASS: Result for --VARUPPERCASE should match expected special indices.
-PASS: Result for --var_snake_case should match expected special indices.
-PASS: Result for var(--name) should match expected special indices.
-PASS: Result for rgb(0, 0, 0) should match expected special indices.
-PASS: Result for rgb(0 0 0 / 100%) should match expected special indices.
-PASS: Result for rgb(0 0 0 / 0.1) should match expected special indices.
+PASS: The special characters in "margin" should match.
+PASS: The special characters in "MARGIN" should match.
+PASS: The special characters in "margin-right" should match.
+PASS: The special characters in "-webkit-mask" should match.
+PASS: The special characters in "--var-kebab-case" should match.
+PASS: The special characters in "--varCamelCase" should match.
+PASS: The special characters in "--varlowercase" should match.
+PASS: The special characters in "--VARUPPERCASE" should match.
+PASS: The special characters in "--var_snake_case" should match.
+PASS: The special characters in "var(--name)" should match.
+PASS: The special characters in "rgb(0, 0, 0)" should match.
+PASS: The special characters in "rgb(0 0 0 / 100%)" should match.
+PASS: The special characters in "rgb(0 0 0 / 0.1)" should match.
-- Running test case: ExecuteQueryAgainstNoValues
PASS: Should return no results.
Modified: trunk/LayoutTests/inspector/unit-tests/css-query-controller.html (295059 => 295060)
--- trunk/LayoutTests/inspector/unit-tests/css-query-controller.html 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/LayoutTests/inspector/unit-tests/css-query-controller.html 2022-05-31 18:09:31 UTC (rev 295060)
@@ -15,55 +15,55 @@
let tests = [
{
padvalue: "margin",
- expected: "^",
+ expected: "^ ",
},
{
padvalue: "MARGIN",
- expected: "^",
+ expected: "^ ",
},
{
padvalue: "margin-right",
- expected: "^ ^^",
+ expected: "^ ^^ ",
},
{
padvalue: "-webkit-mask",
- expected: "^^ ^^",
+ expected: "^^ ^^ ",
},
{
padvalue: "--var-kebab-case",
- expected: "^^^ ^^ ^^",
+ expected: "^^^ ^^ ^^ ",
},
{
padvalue: "--varCamelCase",
- expected: "^^^ ^ ^",
+ expected: "^^^ ^ ^ ",
},
{
padvalue: "--varlowercase",
- expected: "^^^",
+ expected: "^^^ ",
},
{
padvalue: "--VARUPPERCASE",
- expected: "^^^",
+ expected: "^^^ ",
},
{
padvalue: "--var_snake_case",
- expected: "^^^ ^^ ^^",
+ expected: "^^^ ^^ ^^ ",
},
{
padvalue: "var(--name)",
- expected: "^ ^^^",
+ expected: "^ ^^^ ",
},
{
padvalue: "rgb(0, 0, 0)",
- expected: "^",
+ expected: "^ ",
},
{
padvalue: "rgb(0 0 0 / 100%)",
- expected: "^",
+ expected: "^ ",
},
{
padvalue: "rgb(0 0 0 / 0.1)",
- expected: "^",
+ expected: "^ ",
}
];
@@ -72,12 +72,12 @@
specialIndices.forEach((index) => {
mask = mask.substr(0, index) + "^" + mask.substr(index + 1);
});
- return mask.trim();
+ return mask;
}
for (let {padvalue, expected} of tests) {
- let actual = createSpecialMask(padvalue, matcher._findSpecialCharacterIndices(padvalue));
- InspectorTest.expectEqual(actual, expected, `Result for ${padvalue} should match expected special indices.`);
+ let actual = createSpecialMask(padvalue, matcher._findSpecialCharacterIndicesInPropertyName(padvalue));
+ InspectorTest.expectEqual(actual, expected, `The special characters in "${padvalue}" should match.`);
}
}
});
Modified: trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt (295059 => 295060)
--- trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt 2022-05-31 18:09:31 UTC (rev 295060)
@@ -2,17 +2,31 @@
== Running test suite: ResourceQueryController
--- Running test case: FindSpecialCharacterIndices
-PASS: Result should match expected special indices.
-PASS: Result should match expected special indices.
-PASS: Result should match expected special indices.
-PASS: Result should match expected special indices.
-PASS: Result should match expected special indices.
-PASS: Result should match expected special indices.
-PASS: Result should match expected special indices.
-PASS: Result should match expected special indices.
-PASS: Result should match expected special indices.
+-- Running test case: FindSpecialCharacterIndices.DisplayName
+PASS: The special characters in "Abcd" should match.
+PASS: The special characters in "ABCDE" should match.
+PASS: The special characters in "abcdef" should match.
+PASS: The special characters in "abc-def" should match.
+PASS: The special characters in "abc---def" should match.
+PASS: The special characters in "a-bc_de.f" should match.
+PASS: The special characters in "AxBxCxDxExFx" should match.
+PASS: The special characters in "ab-c_d.ef" should match.
+PASS: The special characters in "AxBxCxdxexDxyxEF" should match.
+-- Running test case: FindSpecialCharacterIndices.URL
+PASS: The special characters in "aBcd" should match.
+PASS: The special characters in "/aBcd" should match.
+PASS: The special characters in "aBcd_dEfg" should match.
+PASS: The special characters in "/aBcd_dEfg" should match.
+PASS: The special characters in "aBcd-dEfg" should match.
+PASS: The special characters in "/aBcd-dEfg" should match.
+PASS: The special characters in "aBcd.dEfg" should match.
+PASS: The special characters in "/aBcd.dEfg" should match.
+PASS: The special characters in "aBcd/dEfg" should match.
+PASS: The special characters in "/aBcd/dEfg" should match.
+PASS: The special characters in "aBcd/dEfg_hIjk-lMno.pQrs" should match.
+PASS: The special characters in "/aBcd/dEfg_hIjk-lMno.pQrs" should match.
+
-- Running test case: ExecuteQueryAgainstNoResources
PASS: Should return no results.
Modified: trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html (295059 => 295060)
--- trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html 2022-05-31 18:09:31 UTC (rev 295060)
@@ -8,30 +8,30 @@
let suite = InspectorTest.createSyncSuite("ResourceQueryController");
suite.addTestCase({
- name: "FindSpecialCharacterIndices",
- description: "Should correctly find special filename characters.",
+ name: "FindSpecialCharacterIndices.DisplayName",
+ description: "Should correctly find special filename characters in the displayName.",
test() {
let matcher = new WI.ResourceQueryController;
let tests = [
{
filename: "Abcd",
- expected: "^"
+ expected: "^ ",
},
{
filename: "ABCDE",
- expected: "^"
+ expected: "^ ",
},
{
filename: "abcdef",
- expected: "^",
+ expected: "^ ",
},
{
filename: "abc-def",
- expected: "^ ^^",
+ expected: "^ ^^ ",
},
{
filename: "abc---def",
- expected: "^ ^^^^",
+ expected: "^ ^^^^ ",
},
{
filename: "a-bc_de.f",
@@ -39,15 +39,15 @@
},
{
filename: "AxBxCxDxExFx",
- expected: "^ ^ ^ ^ ^ ^",
+ expected: "^ ^ ^ ^ ^ ^ ",
},
{
filename: "ab-c_d.ef",
- expected: "^ ^^^^^^",
+ expected: "^ ^^^^^^ ",
},
{
filename: "AxBxCxdxexDxyxEF",
- expected: "^ ^ ^ ^ ^",
+ expected: "^ ^ ^ ^ ^ ",
},
];
@@ -56,17 +56,88 @@
specialIndices.forEach((index) => {
mask = mask.substr(0, index) + "^" + mask.substr(index + 1);
});
- return mask.trim();
+ return mask;
}
for (let {filename, expected} of tests) {
- let actual = createSpecialMask(filename, matcher._findSpecialCharacterIndices(filename));
- InspectorTest.expectEqual(actual, expected, "Result should match expected special indices.");
+ let actual = createSpecialMask(filename, matcher._findSpecialCharacterIndicesInDisplayName(filename));
+ InspectorTest.expectEqual(actual, expected, `The special characters in "${filename}" should match.`);
}
}
});
suite.addTestCase({
+ name: "FindSpecialCharacterIndices.URL",
+ description: "Should correctly find special filename characters in the url.",
+ test() {
+ let matcher = new WI.ResourceQueryController;
+ let tests = [
+ {
+ filename: "aBcd",
+ expected: "^^ ",
+ },
+ {
+ filename: "/aBcd",
+ expected: "^^^ ",
+ },
+ {
+ filename: "aBcd_dEfg",
+ expected: "^^ ^^^ ",
+ },
+ {
+ filename: "/aBcd_dEfg",
+ expected: "^^^ ^^^ ",
+ },
+ {
+ filename: "aBcd-dEfg",
+ expected: "^^ ^^^ ",
+ },
+ {
+ filename: "/aBcd-dEfg",
+ expected: "^^^ ^^^ ",
+ },
+ {
+ filename: "aBcd.dEfg",
+ expected: "^^ ^^^ ",
+ },
+ {
+ filename: "/aBcd.dEfg",
+ expected: "^^^ ^^^ ",
+ },
+ {
+ filename: "aBcd/dEfg",
+ expected: "^^ ^^^ ",
+ },
+ {
+ filename: "/aBcd/dEfg",
+ expected: "^^^ ^^^ ",
+ },
+ {
+ filename: "aBcd/dEfg_hIjk-lMno.pQrs",
+ expected: "^^ ^^^ ^^^ ^^^ ^^^ ",
+ },
+ {
+ filename: "/aBcd/dEfg_hIjk-lMno.pQrs",
+ expected: "^^^ ^^^ ^^^ ^^^ ^^^ ",
+ },
+ ];
+
+ function createSpecialMask(filename, specialIndices) {
+ let mask = " ".repeat(filename.length);
+ specialIndices.forEach((index) => {
+ mask = mask.substr(0, index) + "^" + mask.substr(index + 1);
+ });
+ return mask;
+ }
+
+ for (let {filename, expected} of tests) {
+ let actual = createSpecialMask(filename, matcher._findSpecialCharacterIndicesInURL(filename));
+ InspectorTest.expectEqual(actual, expected, `The special characters in "${filename}" should match.`);
+ }
+ }
+ });
+
+ suite.addTestCase({
name: "ExecuteQueryAgainstNoResources",
description: "Should return no results if no resources were added to the controller.",
test() {
Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSQueryController.js (295059 => 295060)
--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSQueryController.js 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSQueryController.js 2022-05-31 18:09:31 UTC (rev 295060)
@@ -63,7 +63,7 @@
for (let value of this._values) {
if (!this._cachedSpecialCharacterIndicesForValueMap.has(value))
- this._cachedSpecialCharacterIndicesForValueMap.set(value, this._findSpecialCharacterIndices(value));
+ this._cachedSpecialCharacterIndicesForValueMap.set(value, this._findSpecialCharacterIndicesInPropertyName(value));
let matches = this.findQueryMatches(query, value.toLowerCase(), this._cachedSpecialCharacterIndicesForValueMap.get(value));
if (matches.length)
@@ -79,37 +79,8 @@
// Private
- _findSpecialCharacterIndices(string)
+ _findSpecialCharacterIndicesInPropertyName(propertyName)
{
- if (!string.length)
- return [];
-
- const separators = "-_";
-
- // Special characters include the following:
- // 1. The first character.
- // 2. Uppercase characters that follow a lowercase letter.
- // 3. Separators and the first character following the separator.
- let indices = [0];
-
- for (let i = 1; i < string.length; ++i) {
- let character = string[i];
- let isSpecial = false;
-
- if (separators.includes(character))
- isSpecial = true;
- else {
- let previousCharacter = string[i - 1];
- if (separators.includes(previousCharacter))
- isSpecial = true;
- else if (character.isUpperCase() && previousCharacter.isLowerCase())
- isSpecial = true;
- }
-
- if (isSpecial)
- indices.push(i);
- }
-
- return indices;
+ return this.findSpecialCharacterIndices(propertyName, "-_");
}
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/QueryController.js (295059 => 295060)
--- trunk/Source/WebInspectorUI/UserInterface/Controllers/QueryController.js 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/QueryController.js 2022-05-31 18:09:31 UTC (rev 295060)
@@ -108,4 +108,39 @@
return matches;
}
+
+ // Protected
+
+ findSpecialCharacterIndices(string, separators)
+ {
+ if (!string.length)
+ return [];
+
+ // Special characters include the following:
+ // - The first character.
+ // - Uppercase characters that follow a lowercase letter.
+ // - Separators and the first character following the separator.
+
+ let indices = [0];
+
+ for (let i = 1; i < string.length; ++i) {
+ let character = string[i];
+ let isSpecial = false;
+
+ if (separators.includes(character))
+ isSpecial = true;
+ else {
+ let previousCharacter = string[i - 1];
+ if (separators.includes(previousCharacter))
+ isSpecial = true;
+ else if (character.isUpperCase() && previousCharacter.isLowerCase())
+ isSpecial = true;
+ }
+
+ if (isSpecial)
+ indices.push(i);
+ }
+
+ return indices;
+ }
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js (295059 => 295060)
--- trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js 2022-05-31 18:09:31 UTC (rev 295060)
@@ -67,15 +67,36 @@
let results = [];
for (let [resource, cachedData] of this._resourceDataMap) {
- if (!cachedData.searchString) {
+ if (isEmptyObject(cachedData)) {
let displayName = resource.displayName;
- cachedData.searchString = displayName.toLowerCase();
- cachedData.specialCharacterIndices = this._findSpecialCharacterIndices(displayName);
+ cachedData.displayName = {
+ searchString: displayName.toLowerCase(),
+ specialCharacterIndices: this._findSpecialCharacterIndicesInDisplayName(displayName),
+ };
+
+ let url = ""
+ cachedData.url = {
+ searchString: url.toLowerCase(),
+ specialCharacterIndices: this._findSpecialCharacterIndicesInURL(url),
+ };
}
- let matches = this.findQueryMatches(query, cachedData.searchString, cachedData.specialCharacterIndices);
- if (matches.length)
- results.push(new WI.ResourceQueryResult(resource, matches, cookie));
+ let resourceResult = null;
+
+ let findQueryMatches = ({searchString, specialCharacterIndices}) => {
+ let matches = this.findQueryMatches(query, searchString, specialCharacterIndices);
+ if (!matches.length)
+ return;
+
+ let queryResult = new WI.ResourceQueryResult(resource, searchString, matches, cookie);
+ if (!resourceResult || resourceResult.rank < queryResult.rank)
+ resourceResult = queryResult;
+ };
+ findQueryMatches(cachedData.displayName);
+ findQueryMatches(cachedData.url);
+
+ if (resourceResult)
+ results.push(resourceResult);
}
// Resources are sorted in descending order by rank. Resources of equal
@@ -89,38 +110,13 @@
// Private
- _findSpecialCharacterIndices(string)
+ _findSpecialCharacterIndicesInDisplayName(displayName)
{
- if (!string.length)
- return [];
+ return this.findSpecialCharacterIndices(displayName, "_.-");
+ }
- const filenameSeparators = "_.-";
-
- // Special characters include the following:
- // 1. The first character.
- // 2. Uppercase characters that follow a lowercase letter.
- // 3. Filename separators and the first character following the separator.
- let indices = [0];
-
- for (let i = 1; i < string.length; ++i) {
- let character = string[i];
- let isSpecial = false;
-
- if (filenameSeparators.includes(character))
- isSpecial = true;
- else {
- let previousCharacter = string[i - 1];
- let previousCharacterIsSeparator = filenameSeparators.includes(previousCharacter);
- if (previousCharacterIsSeparator)
- isSpecial = true;
- else if (character.isUpperCase() && previousCharacter.isLowerCase())
- isSpecial = true;
- }
-
- if (isSpecial)
- indices.push(i);
- }
-
- return indices;
+ _findSpecialCharacterIndicesInURL(url)
+ {
+ return this.findSpecialCharacterIndices(url, "_.-/");
}
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js (295059 => 295060)
--- trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js 2022-05-31 18:09:31 UTC (rev 295060)
@@ -25,11 +25,12 @@
WI.ResourceQueryResult = class ResourceQueryResult extends WI.QueryResult
{
- constructor(resource, matches, cookie)
+ constructor(resource, searchString, matches, cookie)
{
console.assert(resource instanceof WI.Resource, resource);
super(resource, matches);
+ this._searchString = searchString;
this._cookie = cookie || null;
}
@@ -36,6 +37,7 @@
// Public
get resource() { return this.value; }
+ get searchString() { return this._searchString; }
get cookie() { return this._cookie; }
// Testing
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js (295059 => 295060)
--- trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js 2022-05-31 18:00:33 UTC (rev 295059)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js 2022-05-31 18:09:31 UTC (rev 295060)
@@ -76,19 +76,27 @@
_populateResourceTreeOutline()
{
- function createHighlightedTitleFragment(title, highlightTextRanges)
+ function createHighlightedTitleFragment(title, searchString, highlightTextRanges)
{
+ let shift = searchString.indexOf(title.toLowerCase());
+ console.assert(shift >= 0);
+
let titleFragment = document.createDocumentFragment();
let lastIndex = 0;
for (let textRange of highlightTextRanges) {
- if (textRange.startColumn > lastIndex)
- titleFragment.append(title.substring(lastIndex, textRange.startColumn));
+ let end = textRange.endColumn - shift;
+ if (end >= 0) {
+ let start = textRange.startColumn - shift;
+ if (start > lastIndex)
+ titleFragment.append(title.substring(lastIndex, start));
- let highlightSpan = document.createElement("span");
- highlightSpan.classList.add("highlighted");
- highlightSpan.append(title.substring(textRange.startColumn, textRange.endColumn));
- titleFragment.append(highlightSpan);
- lastIndex = textRange.endColumn;
+ let highlightSpan = document.createElement("span");
+ highlightSpan.classList.add("highlighted");
+ highlightSpan.append(title.substring(start, end));
+ titleFragment.append(highlightSpan);
+ }
+
+ lastIndex = end;
}
if (lastIndex < title.length)
@@ -122,7 +130,7 @@
if (!treeElement)
continue;
- treeElement.mainTitle = createHighlightedTitleFragment(resource.displayName, result.matchingTextRanges);
+ treeElement.mainTitle = createHighlightedTitleFragment(resource.displayName, result.searchString, result.matchingTextRanges);
if (resource instanceof WI.LocalResource && resource.localResourceOverride)
treeElement.subtitle = WI.UIString("Local Override");