From a10984ea039431d9bc9fba6f0795a6bcb9c8785f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 13 Feb 2025 15:55:25 +0000 Subject: [PATCH] Inspector: Keep current property filter when switching selected node If you have a search filter and then click on a different node, this now applies the filter to the new node's properties, instead of showing all of them. --- Base/res/ladybird/inspector.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Base/res/ladybird/inspector.js b/Base/res/ladybird/inspector.js index 4902c8f6ce..3ca035a505 100644 --- a/Base/res/ladybird/inspector.js +++ b/Base/res/ladybird/inspector.js @@ -336,6 +336,12 @@ inspector.setStyleSheetSource = (identifier, sourceBase64) => { styleSheetSource.innerHTML = decodeBase64(sourceBase64); }; +const applyPropertyFilter = (row, searchText) => { + const nameMatch = row.cells[0].textContent.toLowerCase().includes(searchText); + const valueMatch = row.cells[1].textContent.toLowerCase().includes(searchText); + row.style.display = nameMatch || valueMatch ? "" : "none"; +}; + const setupPropertyFilter = inputId => { const filterInput = document.getElementById(`${inputId}-filter`); @@ -345,10 +351,7 @@ const setupPropertyFilter = inputId => { const rows = tbody.getElementsByTagName("tr"); for (let row of rows) { - const nameMatch = row.cells[0].textContent.toLowerCase().includes(searchText); - const valueMatch = row.cells[1].textContent.toLowerCase().includes(searchText); - - row.style.display = nameMatch || valueMatch ? "" : "none"; + applyPropertyFilter(row, searchText); } }); }; @@ -359,6 +362,8 @@ inspector.createPropertyTables = (computedStyle, resolvedStyle, customProperties let newTable = document.createElement("tbody"); newTable.setAttribute("id", tableID); + let searchText = oldTable.parentNode.parentNode.querySelector(".property-filter").value; + Object.keys(properties) .sort((a, b) => { let baseResult = a.localeCompare(b); @@ -382,6 +387,10 @@ inspector.createPropertyTables = (computedStyle, resolvedStyle, customProperties let valueColumn = row.insertCell(); valueColumn.innerText = properties[name]; + + if (searchText) { + applyPropertyFilter(row, searchText); + } }); oldTable.parentNode.replaceChild(newTable, oldTable);