fix(project): keep attachments in the current project (#2320)

Attach adds a trusted folder to the current project without reopening it or moving its root. Attachments live in the primary project's private .openidea/workspace.json, and detaching the last one restores a plain project.

ProjectInfo.name stays the primary project's name; displayName supplies window titles, project tabs and Recent Projects. Attach is no longer a remembered opening policy, and File > Attach Project is available when the policy is not Ask. Attached folders must be trusted, and Restricted Mode names any attached folder that blocks trust. Explicit workspaces keep their behaviour and still cannot be created in or inside a linked project.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-09 19:23:05 +08:00
1 джерело 023c3f36c2
коміт 1ae8572021
60 files changed
+1155 -233

No files matched your search

+18 -6
Переглянути файл
@@ -216,7 +216,7 @@ describe("EditorController", () => {
expect(pane().tabs.map((t) => t.input.path)).toEqual(["/p/a.ts", "/p/c.ts"]);
});
it("carries the plain project's editor tabs into its automatic workspace", async () => {
it("keeps editor tabs and unsaved documents through attach and detach", async () => {
const settings = {};
useProject.setState({
project: { root: "/attach-a", name: "A", trusted: true, isGit: false, settings },
@@ -227,19 +227,31 @@ describe("EditorController", () => {
ctrl.start();
await ctrl.openFile("/attach-a/one.txt", { focus: false, preview: false });
await ctrl.openFile("/attach-a/two.txt", { focus: false, preview: false });
const slot = ctrl.activeSlot!;
const host = document.createElement("div");
const view = slot.mount(host);
ctrl.onMounted(slot);
view.dispatch({ changes: { from: 0, insert: "unsaved " }, userEvent: "input.type" });
const tabs = useTabs.getState();
useProject.setState({
project: {
root: "/attach-workspace",
name: "A",
root: "/attach-a",
name: "A, attach-b",
trusted: true,
isGit: false,
settings,
workspace: { version: 1, name: "A", projects: ["/attach-a", "/attach-b"] },
},
});
await vi.waitFor(() =>
expect(openFilePaths(useTabs.getState())).toEqual(["/attach-a/one.txt", "/attach-a/two.txt"]),
);
expect(useTabs.getState()).toBe(tabs);
expect(ctrl.activeSlot).toBe(slot);
expect(view.state.doc.toString()).toContain("unsaved ");
expect(openFilePaths(useTabs.getState())).toEqual(["/attach-a/one.txt", "/attach-a/two.txt"]);
useProject.setState({ project: { root: "/attach-a", name: "A", trusted: true, isGit: false, settings } });
expect(useTabs.getState()).toBe(tabs);
expect(ctrl.activeSlot).toBe(slot);
expect(view.state.doc.toString()).toContain("unsaved ");
host.remove();
useProject.setState({ project: null });
});
-9
Переглянути файл
@@ -307,15 +307,6 @@ export class EditorController implements SlotHost {
prevRoot = root;
prevLight = s.lightEdit;
this.saveSession();
if (
root &&
previous.project &&
!previous.project.workspace &&
s.project?.workspace?.projects[0] === previous.project.root
) {
const session = loadSession(previous.project.root);
if (session) storeSession(root, session);
}
this.sessionRoot = null;
const generation = ++this.projectGeneration;
const documents = customDocuments(useTabs.getState(), useContributions.getState().editorKinds);