mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
Open in New Window on a project file's tab now opens an editor-only window (editor-<parent>-n) instead of a second project workbench. It shares the parent's documents and language servers; unsaved text, caret and selection move with the tab, and the source tab is removed only after the new window reports ready. Files outside the project keep opening a full window. Review changes: closing the window settles only its own unsaved files (the project window's guard also asked to terminate running processes); Escape no longer closes it; error messages go through the text catalog; the window has its own stylesheet. Closes #4117 Co-authored-by: GGVidal <52431033+GGVidal@users.noreply.github.com>
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { getCurrentWindow } from "@tauri-apps/api/window";
|
|
import { EDITOR_READY, type EditorReadyResult } from "@/platform/auxWindow";
|
|
import { tx } from "@/platform/i18n";
|
|
import { call, commands, type EditorLaunch } from "@/platform/ipc";
|
|
|
|
const READY_MS = 30_000;
|
|
|
|
/** Opens a project-file aux editor and resolves once it has taken over the document. */
|
|
export async function openLightweightEditor(launch: EditorLaunch, background: string | null): Promise<void> {
|
|
const parent = getCurrentWindow();
|
|
let off: (() => void) | undefined;
|
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
try {
|
|
await new Promise<void>((resolve, reject) => {
|
|
timer = setTimeout(() => reject(new Error(tx("Timed out opening the editor window"))), READY_MS);
|
|
void parent
|
|
.listen<EditorReadyResult>(EDITOR_READY, ({ payload }) => {
|
|
if (payload.path && payload.path !== launch.path) return;
|
|
if (payload.ok) resolve();
|
|
else reject(new Error(payload.error || tx("Could not open the editor window")));
|
|
})
|
|
.then((unlisten) => {
|
|
off = unlisten;
|
|
return call(commands.windowOpenEditor(launch, background));
|
|
})
|
|
.catch(reject);
|
|
});
|
|
} finally {
|
|
if (timer) clearTimeout(timer);
|
|
off?.();
|
|
}
|
|
}
|