дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-16 22:55:42 +02:00
Порівняти коміти
1
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
ad734491a3 |
No files matched your search
@@ -303,6 +303,6 @@ describe("closing the hierarchy tab", () => {
|
||||
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");
|
||||
expect(hide).toHaveBeenCalledWith("hierarchy", { removeFromStripe: true });
|
||||
});
|
||||
});
|
||||
@@ -92,10 +92,10 @@ export function resetHierarchy() {
|
||||
}));
|
||||
}
|
||||
|
||||
/** Closes the hierarchy's content tab; with no content left the tool window hides. */
|
||||
/** Closes the hierarchy's content tab; with no content left the tool window and its stripe button go. */
|
||||
export function closeHierarchy() {
|
||||
resetHierarchy();
|
||||
toolWindowService().hide("hierarchy");
|
||||
toolWindowService().hide("hierarchy", { removeFromStripe: true });
|
||||
}
|
||||
|
||||
/** The empty-result line of the hierarchy tree. */
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const show = vi.fn();
|
||||
const hide = vi.fn();
|
||||
vi.mock("@/workbench/contributions", async (orig) => ({
|
||||
...(await orig<typeof import("@/workbench/contributions")>()),
|
||||
toolWindowService: () => ({ show }),
|
||||
toolWindowService: () => ({ show, hide }),
|
||||
}));
|
||||
/** The editor at the caret (`null`: a search from outside an editor). */
|
||||
let caretView: import("@codemirror/view").EditorView | null = null;
|
||||
@@ -35,8 +36,16 @@ vi.mock("@tauri-apps/api/core", async (orig) => ({
|
||||
|
||||
const { registerDocumentIndexSync } = await import("@/workbench/contributions");
|
||||
|
||||
const { activeUsageSearch, findUsages, openUsageTab, pinUsageTab, resetUsages, showUsageResults, useUsages } =
|
||||
await import("./usages");
|
||||
const {
|
||||
activeUsageSearch,
|
||||
closeUsageTab,
|
||||
findUsages,
|
||||
openUsageTab,
|
||||
pinUsageTab,
|
||||
resetUsages,
|
||||
showUsageResults,
|
||||
useUsages,
|
||||
} = await import("./usages");
|
||||
|
||||
describe("showUsageResults", () => {
|
||||
it("shows given usages in the Find Usages tool window", async () => {
|
||||
@@ -221,4 +230,16 @@ describe("usage tabs", () => {
|
||||
openUsageTab(search(104));
|
||||
expect(useUsages.getState().tabs.map((t) => t.id)).toEqual([102, 104]);
|
||||
});
|
||||
|
||||
it("take the tool window and its stripe button away with the last one", () => {
|
||||
resetUsages();
|
||||
hide.mockClear();
|
||||
openUsageTab(search(201));
|
||||
pinUsageTab(201, true);
|
||||
openUsageTab(search(202));
|
||||
closeUsageTab(201);
|
||||
expect(hide).not.toHaveBeenCalled();
|
||||
closeUsageTab(202);
|
||||
expect(hide).toHaveBeenCalledWith("usages", { removeFromStripe: true });
|
||||
});
|
||||
});
|
||||
@@ -168,6 +168,14 @@ export function closeUsageTab(id: number) {
|
||||
const active = s.active === id ? (tabs[Math.min(i, tabs.length - 1)]?.id ?? null) : s.active;
|
||||
return { tabs, active };
|
||||
});
|
||||
// As in IDEA, the tool window and its stripe button go away with its last tab.
|
||||
if (!useUsages.getState().tabs.length) {
|
||||
try {
|
||||
toolWindowService().hide("usages", { removeFromStripe: true });
|
||||
} catch {
|
||||
// Workbench not ready (tests).
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Rerun of the selected tab (⌘R in the Find Usages tool window). */
|
||||
|
||||
@@ -15,5 +15,5 @@ it("hides the Debug tool window once its last session tab is closed", async () =
|
||||
expect(await closeSessionTab(1)).toBe(true);
|
||||
expect(hide).not.toHaveBeenCalled();
|
||||
expect(await closeSessionTab(2)).toBe(true);
|
||||
expect(hide).toHaveBeenCalledWith("debug");
|
||||
expect(hide).toHaveBeenCalledWith("debug", { removeFromStripe: true });
|
||||
});
|
||||
@@ -880,10 +880,10 @@ export async function closeSessionTab(id: DebugSessionId): Promise<boolean> {
|
||||
await stopSession(s.id);
|
||||
}
|
||||
removeSession(s.id);
|
||||
// As in IDEA, the tool window goes away with its last tab.
|
||||
// As in IDEA, the tool window and its stripe button go away with its last tab.
|
||||
if (!Object.keys(useDebug.getState().sessions).length) {
|
||||
try {
|
||||
toolWindowService().hide("debug");
|
||||
toolWindowService().hide("debug", { removeFromStripe: true });
|
||||
} catch {
|
||||
// Workbench not ready (tests).
|
||||
}
|
||||
|
||||
@@ -303,7 +303,8 @@ function currentTab(
|
||||
export async function closeRunTab(id: string, traces: readonly StackTraceTab[]) {
|
||||
if (traces.some((t) => t.id === id)) closeStackTrace(id);
|
||||
else if (!(await closeSessionTab(id))) return;
|
||||
if (!useRun.getState().sessions.length && !useStackTraces.getState().tabs.length) toolWindowService().hide("run");
|
||||
if (!useRun.getState().sessions.length && !useStackTraces.getState().tabs.length)
|
||||
toolWindowService().hide("run", { removeFromStripe: true });
|
||||
}
|
||||
|
||||
/** Session (and stack trace) tabs in the tool window header. */
|
||||
|
||||
@@ -24,5 +24,5 @@ it("hides the Run tool window once its last tab is closed", async () => {
|
||||
await closeRunTab("t", useStackTraces.getState().tabs);
|
||||
expect(hide).not.toHaveBeenCalled();
|
||||
await closeRunTab("b", useStackTraces.getState().tabs);
|
||||
expect(hide).toHaveBeenCalledWith("run");
|
||||
expect(hide).toHaveBeenCalledWith("run", { removeFromStripe: true });
|
||||
});
|
||||
@@ -1,8 +1,10 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { provideToolWindowService, type ToolWindowService } from "@/workbench/contributions";
|
||||
import type { FileMatches, SearchQuery } from "@/platform/ipc";
|
||||
import { buildFindTree } from "../find/FindToolWindow";
|
||||
import type { FindDeps } from "../find/session";
|
||||
import {
|
||||
closeFindTab,
|
||||
disposeFindWindow,
|
||||
openEditorResults,
|
||||
openInFindWindow,
|
||||
@@ -38,6 +40,18 @@ const file = (rel: string): FileMatches => ({
|
||||
afterEach(disposeFindWindow);
|
||||
|
||||
describe("Find tool window tabs", () => {
|
||||
it("take the tool window and its stripe button away with the last one", () => {
|
||||
const hide = vi.fn();
|
||||
provideToolWindowService({ show: vi.fn(), hide } as unknown as ToolWindowService);
|
||||
const a = openInFindWindow(q("a"), "a", { deps });
|
||||
pinFindTab(a, true);
|
||||
const b = openInFindWindow(q("b"), "b", { deps });
|
||||
closeFindTab(a);
|
||||
expect(hide).not.toHaveBeenCalled();
|
||||
closeFindTab(b);
|
||||
expect(hide).toHaveBeenCalledWith("find", { removeFromStripe: true });
|
||||
});
|
||||
|
||||
it("reuses the selected tab unless it is pinned", () => {
|
||||
const a = openInFindWindow(q("a"), "a", { deps });
|
||||
const b = openInFindWindow(q("b"), "b", { deps });
|
||||
|
||||
@@ -134,6 +134,8 @@ export function closeFindTab(id: number) {
|
||||
const active = s.active === id ? (tabs[Math.min(i, tabs.length - 1)]?.id ?? null) : s.active;
|
||||
return { tabs, active };
|
||||
});
|
||||
// As in IDEA, the tool window and its stripe button go away with its last tab.
|
||||
if (!useFindWindow.getState().tabs.length) maybeToolWindowService()?.hide("find", { removeFromStripe: true });
|
||||
}
|
||||
|
||||
export function disposeFindWindow() {
|
||||
|
||||
@@ -709,7 +709,11 @@ export interface EditorCloseSession {
|
||||
|
||||
export interface ToolWindowService {
|
||||
show(id: string, focus?: boolean): void;
|
||||
hide(id: string): void;
|
||||
/**
|
||||
* `removeFromStripe`: a window whose content is its tabs (Find, Run, Hierarchy…) lost its last
|
||||
* one: its stripe button goes too, until new content opens it again (IDEA).
|
||||
*/
|
||||
hide(id: string, options?: { removeFromStripe?: boolean }): void;
|
||||
toggle(id: string): void;
|
||||
isVisible(id: string): boolean;
|
||||
}
|
||||
|
||||
@@ -476,6 +476,19 @@ describe("stripe buttons", () => {
|
||||
resetToolWindowPlacements();
|
||||
expect(buttons()).toEqual({});
|
||||
});
|
||||
|
||||
it("drops the button of a window that lost its last tab until new content opens it", () => {
|
||||
disposers.push(registerToolWindow(find));
|
||||
showToolWindow("find");
|
||||
toolWindowServiceImpl.hide("find");
|
||||
expect(hasStripeButton(find, buttons())).toBe(true);
|
||||
showToolWindow("find");
|
||||
toolWindowServiceImpl.hide("find", { removeFromStripe: true });
|
||||
expect(isToolWindowVisible("find")).toBe(false);
|
||||
expect(hasStripeButton(find, buttons())).toBe(false);
|
||||
showToolWindow("find");
|
||||
expect(hasStripeButton(find, buttons())).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("view modes", () => {
|
||||
|
||||
@@ -742,7 +742,7 @@ function isFocusWithinToolWindow(id: string): boolean {
|
||||
|
||||
export const toolWindowServiceImpl: ToolWindowService = {
|
||||
show: (id, focus) => showToolWindow(id, focus),
|
||||
hide: hideToolWindow,
|
||||
hide: (id, options) => (options?.removeFromStripe ? removeFromStripe(id) : hideToolWindow(id)),
|
||||
toggle: toggleToolWindow,
|
||||
isVisible: isToolWindowVisible,
|
||||
};
|
||||
|
||||
Reference in new issue
Заблокувати користувача