Keep a multi-row sidebar selection through new traffic, and restore rows on Back

The shared Tree reset its selection to the last focused row after every
render, so several selected rows collapsed to one whenever the tree rendered
again, as new traffic changing the counts makes it. It now leaves the
selection alone while that row is still in view and selected.

The proxy's sidebar sync also makes All traffic exclusive, groups a saved
search's own OR in parentheses beside other rows, applies System's heading
query, and on Back or Forward selects the rows whose queries make up the
restored filter, compared by shape so AND and OR stay apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Gregory SchierandClaude Opus 5.5 authored and Stetta task tk_mwaxu5pizxqxbmzj committed 2026-11-10 11:01:54 -07:00
1 parent cc83c7cd1e
commit e0b435c416
10 files changed
+313 -29

No files matched your search

+12 -3
View File
@@ -28,7 +28,13 @@ import { useAtomValue, useStore } from "jotai";
import { draggingIdsFamily, focusIdsFamily, hoveredParentFamily, selectedIdsFamily } from "./atoms";
import { type CollapsedAtom, CollapsedAtomContext } from "./context";
import type { ContextMenuRenderer, TreeNode } from "./common";
import { closestVisibleNode, equalSubtree, getSelectedItems, hasAncestor } from "./common";
import {
closestVisibleNode,
equalSubtree,
getSelectedItems,
hasAncestor,
tabbableSelection,
} from "./common";
import { TreeDragOverlay } from "./TreeDragOverlay";
import type { TreeItemClickEvent, TreeItemHandle, TreeItemProps } from "./TreeItem";
import type { TreeItemListProps } from "./TreeItemList";
@@ -222,9 +228,12 @@ function TreeInner<T extends { id: string }>(
}
const closest = closestVisibleNode(store, collapsedAtom, lastSelectedItem.node);
if (closest != null) {
if (closest != null && lastSelectedId != null) {
const id = closest.item.id;
store.set(selectedIdsFamily(treeId), [id]);
const selected = store.get(selectedIdsFamily(treeId));
const next = tabbableSelection(selected, lastSelectedId, id);
if (next == null) return;
store.set(selectedIdsFamily(treeId), next);
store.set(focusIdsFamily(treeId), { anchorId: id, lastId: id });
}
}, [selectableItems, treeId]);
@@ -0,0 +1,19 @@
import { describe, expect, test } from "vite-plus/test";
import { tabbableSelection } from "./common";
describe("tabbableSelection", () => {
test("leaves several selected rows alone while the last one focused is in view", () => {
// As the tree renders again, say for new counts, the selection stands.
expect(tabbableSelection(["a", "b", "c"], "b", "b")).toBeNull();
expect(tabbableSelection(["b"], "b", "b")).toBeNull();
});
test("moves to the closest row in view once the last one focused is hidden", () => {
expect(tabbableSelection(["a", "child"], "child", "parent")).toEqual(["parent"]);
});
test("selects the last row focused when the selection no longer holds it", () => {
expect(tabbableSelection([], "b", "b")).toEqual(["b"]);
expect(tabbableSelection(["a"], "b", "b")).toEqual(["b"]);
});
});
+14
View File
@@ -85,6 +85,20 @@ export function isVisibleNode<T extends { id: string }>(
return true;
}
/**
* The selection that keeps a row tabbable, from the last row focused and the closest of it still
* in view, or null to leave the selection as it is: while that row is in view and selected, a
* selection of several rows stands, rather than shrinking to it each time the tree renders.
*/
export function tabbableSelection(
selected: readonly string[],
lastId: string,
closestId: string,
): string[] | null {
if (closestId === lastId && selected.includes(lastId)) return null;
return [closestId];
}
export function closestVisibleNode<T extends { id: string }>(
store: JotaiStore,
collapsedAtom: CollapsedAtom,