Compare commits

...
Author SHA1 Message Date
l0ng-ai 46c89db926 fix(hierarchy): let the hierarchy tab be closed
The Hierarchy tool window's content tab had no close button, so a type or
call hierarchy stayed until another one replaced it. The tab is closable
now; closing it clears the tree and hides the tool window, which has no
other content.

Refs #2471
2026-11-10 23:32:42 +08:00
3 changed files with 21 additions and 2 deletions

No files matched your search

+3 -1
View File
@@ -17,6 +17,7 @@ import {
} from "@/ui";
import { openLocation } from "./ipc";
import {
closeHierarchy,
ROOT_ID,
directionLabel,
hierarchyTitle,
@@ -64,9 +65,10 @@ export function HierarchyTabs() {
variant="compact"
className={styles.tabs}
aria-label="Hierarchies"
items={[{ id: "current", label }]}
items={[{ id: "current", label, closable: true }]}
activeId="current"
onSelect={() => undefined}
onClose={closeHierarchy}
/>
);
}
+12 -1
View File
@@ -2,9 +2,10 @@ import { describe, expect, it, vi } from "vitest";
import type { HierarchyItem, OutlineItem, ReferencesIncomplete, SymbolKind } from "@/bindings";
const hint = vi.fn();
const hide = vi.hoisted(() => vi.fn());
vi.mock("@/workbench/contributions", async (orig) => ({
...(await orig<typeof import("@/workbench/contributions")>()),
toolWindowService: () => ({ show: () => undefined }),
toolWindowService: () => ({ show: () => undefined, hide }),
}));
const range = (l1: number, c1: number, l2: number, c2: number) => ({
@@ -167,3 +168,13 @@ describe("hierarchy", () => {
}
});
});
describe("closing the hierarchy tab", () => {
it("clears the tree and hides the tool window", async () => {
const { closeHierarchy, useHierarchy } = await import("./hierarchy");
useHierarchy.setState({ root: { name: "Number", path: "/p/Number.java", line: 0, col: 0 } as never });
closeHierarchy();
expect(useHierarchy.getState().root).toBeNull();
expect(hide).toHaveBeenCalledWith("hierarchy");
});
});
+6
View File
@@ -73,6 +73,12 @@ export function resetHierarchy() {
}));
}
/** Closes the hierarchy's content tab; with no content left the tool window hides. */
export function closeHierarchy() {
resetHierarchy();
toolWindowService().hide("hierarchy");
}
/** The empty-result line of the hierarchy tree. */
export function noneFoundLabel(mode: HierarchyMode, direction: HierarchyDirection): string {
if (mode === "call") return direction === "incoming" ? tx`— no callers found` : tx`— no callees found`;