дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
fix(vcs): let the branch tree collapse and expand while searching (#7471)
In Git > Log > Branches, folder arrows, Expand All and Collapse All did nothing while a search was active. A new search still shows every match expanded, but the user can now collapse and expand within it; clearing the search restores the expansion from before. Fixes #7438 Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
099bb57abd
коміт
ad0a755f07
2 files changed
+64
-6
No files matched your search
@@ -129,6 +129,56 @@ describe("Git Log branches pane", () => {
|
||||
expect(screen.getByText("feature")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe("while searching", () => {
|
||||
const remotes = ["bugfix", "develop", "smoke"].map((n) => b(`origin/stable/sp4/${n}`, { remote: true }));
|
||||
const search = (value: string) =>
|
||||
fireEvent.change(screen.getByLabelText("Filter branches and tags"), { target: { value } });
|
||||
const toggle = (label: string, key: "ArrowLeft" | "ArrowRight") => {
|
||||
fireEvent.mouseDown(screen.getByText(label));
|
||||
fireEvent.keyDown(screen.getByRole("tree", { name: "Branches" }), { key });
|
||||
};
|
||||
beforeEach(() => useVcs.setState({ branches: [...branches, ...remotes] }));
|
||||
|
||||
it("collapses and expands a matched folder", () => {
|
||||
render(<BranchesPanel />);
|
||||
search("sp4/");
|
||||
expect(screen.getByText("bugfix")).toBeInTheDocument();
|
||||
toggle("sp4", "ArrowLeft");
|
||||
expect(screen.queryByText("bugfix")).toBeNull();
|
||||
toggle("sp4", "ArrowRight");
|
||||
expect(screen.getByText("bugfix")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("expands every match again when the search changes", () => {
|
||||
render(<BranchesPanel />);
|
||||
search("sp4/");
|
||||
toggle("sp4", "ArrowLeft");
|
||||
search("sp4/b");
|
||||
expect(screen.getByText("bugfix")).toBeInTheDocument();
|
||||
search("sp4/");
|
||||
expect(screen.getByText("bugfix")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("puts back the expansion from before the search when it is cleared", () => {
|
||||
render(<BranchesPanel />);
|
||||
toggle("Local", "ArrowLeft");
|
||||
expect(screen.queryByText("feature")).toBeNull();
|
||||
search("sp4/");
|
||||
toggle("sp4", "ArrowLeft");
|
||||
search("");
|
||||
expect(screen.queryByText("feature")).toBeNull();
|
||||
});
|
||||
|
||||
it("collapses and expands every group from the toolbar", () => {
|
||||
render(<BranchesPanel />);
|
||||
search("sp4/");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Collapse All" }));
|
||||
expect(screen.queryByText("bugfix")).toBeNull();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Expand All" }));
|
||||
expect(screen.getByText("bugfix")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("binds Expand All / Collapse All to the primary modifier with plus and minus", () => {
|
||||
render(<BranchesPanel />);
|
||||
const tree = screen.getByRole("tree", { name: "Branches" });
|
||||
|
||||
@@ -229,8 +229,16 @@ export function BranchesPanel() {
|
||||
lines,
|
||||
]);
|
||||
const roots = useMemo(() => filterBranchTree(allRoots, query), [allRoots, query]);
|
||||
// While searching every match is shown expanded.
|
||||
const searchExpanded = useMemo(() => (query.trim() ? new Set(branchGroupKeys(roots)) : undefined), [roots, query]);
|
||||
// A new search shows every match expanded; within that search the user can still collapse and
|
||||
// expand (IDEA), and clearing it brings back the expansion from before the search.
|
||||
const allMatches = useMemo(() => (query.trim() ? new Set(branchGroupKeys(roots)) : undefined), [roots, query]);
|
||||
const [searchKeys, setSearchKeys] = useState<ReadonlySet<string>>();
|
||||
const searchExpanded = allMatches && (searchKeys ?? allMatches);
|
||||
const setExpanded = (keys: ReadonlySet<string>) => (allMatches ? setSearchKeys(keys) : setExpandedKeys(keys));
|
||||
const search = (next: string) => {
|
||||
setQuery(next);
|
||||
setSearchKeys(undefined);
|
||||
};
|
||||
const defaultExpanded = useMemo(
|
||||
() => [
|
||||
...branchGroupKeys(allRoots),
|
||||
@@ -320,7 +328,7 @@ export function BranchesPanel() {
|
||||
// The selected branch in each repository it was picked in (a merged branch: all of them).
|
||||
const favoriteTargets = targets.filter((t) => t.branch && t.ref === target?.ref);
|
||||
const favorite = favoriteTargets.some((t) => isFavoriteBranch(t.branch!, favoritesOf(t.repo)));
|
||||
const expandAll = () => setExpandedKeys(new Set(expandable.keys));
|
||||
const expandAll = () => setExpanded(new Set(expandable.keys));
|
||||
// Collapse All keeps the selected rows reachable: their ancestors stay open, so the selection
|
||||
// does not end up inside a collapsed group.
|
||||
const collapseAll = () => {
|
||||
@@ -328,7 +336,7 @@ export function BranchesPanel() {
|
||||
for (const key of selected) {
|
||||
for (let parent = expandable.parents.get(key); parent; parent = expandable.parents.get(parent)) keep.add(parent);
|
||||
}
|
||||
setExpandedKeys(keep);
|
||||
setExpanded(keep);
|
||||
};
|
||||
const onKeyDownCapture = (e: KeyboardEvent<HTMLDivElement>) => {
|
||||
// Expand All / Collapse All while the branch tree has focus: ⌘+ / ⌘-, and on Windows and
|
||||
@@ -427,7 +435,7 @@ export function BranchesPanel() {
|
||||
<SearchField
|
||||
className={styles.branchSearch}
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
onChange={search}
|
||||
placeholder="Branch or tag"
|
||||
aria-label="Filter branches and tags"
|
||||
/>
|
||||
@@ -441,7 +449,7 @@ export function BranchesPanel() {
|
||||
isExpandable={(n) => !!n.children}
|
||||
defaultExpanded={defaultExpanded}
|
||||
expanded={searchExpanded ?? expandedKeys}
|
||||
onExpandedChange={(next) => setExpandedKeys(next)}
|
||||
onExpandedChange={setExpanded}
|
||||
getIcon={(n) =>
|
||||
n.kind === "head"
|
||||
? "commit"
|
||||
|
||||
Reference in new issue
Заблокувати користувача