A high-performance Android storage analyzer that bypasses MTP using a native C++ daemon, a Rust TCP bridge, and a React Treemap UI.
Rust
Allow selecting files across pages of search results (#223)
Vishnu Srivatsavaa713f394e64b
diff --git a/docs/search.md b/docs/search.mdindex 2f23199..48dde9a 100644--- a/docs/search.md+++ b/docs/search.md@@ -48,6 +48,14 @@ directory itself; file results open the parent.eligibility rules as browsing: disabled for read-only scans and for namescontaining line-protocol delimiters.+## Selecting files++Use the checkboxes beside counted files to select them. Press Space to toggle+a focused checkbox. The selection count includes all pages of the current+search. Choose **Clear selection** to start over. A different query, folder+scope, or scan clears the selection. Deleting a file also clears it by+advancing the current scan revision.+## Bounds and measurementsThe response is bounded by the 1 MiB scan-query limit. The backend measuresdiff --git a/src/SearchFiles.tsx b/src/SearchFiles.tsxindex c186a0f..1e25133 100644--- a/src/SearchFiles.tsx+++ b/src/SearchFiles.tsx@@ -1,4 +1,4 @@-import { useEffect, useState } from "react";+import { useEffect, useRef, useState } from "react";import { getSearchResults } from "./scanIpc";import { FILE_TYPE_LABELS } from "./fileTypeSummary";import type { FileType } from "./fileTypeSummary";@@ -17,10 +17,15 @@ export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {const { generation, revision, root_path, read_only, total_size } = scope;const [input, setInput] = useState("");const [query, setQuery] = useState("");+ const [selection, setSelection] = useState<{ scope: string; ids: Set<number> } | null>(null);+ const searchInput = useRef<HTMLInputElement>(null);const [entireScan, setEntireScan] = useState(false);const fileType = category?.kind ?? null;const activeFolder = entireScan ? null : folder;const pageScope = JSON.stringify([generation, revision, activeFolder?.id, fileType]);+ const selectionScope = JSON.stringify([pageScope, query]);+ const selected = selection?.scope === selectionScope ? selection.ids : undefined;+ const selectedCount = selected?.size ?? 0;const [pagination, setPagination] = useState({ scope: pageScope, offsets: [0] });// A revision changes DFS order. Reset synchronously before issuing a request;// keep the submitted query, but never carry offsets into a changed snapshot.@@ -44,14 +49,27 @@ export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {const error = state.key === key ? state.error : undefined;const submit = () => {if (!input) return;+ if (input !== query) setSelection(null);setQuery(input);setPagination({ scope: pageScope, offsets: [0] });};const results = data?.results ?? [];const changeScope = () => {+ setSelection(null);setEntireScan(value => !value);setPagination({ scope: "", offsets: [0] });};+ const setFileSelected = (id: number, checked: boolean) => {+ setSelection(current => {+ const ids = new Set(current?.scope === selectionScope ? current.ids : undefined);+ if (checked) ids.add(id); else ids.delete(id);+ return { scope: selectionScope, ids };+ });+ };+ const clearSelection = () => {+ setSelection(null);+ searchInput.current?.focus();+ };const range = results.length ? `${skip + 1}–${skip + results.length}` : "0";const status = category? data ? `Showing ${range} files` : error ? "Files unavailable" : "Loading files…"@@ -63,7 +81,7 @@ export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {<button type="button" autoFocus disabled={busy} onClick={category.clear}className="text-xs text-accent-400 hover:underline">Clear filter</button></div> : <form className="flex items-center gap-2 py-3" onSubmit={event => { event.preventDefault(); submit(); }}>- <input id="search-input" value={input} disabled={busy}+ <input id="search-input" ref={searchInput} value={input} disabled={busy}onChange={event => setInput(event.target.value)}placeholder={activeFolder ? "Search names in this folder" : "Search names in this scan"}className="flex-1 bg-zinc-900 border border-zinc-700 rounded px-3 py-1.5 text-sm text-zinc-200" />@@ -76,8 +94,15 @@ export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {{activeFolder ? "Search entire scan" : "Search this folder"}</button></div>}- <div className="flex items-center justify-between gap-3 pb-3">- <p role="status" className="text-xs text-zinc-400">{status}</p>+ <div className="flex flex-wrap items-center justify-between gap-3 pb-3">+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-zinc-400">+ <p role="status" className="break-all">{status}</p>+ {!category && <span id="search-selection-count" role="status" className={selectedCount ? "text-accent-300" : "sr-only"}>+ {selectedCount === 1 ? "1 file selected" : selectedCount > 1 ? `${selectedCount.toLocaleString("en-US")} files selected` : ""}+ </span>}+ {selectedCount > 0 && <button type="button" disabled={busy} onClick={clearSelection}+ className="text-accent-400 hover:underline">Clear selection</button>}+ </div><div className="flex gap-2 shrink-0 text-xs"><button disabled={busy || !data || skip === 0} onClick={() => setPagination({ scope: pageScope, offsets: offsets.slice(0, -1) })}className="text-zinc-300 hover:underline disabled:text-zinc-600">Previous</button>@@ -91,6 +116,12 @@ export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {</p>}<ol className="divide-y divide-zinc-800/80">{results.map(({ node, path }) => <li key={node.id} className="search-result-row flex items-center gap-3 py-3">+ {!category && <div className="w-4 shrink-0">+ {node.type === "file" && node.counted && <input type="checkbox" disabled={busy}+ aria-label={`Select ${node.name}`} checked={selected?.has(node.id) ?? false}+ onChange={event => setFileSelected(node.id, event.currentTarget.checked)}+ className="block size-4 accent-accent-500 cursor-pointer" />}+ </div>}<div className="flex-1 min-w-0"><p className="text-sm text-zinc-200 whitespace-pre-wrap break-all">{node.name}</p><p className="text-xs text-zinc-500 font-mono whitespace-pre-wrap break-all" dir="auto">{path}</p>diff --git a/tests/browser_keys.mjs b/tests/browser_keys.mjsindex fc5bd5a..3cbf957 100644--- a/tests/browser_keys.mjs+++ b/tests/browser_keys.mjs@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";const keys = {Enter: { key: "Enter", code: "Enter", windowsVirtualKeyCode: 13, text: "\r" },+ Space: { key: " ", code: "Space", windowsVirtualKeyCode: 32, text: " " },Tab: { key: "Tab", code: "Tab", windowsVirtualKeyCode: 9 },"Shift+Tab": { key: "Tab", code: "Tab", windowsVirtualKeyCode: 9, modifiers: 8 },Escape: { key: "Escape", code: "Escape", windowsVirtualKeyCode: 27 },diff --git a/tests/check_scan_ui.py b/tests/check_scan_ui.pyindex 944d75f..f2a09b4 100644--- a/tests/check_scan_ui.py+++ b/tests/check_scan_ui.py@@ -118,7 +118,7 @@ def main():value = json.loads(self.rfile.read(length))if self.path == '/keyboard':if not isinstance(value, dict) or value.get('key') not in (- 'Enter', 'Tab', 'Shift+Tab', 'Escape', 'Home', 'End',+ 'Enter', 'Space', 'Tab', 'Shift+Tab', 'Escape', 'Home', 'End','ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'):self.send_error(400)returndiff --git a/tests/scan_ui_fixture.js b/tests/scan_ui_fixture.jsindex 471cc6f..4239bf9 100644--- a/tests/scan_ui_fixture.js+++ b/tests/scan_ui_fixture.js@@ -305,7 +305,7 @@const report = (passed, error) => {const output = document.createElement("pre");output.id = "scan-test-report";- output.textContent = JSON.stringify({ fixture: "scan-ui", passed, error, ipc_calls: calls.length, wide_paging: widePaging, expanded_tree: expandedTree, checks: passed ? ["offline fonts under CSP", "bounded collapsed discovery diagnostics", "discovery retry recovery", "setup alignment", "result fonts", "file label semantics", "usable file workspace", "keyboard storage map visibility", "collapsible diagnostics", "complete paging", "directory paging focus and retries", "expanded-tree row growth and keyboard focus", "first-scan comparison", "unchanged comparison after rescan", "deletion delta comparison", "cross-device comparison isolation", "bounded package-folder paging and coverage", "package query retries and stale replies", "bounded file-type totals", "file-type retry and malformed response", "file-type generation and deletion revision", "file-type coverage and empty scan", "file-type drilldown paging, keyboard and revision", "bounded largest files", "late largest response", "largest query retry", "malformed largest response recovery", "largest ID-only deletion", "largest read-only guards", "largest folder navigation without rescanning", "bounded search results", "late search response", "search retry and malformed response", "search ID-only deletion", "read-only search deletion disabled", "late zoom", "Other tile", "stale confirmation", "exact confirmation whitespace", "reachable long-path confirmation", "native modal keyboard focus and cancellation", "ID-only deletion", "revision refresh", "partial failure", "read-only", "acknowledged shutdown", "unconfirmed shutdown", "reconnect", "stop action ordering", "duplicate rescan guard", "rescan failure recovery", "rescan cancellation recovery", "toast dismissal integration", "bounded diagnostic integration"] : undefined });+ output.textContent = JSON.stringify({ fixture: "scan-ui", passed, error, ipc_calls: calls.length, wide_paging: widePaging, expanded_tree: expandedTree, checks: passed ? ["offline fonts under CSP", "bounded collapsed discovery diagnostics", "discovery retry recovery", "setup alignment", "result fonts", "file label semantics", "usable file workspace", "keyboard storage map visibility", "collapsible diagnostics", "complete paging", "directory paging focus and retries", "expanded-tree row growth and keyboard focus", "first-scan comparison", "unchanged comparison after rescan", "deletion delta comparison", "cross-device comparison isolation", "bounded package-folder paging and coverage", "package query retries and stale replies", "bounded file-type totals", "file-type retry and malformed response", "file-type generation and deletion revision", "file-type coverage and empty scan", "file-type drilldown paging, keyboard and revision", "bounded largest files", "late largest response", "largest query retry", "malformed largest response recovery", "largest ID-only deletion", "largest read-only guards", "largest folder navigation without rescanning", "bounded search results", "scoped search selection", "late search response", "search retry and malformed response", "search ID-only deletion", "read-only search deletion disabled", "late zoom", "Other tile", "stale confirmation", "exact confirmation whitespace", "reachable long-path confirmation", "native modal keyboard focus and cancellation", "ID-only deletion", "revision refresh", "partial failure", "read-only", "acknowledged shutdown", "unconfirmed shutdown", "reconnect", "stop action ordering", "duplicate rescan guard", "rescan failure recovery", "rescan cancellation recovery", "toast dismissal integration", "bounded diagnostic integration"] : undefined });document.body.append(output);void fetch("/report", { method: "POST", body: output.textContent }).then(() => {if (passed) location.replace("/tests/toast_lifecycle_fixture.html");@@ -671,6 +671,8 @@// Search: bounded pages, a superseded held response, retry, malformed// recovery, and ID-only deletion. No rescan is ever allowed here.const searchRows = () => [...document.querySelectorAll(".search-result-row")];+ const searchCheckbox = (row = searchRows()[0]) => row?.querySelector('input[type="checkbox"]');+ const selectionCount = () => document.querySelector("#search-selection-count")?.textContent ?? "";const searchFor = text => {const input = document.querySelector("#search-input");const set = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;@@ -686,6 +688,11 @@searchFor("nested");await waitFor(() => searchRows().length === 37, "First folder search page missing");check(calls.filter(call => call.command === "get_search_results").at(-1).args.folderId === 1, "Search lost the folder ID");+ searchNext().focus();+ await pressKey("Tab");+ check(document.activeElement === searchCheckbox(), "First search checkbox is missing from the tab order");+ await pressKey("Space");+ check(searchCheckbox().checked && selectionCount() === "1 file selected", "Space did not select a search result");holdSearch = true;searchNext().click();await waitFor(() => typeof resolveSearch === "function", "Second folder page did not start");@@ -695,6 +702,7 @@resolveSearch = undefined;await pause(30);check(searchRows()[0]?.textContent.includes("nested-0"), "Late folder page replaced whole-scan results");+ check(!searchCheckbox().checked && !selectionCount(), "Folder selection leaked into the whole scan");searchFor("file");await waitFor(() => searchRows().length === 100, "Whole-scan results missing");button("Search this folder").click();@@ -723,13 +731,23 @@searchFor("nested");await waitFor(() => searchRows().length === 37, "Byte-bounded search page missing");const nestedCount = searchRows().length;+ searchCheckbox().click();const firstNestedNames = searchRows().map(row => row.textContent);searchNext().click();await waitFor(() => searchRows()[0]?.textContent.includes("nested-37"), "Short-page continuation skipped matches");check(calls.filter(call => call.command === "get_search_results").at(-1).args.skip === 37, "Short-page continuation used a fixed offset");+ check(!searchCheckbox().checked && selectionCount() === "1 file selected", "Paging lost or applied selection to the wrong row");+ searchCheckbox().click();+ check(selectionCount() === "2 files selected", "Selection count did not include both pages");button("Previous").click();await waitFor(() => searchRows()[0]?.textContent.includes("nested-0"), "Short-page Previous failed");check(JSON.stringify(searchRows().map(row => row.textContent)) === JSON.stringify(firstNestedNames), "Previous changed short-page boundaries");+ check(searchCheckbox().checked && selectionCount() === "2 files selected", "Previous lost cross-page selection");+ button("Clear selection").focus();+ await pressKey("Enter");+ check(!searchCheckbox().checked && !selectionCount() && document.activeElement.id === "search-input",+ "Keyboard clearing did not reset selection and restore focus");+ searchCheckbox().click();searchFor("zzz-no-match");await waitFor(() => document.body.textContent.includes("No matching names"), "Empty search state missing");failSearch = true;@@ -743,6 +761,7 @@check(searchRows().length === 0, "Malformed search response retained rows");button("Retry").click();await waitFor(() => searchRows().length === nestedCount, "Malformed search response did not recover");+ check(!searchCheckbox().checked && !selectionCount(), "Returning to an old query restored its selection");searchFor("zzz-no-match");await waitFor(() => document.body.textContent.includes("No matching names"), "Pre-delete empty state missing");searchFor("file");@@ -754,6 +773,8 @@// disappears on the revision refresh.const target = searchRows().find(row => !row.textContent.includes("/large-folder/")&& !row.textContent.includes(" file-0 ") && !row.textContent.includes(" file-1 "));+ searchCheckbox(target).click();+ check(selectionCount() === "1 file selected", "Search target could not be selected before deletion");const targetLabel = target.querySelector('[aria-label^="Delete "]').getAttribute("aria-label");const deletesBeforeSearch = calls.filter(call => call.command === "delete_item").length;const trigger = target.querySelector('[aria-label^="Delete "]');@@ -797,6 +818,7 @@await waitFor(() => searchRows()[0]?.textContent.includes(" file-0 "), "Deletion did not restart search pagination");check(calls.filter(call => call.command === "get_search_results").at(-1).args.skip === 0, "Revision refresh retained the old offset");check(!button("Previous"), "Previous remained enabled after revision reset");+ check(!searchCheckbox().checked && !selectionCount(), "Selection survived a deletion revision");check(calls.filter(call => call.command === "delete_item").length === deletesBeforeSearch + 1, "Search deletion count wrong");check(calls.filter(item => item.command === "run_scan").length === scanCount + 1, "Search browsing rescanned the phone");button("Storage map").click();