дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
Порівняти коміти
5
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
c1fc9624ce | ||
|
|
3de33f21d3 | ||
|
|
4e8a392fed | ||
|
|
7c3b40b1c4 | ||
|
|
38279f3c29 |
No files matched your search
@@ -0,0 +1,41 @@
|
||||
name: Cancel runs of closed PRs
|
||||
on:
|
||||
# pull_request_target so it also runs for PRs from forks. It never checks out or
|
||||
# runs PR code: it only lists and cancels workflow runs of the closed PR's branch.
|
||||
pull_request_target:
|
||||
types: [closed]
|
||||
|
||||
permissions:
|
||||
actions: write
|
||||
|
||||
jobs:
|
||||
cancel:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/github-script@v8
|
||||
with:
|
||||
script: |
|
||||
// A merged or closed PR's remaining CI only holds runners other PRs wait for.
|
||||
const pr = context.payload.pull_request;
|
||||
const { owner, repo } = context.repo;
|
||||
const headRepo = pr.head.repo?.full_name;
|
||||
// The API's status filter lags behind new runs: list the branch and check each one.
|
||||
const runs = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, {
|
||||
owner,
|
||||
repo,
|
||||
branch: pr.head.ref,
|
||||
per_page: 100,
|
||||
});
|
||||
let cancelled = 0;
|
||||
for (const run of runs) {
|
||||
if (run.id === context.runId || run.status === 'completed') continue;
|
||||
if (run.head_repository?.full_name !== headRepo) continue;
|
||||
if (!['pull_request', 'pull_request_target'].includes(run.event)) continue;
|
||||
try {
|
||||
await github.rest.actions.cancelWorkflowRun({ owner, repo, run_id: run.id });
|
||||
cancelled++;
|
||||
} catch (e) {
|
||||
core.warning(`run ${run.id}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
core.info(`Cancelled ${cancelled} run(s) of #${pr.number}`);
|
||||
@@ -5,6 +5,7 @@ on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
types: [opened, synchronize, reopened]
|
||||
merge_group:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
@@ -12,8 +13,9 @@ permissions:
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.ref }}
|
||||
# A newer push supersedes the run in progress, on main too.
|
||||
cancel-in-progress: true
|
||||
# A newer push supersedes a pull request's run in progress. Runs on main and in the merge
|
||||
# queue finish, so a broken main shows up and the queue's required checks report.
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -23,7 +25,7 @@ env:
|
||||
|
||||
jobs:
|
||||
# Which parts a pull request touches, so jobs it can't affect skip and leave the
|
||||
# shared runners to others. Pushes and manual runs always run everything.
|
||||
# shared runners to others. Pushes, the merge queue and manual runs always run everything.
|
||||
changes:
|
||||
name: Changes
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main", "project-*", "settings-*", "comparison-*", "diff-*", "deployment-*"],
|
||||
"windows": ["main", "project-*", "settings-*", "comparison-*", "diff-*", "editor-*", "deployment-*"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"core:window:allow-start-dragging",
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "e2e-bridge",
|
||||
"description": "Debug-only automation bridge",
|
||||
"windows": ["main", "project-*", "settings-*", "comparison-*", "diff-*", "deployment-*"],
|
||||
"windows": ["main", "project-*", "settings-*", "comparison-*", "diff-*", "editor-*", "deployment-*"],
|
||||
"permissions": ["mcp-bridge:default"]
|
||||
}
|
||||
@@ -123,6 +123,20 @@ pub async fn window_open_diff(
|
||||
windows::open_diff_window(&app, &window, diff, background)
|
||||
}
|
||||
|
||||
/// Opens a lightweight editor window for `editor` next to this project window ("Open in New Window").
|
||||
/// `background` (`#rrggbb`) paints it until its page has loaded.
|
||||
#[desktop_command(trust = always)]
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn window_open_editor(
|
||||
app: AppHandle,
|
||||
window: WebviewWindow,
|
||||
editor: windows::EditorLaunch,
|
||||
background: Option<String>,
|
||||
) -> IdeResult<()> {
|
||||
windows::open_editor_window(&app, &window, editor, background)
|
||||
}
|
||||
|
||||
/// Opens this window's Sync with Deployed window comparing `paths` with `server` (or hands them
|
||||
/// to the open one). `background` (`#rrggbb`) paints a new window until its page has loaded.
|
||||
#[desktop_command(trust = always)]
|
||||
@@ -928,6 +942,7 @@ ide_command::desktop_domain!(
|
||||
window_open_comparison,
|
||||
window_open_deployment,
|
||||
window_open_diff,
|
||||
window_open_editor,
|
||||
window_open_file_in_new_window,
|
||||
window_open_files,
|
||||
window_open_project,
|
||||
|
||||
@@ -41,6 +41,8 @@ const COMPARISON_SIZE: (f64, f64) = (1100.0, 720.0);
|
||||
const COMPARISON_MIN_SIZE: (f64, f64) = (640.0, 360.0);
|
||||
const DIFF_SIZE: (f64, f64) = (1100.0, 720.0);
|
||||
const DIFF_MIN_SIZE: (f64, f64) = (640.0, 360.0);
|
||||
const EDITOR_SIZE: (f64, f64) = (1100.0, 720.0);
|
||||
const EDITOR_MIN_SIZE: (f64, f64) = (640.0, 360.0);
|
||||
const DEPLOYMENT_SIZE: (f64, f64) = (1400.0, 900.0);
|
||||
const DEPLOYMENT_MIN_SIZE: (f64, f64) = (800.0, 500.0);
|
||||
|
||||
@@ -77,6 +79,24 @@ pub struct Launch {
|
||||
/// Deployment windows: the server and local selection to compare.
|
||||
#[serde(default)]
|
||||
pub deployment: Option<DeploymentLaunch>,
|
||||
/// Editor windows: the file to show (Open in New Window → lightweight aux editor).
|
||||
#[serde(default)]
|
||||
pub editor: Option<Box<EditorLaunch>>,
|
||||
}
|
||||
|
||||
/// A file opened in a lightweight editor window, with optional caret / selection (0-based).
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EditorLaunch {
|
||||
pub path: ide_core::IpcPath,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub line: Option<u32>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub column: Option<u32>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub end_line: Option<u32>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub end_column: Option<u32>,
|
||||
}
|
||||
|
||||
/// Local files to compare with a deployment server (Sync with Deployed).
|
||||
@@ -352,11 +372,13 @@ pub enum AuxKind {
|
||||
Settings,
|
||||
Comparison,
|
||||
Diff,
|
||||
Editor,
|
||||
Deployment,
|
||||
}
|
||||
|
||||
impl AuxKind {
|
||||
const ALL: [AuxKind; 4] = [AuxKind::Settings, AuxKind::Comparison, AuxKind::Diff, AuxKind::Deployment];
|
||||
const ALL: [AuxKind; 5] =
|
||||
[AuxKind::Settings, AuxKind::Comparison, AuxKind::Diff, AuxKind::Editor, AuxKind::Deployment];
|
||||
|
||||
/// Label prefix, and the key of the one remembered geometry shared by every window of the kind.
|
||||
pub fn name(self) -> &'static str {
|
||||
@@ -364,13 +386,14 @@ impl AuxKind {
|
||||
AuxKind::Settings => "settings",
|
||||
AuxKind::Comparison => "comparison",
|
||||
AuxKind::Diff => "diff",
|
||||
AuxKind::Editor => "editor",
|
||||
AuxKind::Deployment => "deployment",
|
||||
}
|
||||
}
|
||||
|
||||
/// Several per project window (`<kind>-<parent>-<n>`), else one (`<kind>-<parent>`).
|
||||
fn multiple(self) -> bool {
|
||||
matches!(self, AuxKind::Comparison | AuxKind::Diff)
|
||||
matches!(self, AuxKind::Comparison | AuxKind::Diff | AuxKind::Editor)
|
||||
}
|
||||
|
||||
/// Shows the project's documents: gets its parent's events and edits made in sibling windows,
|
||||
@@ -394,6 +417,7 @@ impl AuxKind {
|
||||
AuxKind::Settings => SETTINGS_MIN_SIZE,
|
||||
AuxKind::Comparison => COMPARISON_MIN_SIZE,
|
||||
AuxKind::Diff => DIFF_MIN_SIZE,
|
||||
AuxKind::Editor => EDITOR_MIN_SIZE,
|
||||
AuxKind::Deployment => DEPLOYMENT_MIN_SIZE,
|
||||
}
|
||||
}
|
||||
@@ -403,6 +427,7 @@ impl AuxKind {
|
||||
AuxKind::Settings => SETTINGS_SIZE,
|
||||
AuxKind::Comparison => COMPARISON_SIZE,
|
||||
AuxKind::Diff => DIFF_SIZE,
|
||||
AuxKind::Editor => EDITOR_SIZE,
|
||||
AuxKind::Deployment => DEPLOYMENT_SIZE,
|
||||
}
|
||||
}
|
||||
@@ -1735,6 +1760,28 @@ pub fn open_diff_window(
|
||||
)
|
||||
}
|
||||
|
||||
/// Opens a lightweight editor window for `editor.path` ("Open in New Window"), sharing the
|
||||
/// parent's project documents and language servers.
|
||||
pub fn open_editor_window(
|
||||
app: &AppHandle,
|
||||
parent: &WebviewWindow,
|
||||
editor: EditorLaunch,
|
||||
background: Option<String>,
|
||||
) -> IdeResult<()> {
|
||||
open_auxiliary_window(
|
||||
app,
|
||||
parent,
|
||||
AuxWindow {
|
||||
kind: AuxKind::Editor,
|
||||
title: "Editor",
|
||||
size: AuxKind::Editor.default_size(),
|
||||
min_size: AuxKind::Editor.min_size(),
|
||||
launch: Launch { editor: Some(Box::new(editor)), ..Default::default() },
|
||||
background,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Opens (or focuses and hands over to) the project window's Sync with Deployed window: local
|
||||
/// files next to their copies on a deployment server, like IDEA's.
|
||||
pub fn open_deployment_window(
|
||||
@@ -2651,14 +2698,24 @@ mod tests {
|
||||
assert_eq!(auxiliary("settings-main"), Some((AuxKind::Settings, "main")));
|
||||
assert_eq!(auxiliary("comparison-project-2-14"), Some((AuxKind::Comparison, "project-2")));
|
||||
assert_eq!(auxiliary("diff-project-2-3"), Some((AuxKind::Diff, "project-2")));
|
||||
assert_eq!(auxiliary("editor-project-2-3"), Some((AuxKind::Editor, "project-2")));
|
||||
assert_eq!(auxiliary("deployment-project-2"), Some((AuxKind::Deployment, "project-2")));
|
||||
for label in ["main", "project-1", "comparison-main", "comparison-main-x", "settings-", "settingsmain"] {
|
||||
assert_eq!(auxiliary(label), None, "{label}");
|
||||
}
|
||||
assert_eq!(state_key("comparison-main-3"), "comparison");
|
||||
assert_eq!(state_key("diff-main-3"), "diff");
|
||||
assert_eq!(state_key("editor-main-3"), "editor");
|
||||
assert_eq!(state_key("project-3"), "project-3");
|
||||
let labels = ["comparison-main-0", "diff-main-1", "project-2", "main", "settings-main", "deployment-project-2"];
|
||||
let labels = [
|
||||
"comparison-main-0",
|
||||
"diff-main-1",
|
||||
"editor-main-2",
|
||||
"project-2",
|
||||
"main",
|
||||
"settings-main",
|
||||
"deployment-project-2",
|
||||
];
|
||||
assert_eq!(sorted_labels(labels.into_iter().filter(|l| auxiliary_parent(l).is_none())), ["main", "project-2"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -723,6 +723,7 @@ window_new always desktop bin
|
||||
window_open_comparison always desktop bindings async
|
||||
window_open_deployment always desktop bindings async
|
||||
window_open_diff always desktop bindings async
|
||||
window_open_editor always desktop bindings async
|
||||
window_open_file_in_new_window always desktop bindings async
|
||||
window_open_files always desktop bindings async
|
||||
window_open_project always desktop bindings async
|
||||
|
||||
@@ -20,6 +20,11 @@ export async function bootAuxiliaryWindow(aux: { kind: AuxKind; parent: string }
|
||||
mountWindowRoot(bootDiffWindow(aux.parent));
|
||||
return;
|
||||
}
|
||||
case "editor": {
|
||||
const { bootEditorWindow } = await import("./editorWindowBoot");
|
||||
mountWindowRoot(bootEditorWindow(aux.parent));
|
||||
return;
|
||||
}
|
||||
case "deployment": {
|
||||
const { bootDeploymentWindow } = await import("./deploymentWindowBoot");
|
||||
mountWindowRoot(bootDeploymentWindow(aux.parent));
|
||||
|
||||
@@ -1907,6 +1907,11 @@ export const commands = {
|
||||
* `background` (`#rrggbb`) paints it until its page has loaded.
|
||||
*/
|
||||
windowOpenDiff: (diff: DiffLaunch_Deserialize, background: string | null) => typedError<null, IdeError>(__TAURI_INVOKE("window_open_diff", { diff, background })),
|
||||
/**
|
||||
* Opens a lightweight editor window for `editor` next to this project window ("Open in New Window").
|
||||
* `background` (`#rrggbb`) paints it until its page has loaded.
|
||||
*/
|
||||
windowOpenEditor: (editor: EditorLaunch_Deserialize, background: string | null) => typedError<null, IdeError>(__TAURI_INVOKE("window_open_editor", { editor, background })),
|
||||
/**
|
||||
* Detaches an editor tab: opens `file` in a forced new window (`project`, None
|
||||
* for LightEdit, decided by the caller), bypassing the focus-an-existing-window
|
||||
@@ -1977,6 +1982,8 @@ export const commands = {
|
||||
diffBeforeFiles: boolean,
|
||||
/** Deployment windows: the server and local selection to compare. */
|
||||
deployment: DeploymentLaunch | null,
|
||||
/** Editor windows: the file to show (Open in New Window → lightweight aux editor). */
|
||||
editor: EditorLaunch_Serialize | null,
|
||||
} | null>("window_take_launch"),
|
||||
/**
|
||||
* Local bootstrap snapshot for a `settings-<parent>` window, avoiding a sequential
|
||||
@@ -5464,6 +5471,27 @@ export type EditorGeneralSettings = {
|
||||
richTextCopy?: boolean,
|
||||
};
|
||||
|
||||
/** A file opened in a lightweight editor window, with optional caret / selection (0-based). */
|
||||
export type EditorLaunch = EditorLaunch_Serialize | EditorLaunch_Deserialize;
|
||||
|
||||
/** A file opened in a lightweight editor window, with optional caret / selection (0-based). */
|
||||
export type EditorLaunch_Deserialize = {
|
||||
path: IpcPath,
|
||||
line?: number | null,
|
||||
column?: number | null,
|
||||
endLine?: number | null,
|
||||
endColumn?: number | null,
|
||||
};
|
||||
|
||||
/** A file opened in a lightweight editor window, with optional caret / selection (0-based). */
|
||||
export type EditorLaunch_Serialize = {
|
||||
path: IpcPath,
|
||||
line?: number | null,
|
||||
column?: number | null,
|
||||
endLine?: number | null,
|
||||
endColumn?: number | null,
|
||||
};
|
||||
|
||||
export type EditorSettings = EditorSettings_Serialize | EditorSettings_Deserialize;
|
||||
|
||||
export type EditorSettings_Deserialize = {
|
||||
@@ -7780,6 +7808,8 @@ export type Launch_Deserialize = {
|
||||
diffBeforeFiles?: boolean,
|
||||
/** Deployment windows: the server and local selection to compare. */
|
||||
deployment?: DeploymentLaunch | null,
|
||||
/** Editor windows: the file to show (Open in New Window → lightweight aux editor). */
|
||||
editor?: EditorLaunch_Deserialize | null,
|
||||
};
|
||||
|
||||
/** What a freshly opened window should do once its frontend is up. */
|
||||
@@ -7809,6 +7839,8 @@ export type Launch_Serialize = {
|
||||
diffBeforeFiles: boolean,
|
||||
/** Deployment windows: the server and local selection to compare. */
|
||||
deployment: DeploymentLaunch | null,
|
||||
/** Editor windows: the file to show (Open in New Window → lightweight aux editor). */
|
||||
editor: EditorLaunch_Serialize | null,
|
||||
};
|
||||
|
||||
/** One SDK or library with its source folders (`< Python 3.12 (.venv) >`). */
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
.window {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
background: var(--bg-app);
|
||||
color: var(--fg);
|
||||
}
|
||||
/* Linux: frameless X11 windows have no shadow, so mark the edge in CSS. */
|
||||
.edge {
|
||||
position: relative;
|
||||
}
|
||||
.edge::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 1;
|
||||
pointer-events: none;
|
||||
box-shadow: inset 0 0 0 1px var(--border-window);
|
||||
}
|
||||
.loading {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: var(--space-2);
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.error {
|
||||
padding: var(--space-4);
|
||||
color: var(--danger);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* Lightweight editor window (`editor-<parent>-<n>`): one project file in a window of its own
|
||||
* ("Open in New Window" without a second workbench).
|
||||
*/
|
||||
import clsx from "clsx";
|
||||
import { create } from "zustand";
|
||||
import { emitTo } from "@tauri-apps/api/event";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { AUX_CLOSED, EDITOR_READY, type AuxCloseResult, type EditorReadyResult } from "@/platform/auxWindow";
|
||||
import { setContext } from "@/platform/context";
|
||||
import { t, tx } from "@/platform/i18n";
|
||||
import { isImeKey } from "@/platform/ime";
|
||||
import { commands, type EditorLaunch } from "@/platform/ipc";
|
||||
import { basename, useProject } from "@/platform/project";
|
||||
import { restoreRemote } from "@/platform/remote";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
import { Spinner, T, isPopupOpen } from "@/ui";
|
||||
import { editorService, notifications } from "@/workbench/contributions";
|
||||
import { EditorArea } from "@/workbench/EditorArea";
|
||||
import { OverlayHost } from "@/workbench/OverlayHost";
|
||||
import { TitleBar } from "@/workbench/TitleBar";
|
||||
import { WindowResizeHandles } from "@/workbench/WindowResizeHandles";
|
||||
import { useApplyTheme } from "@/workbench/theme";
|
||||
import { ask } from "@/workbench/messages";
|
||||
import { editorController } from "./controller";
|
||||
import type { DocModel } from "./model/document";
|
||||
import styles from "./EditorWindow.module.css";
|
||||
|
||||
const useEditorWindow = create<{
|
||||
path: string | null;
|
||||
title: string;
|
||||
error: string | null;
|
||||
}>(() => ({ path: null, title: "", error: null }));
|
||||
|
||||
function showCaption(caption: string) {
|
||||
if (useEditorWindow.getState().title === caption) return;
|
||||
useEditorWindow.setState({ title: caption });
|
||||
void getCurrentWindow()
|
||||
.setTitle(caption)
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
async function reportReady(parent: string, result: Omit<EditorReadyResult, "label">) {
|
||||
const payload: EditorReadyResult = { label: getCurrentWindow().label, ...result };
|
||||
await emitTo(parent, EDITOR_READY, payload).catch((error) =>
|
||||
console.warn("cannot report editor window ready", error),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settles this window's unsaved files before it closes. Only its own documents count: the project
|
||||
* window keeps its processes and any copy of the same file it still has open.
|
||||
*/
|
||||
async function settleUnsaved(models: DocModel[], project: string | null): Promise<boolean> {
|
||||
const dirty = models.filter((model) => model.getMeta().dirty);
|
||||
if (dirty.length === 0) return true;
|
||||
if (useProject.getState().settings?.files?.autoSave !== false) {
|
||||
await Promise.all(dirty.map((model) => model.save("auto")));
|
||||
return true;
|
||||
}
|
||||
const answer = await ask({
|
||||
title: t("app.unsaved.title"),
|
||||
body: t("app.unsaved.body", { count: dirty.length, project: project ?? t("app.title.default") }),
|
||||
buttons: [
|
||||
{ id: "discard", label: t("app.unsaved.discard") },
|
||||
{ id: "save", label: t("app.unsaved.save"), primary: true },
|
||||
],
|
||||
icon: "warning",
|
||||
});
|
||||
if (answer.button === "save") await Promise.all(dirty.map((model) => model.save("explicit")));
|
||||
return answer.button === "save" || answer.button === "discard";
|
||||
}
|
||||
|
||||
/** Loads the launch's file into this window's editor. */
|
||||
export function activateEditorWindow(parent: string): () => void {
|
||||
let projectName: string | null = null;
|
||||
const native = getCurrentWindow();
|
||||
let disposed = false;
|
||||
let closing = false;
|
||||
let stopClose: (() => void) | undefined;
|
||||
void native
|
||||
.onCloseRequested(async (event) => {
|
||||
if (closing) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
closing = true;
|
||||
const models = [...editorController().manager.byId.values()];
|
||||
let closed = false;
|
||||
try {
|
||||
await Promise.all(models.map((model) => model.sync.whenIdle()));
|
||||
closed = await settleUnsaved(models, projectName);
|
||||
if (closed) {
|
||||
for (const model of models) model.dispose();
|
||||
await Promise.all(
|
||||
models.map((model) =>
|
||||
commands.docClose(model.doc).catch((error) => console.warn("cannot release editor document", error)),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
notifications().notify({ level: "error", title: tx("Could not close editor"), body: String(error) });
|
||||
} finally {
|
||||
if (!closed) event.preventDefault();
|
||||
const result: AuxCloseResult = {
|
||||
label: native.label,
|
||||
closed,
|
||||
documents: closed ? models.map((model) => model.doc) : [],
|
||||
};
|
||||
await emitTo(parent, AUX_CLOSED, result).catch((error) =>
|
||||
console.warn("cannot report editor window close", error),
|
||||
);
|
||||
closing = false;
|
||||
}
|
||||
})
|
||||
.then((off) => {
|
||||
if (disposed) off();
|
||||
else stopClose = off;
|
||||
});
|
||||
const onCloseShortcut = (event: KeyboardEvent) => {
|
||||
if (isImeKey(event) || isPopupOpen()) return;
|
||||
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "w") {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
void native.close();
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onCloseShortcut, true);
|
||||
void (async () => {
|
||||
let path = "";
|
||||
try {
|
||||
await restoreRemote();
|
||||
const launch = (await commands.windowTakeLaunch())?.editor as EditorLaunch | null | undefined;
|
||||
if (!launch?.path) throw new Error(tx("Missing editor request"));
|
||||
path = launch.path;
|
||||
const project = await commands.projectCurrent();
|
||||
if (!project) throw new Error(tx("The editor’s project is no longer open"));
|
||||
projectName = project.name;
|
||||
// Settings only: restoring the project's editor session here would overwrite the main window's tabs.
|
||||
useProject.setState({ settings: project.settings });
|
||||
setContext("projectOpen", true);
|
||||
const selection =
|
||||
launch.line != null && launch.column != null
|
||||
? {
|
||||
line: launch.line,
|
||||
col: launch.column,
|
||||
...(launch.endLine != null ? { endLine: launch.endLine, endCol: launch.endColumn ?? 0 } : {}),
|
||||
}
|
||||
: undefined;
|
||||
await editorService().openFile(path, { focus: true, selection });
|
||||
useEditorWindow.setState({ path });
|
||||
showCaption(`${project.name} — ${basename(path)}`);
|
||||
await reportReady(parent, { path, ok: true });
|
||||
} catch (error) {
|
||||
const message = String(error);
|
||||
useEditorWindow.setState({ error: message });
|
||||
await reportReady(parent, { path, ok: false, error: message });
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
disposed = true;
|
||||
stopClose?.();
|
||||
window.removeEventListener("keydown", onCloseShortcut, true);
|
||||
};
|
||||
}
|
||||
|
||||
export function EditorWindow() {
|
||||
useApplyTheme();
|
||||
const { path, title, error } = useEditorWindow();
|
||||
const os = usePlatform((s) => s.os);
|
||||
const ownTitleBar = usePlatform((s) => s.overlayTitleBar || s.framelessTitleBar);
|
||||
return (
|
||||
<main className={clsx(styles.window, os === "linux" && styles.edge)}>
|
||||
{ownTitleBar && <TitleBar minimal dialog title={title} />}
|
||||
{error ? (
|
||||
<div className={styles.error} role="alert">
|
||||
{error}
|
||||
</div>
|
||||
) : !path ? (
|
||||
<div className={styles.loading} role="status">
|
||||
<Spinner />
|
||||
<T>Loading…</T>
|
||||
</div>
|
||||
) : (
|
||||
<div className={styles.body}>
|
||||
<EditorArea />
|
||||
</div>
|
||||
)}
|
||||
<OverlayHost />
|
||||
<WindowResizeHandles />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -47,7 +47,9 @@ import { useDistractionFree } from "@/workbench/distractionFree";
|
||||
import { restoreMaximizedToolWindow } from "@/workbench/toolwindows/store";
|
||||
import { ask, confirm } from "@/workbench/messages";
|
||||
import { t, tx } from "@/platform/i18n";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { call, commands, isTauri } from "@/platform/ipc";
|
||||
import { openLightweightEditor } from "./openLightweightEditor";
|
||||
import { windowBackgroundHex } from "@/workbench/theme";
|
||||
import { save as saveFileDialog, type DialogFilter as SaveDialogFilter } from "@/platform/dialog";
|
||||
import { isUntitledUri, untitledTitle } from "@/platform/virtualDocs";
|
||||
import { isRemoteWindow } from "@/platform/remote";
|
||||
@@ -1856,7 +1858,7 @@ export class EditorController implements SlotHost {
|
||||
changeSplitOrientation(paneId: string) {
|
||||
this.apply((s) => changeSplitOrientation(s, paneId));
|
||||
}
|
||||
/** Save or resolve the dirty guard, open the window, then remove the original tab. */
|
||||
/** Open a lightweight aux editor (or a full window outside the project), then remove the original tab. */
|
||||
async detachTab(paneId: string, tabId: string): Promise<boolean> {
|
||||
const tab = useTabs.getState().panes[paneId]?.tabs.find((t) => t.id === tabId);
|
||||
const path = tab?.input.path;
|
||||
@@ -1873,9 +1875,40 @@ export class EditorController implements SlotHost {
|
||||
const project = useProject.getState().project;
|
||||
const inProject =
|
||||
!!project && (project.workspace?.projects ?? [project.root]).some((root) => isSameOrInside(path, root));
|
||||
const light = inProject && isTextTab(tab) && isTauri();
|
||||
return this.removeGuarded((s) => (s.panes[paneId] ? closeTab(s, paneId, tabId) : s), {
|
||||
beforeRemove: async () => {
|
||||
if (!useTabs.getState().panes[paneId]?.tabs.some((t) => t.id === tabId)) return false;
|
||||
if (light) {
|
||||
const slot = await this.ensureSlot(tabId);
|
||||
if (!slot) return false;
|
||||
const state = slot.currentState();
|
||||
const main = state.selection.main;
|
||||
const from = state.doc.lineAt(main.from);
|
||||
const to = state.doc.lineAt(main.to);
|
||||
try {
|
||||
await openLightweightEditor(
|
||||
{
|
||||
path,
|
||||
line: from.number - 1,
|
||||
column: main.from - from.from,
|
||||
endLine: to.number - 1,
|
||||
endColumn: main.to - to.from,
|
||||
},
|
||||
windowBackgroundHex(),
|
||||
);
|
||||
slot.model.handoffRelease = true;
|
||||
return true;
|
||||
} catch (e) {
|
||||
notifications().notify({
|
||||
level: "error",
|
||||
title: t("app.window.openFailed", { name: basename(path) }),
|
||||
body: e instanceof Error ? e.message : String(e),
|
||||
key: `app.open:${path}`,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (isTextTab(tab)) {
|
||||
const slot = await this.ensureSlot(tabId);
|
||||
if (!slot) return false;
|
||||
|
||||
@@ -8,12 +8,18 @@ import * as contributions from "@/workbench/contributions";
|
||||
import { ask } from "@/workbench/messages";
|
||||
import type * as Messages from "@/workbench/messages";
|
||||
import { registerEditorKind, type EditorDocumentLifecycle } from "@/workbench/contributions";
|
||||
import * as light from "./openLightweightEditor";
|
||||
|
||||
vi.mock("@/workbench/messages", async (original) => ({
|
||||
...(await original<typeof Messages>()),
|
||||
ask: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/platform/ipc", async (original) => {
|
||||
const mod = await original<typeof import("@/platform/ipc")>();
|
||||
return { ...mod, isTauri: () => true };
|
||||
});
|
||||
|
||||
const notify = vi.fn();
|
||||
let ctrl: EditorController;
|
||||
let unregister: (() => void) | undefined;
|
||||
@@ -33,6 +39,7 @@ beforeEach(() => {
|
||||
status: "ok",
|
||||
data: { kind: "opened", label: "second" },
|
||||
});
|
||||
vi.spyOn(light, "openLightweightEditor").mockResolvedValue();
|
||||
});
|
||||
afterEach(() => {
|
||||
ctrl?.stop();
|
||||
@@ -44,7 +51,45 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("detachTab", () => {
|
||||
it.each([false, true])("waits for text save before opening and closing, autosave=%s", async (autoSave) => {
|
||||
it("moves a project file to a lightweight editor without saving first", async () => {
|
||||
useProject.setState({
|
||||
project: { root: "/p", workspace: { projects: ["/p"] } } as never,
|
||||
settings: { files: { autoSave: false } } as never,
|
||||
});
|
||||
const backend = createMemoryBackend({ [path]: "original\n" });
|
||||
const save = vi.spyOn(backend, "save");
|
||||
ctrl = new EditorController(backend);
|
||||
ctrl.start();
|
||||
await ctrl.openFile(path, { focus: false });
|
||||
const [pane, id] = current();
|
||||
ctrl.slotFor(id)!.dispatchLocal({ changes: { from: 0, to: 8, insert: "edited" } });
|
||||
expect(await ctrl.detachTab(pane, id)).toBe(true);
|
||||
expect(hasTab(id)).toBe(false);
|
||||
expect(save).not.toHaveBeenCalled();
|
||||
expect(commands.windowOpenFileInNewWindow).not.toHaveBeenCalled();
|
||||
expect(light.openLightweightEditor).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ path, line: expect.any(Number), column: expect.any(Number) }),
|
||||
null,
|
||||
);
|
||||
await vi.waitFor(() => expect(ctrl.manager.get(path)).toBeUndefined());
|
||||
});
|
||||
|
||||
it("keeps the tab when the lightweight editor fails to open", async () => {
|
||||
useProject.setState({
|
||||
project: { root: "/p", workspace: { projects: ["/p"] } } as never,
|
||||
settings: { files: { autoSave: false } } as never,
|
||||
});
|
||||
ctrl = new EditorController(createMemoryBackend({ [path]: "original\n" }));
|
||||
ctrl.start();
|
||||
await ctrl.openFile(path, { focus: false });
|
||||
const [pane, id] = current();
|
||||
vi.mocked(light.openLightweightEditor).mockRejectedValue(new Error("window failed"));
|
||||
expect(await ctrl.detachTab(pane, id)).toBe(false);
|
||||
expect(hasTab(id)).toBe(true);
|
||||
expect(notify).toHaveBeenCalledWith(expect.objectContaining({ level: "error", body: "window failed" }));
|
||||
});
|
||||
|
||||
it.each([false, true])("waits for text save before opening a full window, autosave=%s", async (autoSave) => {
|
||||
useProject.setState({ settings: { files: { autoSave } } as never });
|
||||
const backend = createMemoryBackend({ [path]: "original\n" });
|
||||
ctrl = new EditorController(backend);
|
||||
@@ -69,6 +114,7 @@ describe("detachTab", () => {
|
||||
const result = ctrl.detachTab(pane, id);
|
||||
await vi.waitFor(() => expect(save).toHaveBeenCalled());
|
||||
expect(commands.windowOpenFileInNewWindow).not.toHaveBeenCalled();
|
||||
expect(light.openLightweightEditor).not.toHaveBeenCalled();
|
||||
expect(hasTab(id)).toBe(true);
|
||||
finish();
|
||||
expect(await result).toBe(true);
|
||||
@@ -168,15 +214,21 @@ describe("detachTab", () => {
|
||||
);
|
||||
|
||||
it.each([
|
||||
["C:\\project\\a.ts", ["C:/project"], "C:/project"],
|
||||
["C:\\other\\a.ts", ["C:/project", "C:/other"], "C:/project"],
|
||||
["C:\\project-other\\a.ts", ["C:/project"], null],
|
||||
])("routes %s by workspace containment", async (file, projects, expected) => {
|
||||
["C:\\project\\a.ts", ["C:/project"], true],
|
||||
["C:\\other\\a.ts", ["C:/project", "C:/other"], true],
|
||||
["C:\\project-other\\a.ts", ["C:/project"], false],
|
||||
])("routes %s by workspace containment", async (file, projects, lightPath) => {
|
||||
useProject.setState({ project: { root: "C:/project", workspace: { projects } } as never });
|
||||
ctrl = new EditorController(createMemoryBackend({ [file]: "text\n" }));
|
||||
ctrl.start();
|
||||
await ctrl.openFile(file, { focus: false });
|
||||
expect(await ctrl.detachTab(...current())).toBe(true);
|
||||
expect(commands.windowOpenFileInNewWindow).toHaveBeenCalledWith(expected, file);
|
||||
if (lightPath) {
|
||||
expect(light.openLightweightEditor).toHaveBeenCalledWith(expect.objectContaining({ path: file }), null);
|
||||
expect(commands.windowOpenFileInNewWindow).not.toHaveBeenCalled();
|
||||
} else {
|
||||
expect(commands.windowOpenFileInNewWindow).toHaveBeenCalledWith(null, file);
|
||||
expect(light.openLightweightEditor).not.toHaveBeenCalled();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -254,6 +254,11 @@ export class DocModel {
|
||||
/** Bumped by every change (local or remote). */
|
||||
changeCounter = 0;
|
||||
closed = false;
|
||||
/**
|
||||
* Tab moved to an auxiliary editor window that already holds this document:
|
||||
* release must drop the local model and backend ref without autosave / keep-dirty.
|
||||
*/
|
||||
handoffRelease = false;
|
||||
private refreshTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
private saving: Promise<void> = Promise.resolve();
|
||||
private meta: DocMeta;
|
||||
@@ -895,8 +900,10 @@ export class DocumentManager {
|
||||
// Defer so that "close tab + reopen in split" in one tick keeps the model.
|
||||
queueMicrotask(async () => {
|
||||
if (model.inUse() || model.closed) return;
|
||||
const handoff = model.handoffRelease;
|
||||
model.handoffRelease = false;
|
||||
const files = this.settings()?.files;
|
||||
if (files?.autoSave !== false && model.getMeta().dirty) {
|
||||
if (!handoff && files?.autoSave !== false && model.getMeta().dirty) {
|
||||
try {
|
||||
await model.save("auto");
|
||||
} catch (e) {
|
||||
@@ -906,7 +913,8 @@ export class DocumentManager {
|
||||
// As in IDEA, a file whose changes are not saved (autosave off, or a failed save) stays
|
||||
// open without a tab: reopening shows the changes, and Save All and the exit check still
|
||||
// cover them. An untitled buffer was asked about when its tab closed.
|
||||
if (model.getMeta().dirty && !isUntitledUri(model.path)) return;
|
||||
// Handoff to an aux editor: the sibling window already references the same document.
|
||||
if (!handoff && model.getMeta().dirty && !isUntitledUri(model.path)) return;
|
||||
if (model.inUse()) return;
|
||||
await model.sync.whenIdle();
|
||||
if (model.inUse()) return;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
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?.();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ const originalTabs = useTabs.getState();
|
||||
const originalProject = useProject.getState();
|
||||
|
||||
beforeEach(() => {
|
||||
useMarkdownModes.setState({ byPath: {}, fallback: "editor" });
|
||||
useMarkdownModes.setState({ byTab: {}, fallback: "editor" });
|
||||
useTabs.setState({
|
||||
layout: { kind: "pane", paneId: "p1" },
|
||||
panes: { p1: { id: "p1", tabs: [first], active: first.id, mru: [first.id] } },
|
||||
@@ -87,7 +87,33 @@ describe("Markdown layout controls", () => {
|
||||
expect(screen.getByRole("toolbar", { name: "Markdown editor layout" }).closest('[role="tabpanel"]')).not.toBeNull();
|
||||
});
|
||||
|
||||
it("routes each pane's layout buttons to that pane's file", () => {
|
||||
it("keeps a separate layout in each split pane of the same file", () => {
|
||||
useProject.setState({ settings: null });
|
||||
const copy = md("t3", first.input.path!);
|
||||
useTabs.setState({
|
||||
layout: {
|
||||
kind: "split",
|
||||
id: "split",
|
||||
dir: "row",
|
||||
children: [
|
||||
{ kind: "pane", paneId: "p1" },
|
||||
{ kind: "pane", paneId: "p2" },
|
||||
],
|
||||
},
|
||||
panes: {
|
||||
p1: { id: "p1", tabs: [first], active: first.id, mru: [first.id] },
|
||||
p2: { id: "p2", tabs: [copy], active: copy.id, mru: [copy.id] },
|
||||
},
|
||||
});
|
||||
render(<EditorAreaView />);
|
||||
fireEvent.click(screen.getAllByRole("button", { name: "Preview Only" })[1]!);
|
||||
const [left, right] = screen.getAllByRole("button", { name: "Preview Only" });
|
||||
expect(left).toHaveAttribute("aria-pressed", "false");
|
||||
expect(right).toHaveAttribute("aria-pressed", "true");
|
||||
expect(screen.getAllByRole("document", { name: "Markdown preview" })).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("routes each pane's layout buttons to that pane's tab", () => {
|
||||
useProject.setState({ settings: null });
|
||||
useTabs.setState({
|
||||
layout: {
|
||||
@@ -106,8 +132,8 @@ describe("Markdown layout controls", () => {
|
||||
});
|
||||
render(<EditorAreaView />);
|
||||
fireEvent.click(screen.getAllByRole("button", { name: "Preview Only" })[1]!);
|
||||
expect(useMarkdownModes.getState().byPath[first.input.path!]).toBeUndefined();
|
||||
expect(useMarkdownModes.getState().byPath[second.input.path!]).toBe("preview");
|
||||
expect(useMarkdownModes.getState().byTab[first.id]).toBe("editor");
|
||||
expect(useMarkdownModes.getState().byTab[second.id]).toBe("preview");
|
||||
act(() => useDistractionFree.setState({ active: true }));
|
||||
expect(screen.getAllByRole("toolbar", { name: "Markdown editor layout" })).toHaveLength(2);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { ComponentType } from "react";
|
||||
import { activate as editor } from "./editor/core";
|
||||
import { activateEditorWindow, EditorWindow } from "./editor/core/EditorWindow";
|
||||
import { installLocaleSync } from "./features/app/locale";
|
||||
import { installMenuBridge } from "./features/app/menuBridge";
|
||||
import { trackRuntimeSettings } from "./features/settings/runtime";
|
||||
import { installKeyboardDispatcher } from "./platform/keymap";
|
||||
import { activateList } from "./windowBoot";
|
||||
|
||||
/**
|
||||
* Lightweight editor window of project window `parent`: one file, sharing the
|
||||
* parent's documents and language servers, with no workbench chrome.
|
||||
*/
|
||||
export function bootEditorWindow(parent: string): ComponentType {
|
||||
activateList("editor window", [
|
||||
["locale", installLocaleSync],
|
||||
["settings", trackRuntimeSettings],
|
||||
["menu", installMenuBridge],
|
||||
["editor", editor],
|
||||
["editorWindow", () => activateEditorWindow(parent)],
|
||||
]);
|
||||
installKeyboardDispatcher();
|
||||
return EditorWindow;
|
||||
}
|
||||
@@ -3,7 +3,8 @@
|
||||
* `"preview"`): the file opens in the text editor, wrapped with the plugin's
|
||||
* editor and the Editor / Editor and Preview / Preview switch (in the tab
|
||||
* strip, or floating when tabs are hidden), as Markdown's preview. The
|
||||
* layout is kept per file; files not switched yet start in the declared one.
|
||||
* layout is kept per editor tab (split panes of one file each have their own);
|
||||
* tabs not switched yet start in the declared one.
|
||||
*/
|
||||
import clsx from "clsx";
|
||||
import { useRef, type ReactNode } from "react";
|
||||
@@ -15,21 +16,21 @@ import styles from "./PluginView.module.css";
|
||||
|
||||
export type EditorLayout = "editor" | "split" | "preview";
|
||||
|
||||
/** `<plugin>/<editor>` → path → layout. */
|
||||
export const useEditorLayouts = create<{ byPath: Record<string, EditorLayout> }>(() => ({ byPath: {} }));
|
||||
/** `<plugin>/<editor>:<tab>` → layout. */
|
||||
const useEditorLayouts = create<{ byTab: Record<string, EditorLayout> }>(() => ({ byTab: {} }));
|
||||
|
||||
const layoutKey = (pluginId: string, editorId: string, path: string) => `${pluginId}/${editorId}:${path}`;
|
||||
const layoutKey = (pluginId: string, editorId: string, tabId: string) => `${pluginId}/${editorId}:${tabId}`;
|
||||
|
||||
export function layoutOf(pluginId: string, decl: CustomEditorDecl, path: string, byPath: Record<string, EditorLayout>) {
|
||||
return byPath[layoutKey(pluginId, decl.id, path)] ?? (decl.layout === "preview" ? "preview" : "split");
|
||||
function layoutOf(pluginId: string, decl: CustomEditorDecl, tabId: string, byTab: Record<string, EditorLayout>) {
|
||||
return byTab[layoutKey(pluginId, decl.id, tabId)] ?? (decl.layout === "preview" ? "preview" : "split");
|
||||
}
|
||||
|
||||
export function setEditorLayout(pluginId: string, editorId: string, path: string, layout: EditorLayout) {
|
||||
useEditorLayouts.setState((s) => ({ byPath: { ...s.byPath, [layoutKey(pluginId, editorId, path)]: layout } }));
|
||||
function setEditorLayout(pluginId: string, editorId: string, tabId: string, layout: EditorLayout) {
|
||||
useEditorLayouts.setState((s) => ({ byTab: { ...s.byTab, [layoutKey(pluginId, editorId, tabId)]: layout } }));
|
||||
}
|
||||
|
||||
function LayoutActions({ pluginId, decl, path }: { pluginId: string; decl: CustomEditorDecl; path: string }) {
|
||||
const layout = useEditorLayouts((s) => layoutOf(pluginId, decl, path, s.byPath));
|
||||
function LayoutActions({ pluginId, decl, tabId }: { pluginId: string; decl: CustomEditorDecl; tabId: string }) {
|
||||
const layout = useEditorLayouts((s) => layoutOf(pluginId, decl, tabId, s.byTab));
|
||||
const button = (value: EditorLayout, icon: string, title: string) => (
|
||||
<IconButton
|
||||
icon={icon}
|
||||
@@ -37,7 +38,7 @@ function LayoutActions({ pluginId, decl, path }: { pluginId: string; decl: Custo
|
||||
size="small"
|
||||
title={title}
|
||||
pressed={layout === value}
|
||||
onClick={() => setEditorLayout(pluginId, decl.id, path, value)}
|
||||
onClick={() => setEditorLayout(pluginId, decl.id, tabId, value)}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
@@ -51,8 +52,8 @@ function LayoutActions({ pluginId, decl, path }: { pluginId: string; decl: Custo
|
||||
|
||||
/** The `tabActions` of a wrapper: the layout switch in the editor's tab strip. */
|
||||
export function layoutActions(pluginId: string, decl: CustomEditorDecl) {
|
||||
return function PluginLayoutActions({ path }: { path: string; tabId: string }) {
|
||||
return <LayoutActions pluginId={pluginId} decl={decl} path={path} />;
|
||||
return function PluginLayoutActions({ tabId }: { path: string; tabId: string }) {
|
||||
return <LayoutActions pluginId={pluginId} decl={decl} tabId={tabId} />;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,6 +61,7 @@ export function layoutActions(pluginId: string, decl: CustomEditorDecl) {
|
||||
export function layoutWrapper(pluginId: string, decl: CustomEditorDecl) {
|
||||
return function PluginEditorLayout({
|
||||
path,
|
||||
tabId,
|
||||
children,
|
||||
actionsInTabs = false,
|
||||
}: {
|
||||
@@ -68,7 +70,7 @@ export function layoutWrapper(pluginId: string, decl: CustomEditorDecl) {
|
||||
children: ReactNode;
|
||||
actionsInTabs?: boolean;
|
||||
}) {
|
||||
const layout = useEditorLayouts((s) => layoutOf(pluginId, decl, path, s.byPath));
|
||||
const layout = useEditorLayouts((s) => layoutOf(pluginId, decl, tabId, s.byTab));
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
return (
|
||||
<div ref={ref} className={clsx(styles.split, styles[`layout-${layout}`])}>
|
||||
@@ -81,7 +83,7 @@ export function layoutWrapper(pluginId: string, decl: CustomEditorDecl) {
|
||||
)}
|
||||
{!actionsInTabs && (
|
||||
<FloatingToolbar targetRef={ref}>
|
||||
<LayoutActions pluginId={pluginId} decl={decl} path={path} />
|
||||
<LayoutActions pluginId={pluginId} decl={decl} tabId={tabId} />
|
||||
</FloatingToolbar>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
import { registerActions, type Action } from "@/platform/actions";
|
||||
import { call, commands, type FileProbe } from "@/platform/ipc";
|
||||
import { getContext } from "@/platform/context";
|
||||
import { activeEditor } from "@/editor/api";
|
||||
import { openWithSystemApp } from "@/platform/fileManager";
|
||||
import { onFileTypesChange } from "@/platform/fileTypes";
|
||||
import { basename, useProject } from "@/platform/project";
|
||||
@@ -72,8 +72,10 @@ function markdownActions(): Action[] {
|
||||
keywords: ["markdown", "preview", "layout"],
|
||||
when: "textEditorActive && editorLangId == markdown",
|
||||
run: ({ arg }) => {
|
||||
const path = typeof arg === "string" ? arg : getContext().editorPath;
|
||||
if (typeof path === "string" && isMarkdownPath(path)) setMarkdownMode(path, m);
|
||||
// The tab's layout buttons pass their tab; the keyboard acts on the focused editor's.
|
||||
const editor = activeEditor();
|
||||
const tabId = typeof arg === "string" ? arg : isMarkdownPath(editor?.ctx.path ?? "") ? editor?.tabId : undefined;
|
||||
if (tabId) setMarkdownMode(tabId, m);
|
||||
},
|
||||
});
|
||||
return [
|
||||
|
||||
@@ -42,7 +42,7 @@ import { publishPreviewSelection, publishPreviewTop, stepMarkdownPreviewFontZoom
|
||||
import { subscribeTheme, themeKey } from "@/platform/themeWatch";
|
||||
import { hasMermaid, MERMAID_SELECTOR, renderMermaidIn } from "./mermaid";
|
||||
import { renderMath } from "@/editor/lsp/markdownMath";
|
||||
import { modeOf, useMarkdownModes } from "./modes";
|
||||
import { modeOf, pinMarkdownMode, useMarkdownModes } from "./modes";
|
||||
import { MarkdownLayoutActions } from "./MarkdownLayoutActions";
|
||||
import {
|
||||
ANCHOR_PREFIX,
|
||||
@@ -90,7 +90,8 @@ export function MarkdownEditor({
|
||||
children: ReactNode;
|
||||
actionsInTabs?: boolean;
|
||||
}) {
|
||||
const mode = useMarkdownModes((s) => modeOf(s, path));
|
||||
const mode = useMarkdownModes((s) => modeOf(s, tabId));
|
||||
useEffect(() => pinMarkdownMode(tabId), [tabId]);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const editorRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import { tx } from "@/platform/i18n";
|
||||
import { modeOf, useMarkdownModes } from "./modes";
|
||||
import styles from "./Markdown.module.css";
|
||||
|
||||
export function MarkdownLayoutActions({ path }: { path: string; tabId: string }) {
|
||||
const mode = useMarkdownModes((s) => modeOf(s, path));
|
||||
export function MarkdownLayoutActions({ tabId }: { path: string; tabId: string }) {
|
||||
const mode = useMarkdownModes((s) => modeOf(s, tabId));
|
||||
return (
|
||||
<div className={styles.layoutActions} role="toolbar" aria-label={tx("Markdown editor layout")}>
|
||||
<IconButton
|
||||
@@ -13,7 +13,7 @@ export function MarkdownLayoutActions({ path }: { path: string; tabId: string })
|
||||
size="small"
|
||||
title="Editor Only"
|
||||
action="markdown.editorOnly"
|
||||
actionArg={path}
|
||||
actionArg={tabId}
|
||||
pressed={mode === "editor"}
|
||||
/>
|
||||
<IconButton
|
||||
@@ -22,7 +22,7 @@ export function MarkdownLayoutActions({ path }: { path: string; tabId: string })
|
||||
size="small"
|
||||
title="Editor and Preview"
|
||||
action="markdown.editorAndPreview"
|
||||
actionArg={path}
|
||||
actionArg={tabId}
|
||||
pressed={mode === "split"}
|
||||
/>
|
||||
<IconButton
|
||||
@@ -31,7 +31,7 @@ export function MarkdownLayoutActions({ path }: { path: string; tabId: string })
|
||||
size="small"
|
||||
title="Preview Only"
|
||||
action="markdown.previewOnly"
|
||||
actionArg={path}
|
||||
actionArg={tabId}
|
||||
pressed={mode === "preview"}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -49,7 +49,7 @@ describe("Markdown preview search & selection highlights", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
disposers.push(registerMarkdownLiveSource());
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -184,7 +184,7 @@ describe("Markdown preview search & selection highlights", () => {
|
||||
|
||||
it("auto-highlights all other occurrences when a word is selected in the preview", async () => {
|
||||
openEditor("alpha beta alpha gamma alpha\n");
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [path]: "split" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "split" } })));
|
||||
render(
|
||||
<MarkdownEditor path={path} tabId="t">
|
||||
<div />
|
||||
@@ -228,7 +228,7 @@ describe("Markdown preview search & selection highlights", () => {
|
||||
|
||||
it("auto-highlights occurrences in the preview when a word is selected in the editor", () => {
|
||||
openEditor("beta alpha beta\n");
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [path]: "split" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "split" } })));
|
||||
render(
|
||||
<MarkdownEditor path={path} tabId="t">
|
||||
<div />
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
/** Markdown editor layout per file: Editor only / Editor and Preview / Preview only (IDEA's split editor). */
|
||||
/**
|
||||
* Markdown editor layout per editor tab: Editor only / Editor and Preview / Preview only. Split
|
||||
* panes showing the same file each keep their own.
|
||||
*/
|
||||
import { create } from "zustand";
|
||||
|
||||
export type MarkdownMode = "editor" | "split" | "preview";
|
||||
@@ -16,17 +19,23 @@ function storedDefault(): MarkdownMode {
|
||||
}
|
||||
|
||||
interface ModesState {
|
||||
byPath: Record<string, MarkdownMode>;
|
||||
/** Mode of files not switched yet: the last one chosen. */
|
||||
byTab: Record<string, MarkdownMode>;
|
||||
/** Mode of tabs opened since: the last one chosen. */
|
||||
fallback: MarkdownMode;
|
||||
}
|
||||
|
||||
export const useMarkdownModes = create<ModesState>(() => ({ byPath: {}, fallback: storedDefault() }));
|
||||
export const useMarkdownModes = create<ModesState>(() => ({ byTab: {}, fallback: storedDefault() }));
|
||||
|
||||
export const modeOf = (s: ModesState, path: string): MarkdownMode => s.byPath[path] ?? s.fallback;
|
||||
export const modeOf = (s: ModesState, tabId: string): MarkdownMode => s.byTab[tabId] ?? s.fallback;
|
||||
|
||||
export function setMarkdownMode(path: string, mode: MarkdownMode) {
|
||||
useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [path]: mode }, fallback: mode }));
|
||||
/** Fixes a shown tab's mode, so choosing one in another tab doesn't change it. */
|
||||
export function pinMarkdownMode(tabId: string) {
|
||||
if (useMarkdownModes.getState().byTab[tabId]) return;
|
||||
useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, [tabId]: s.fallback } }));
|
||||
}
|
||||
|
||||
export function setMarkdownMode(tabId: string, mode: MarkdownMode) {
|
||||
useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, [tabId]: mode }, fallback: mode }));
|
||||
try {
|
||||
localStorage.setItem(DEFAULT_KEY, mode);
|
||||
} catch {
|
||||
|
||||
@@ -25,7 +25,7 @@ describe("preview <details>", () => {
|
||||
const handle = { view, ctx };
|
||||
_addEditor(handle);
|
||||
disposers.push(() => _removeEditor(handle));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [ctx.path]: "split" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "split" } })));
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
|
||||
@@ -39,7 +39,7 @@ describe("Markdown Preview only", () => {
|
||||
disposers.push(registerMarkdownLiveSource());
|
||||
const live = editorContributions().find((c) => c.id === "viewers.markdownLive")!;
|
||||
view = new EditorView({ state: EditorState.create({ doc: source, extensions: [live.extensions(ctx)] }) });
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
@@ -97,7 +97,7 @@ describe("Markdown Preview only", () => {
|
||||
});
|
||||
|
||||
it("leaves the split preview to the editor's scroll sync", () => {
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [path]: "split" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "split" } })));
|
||||
const el = preview();
|
||||
goTo(20);
|
||||
expect(el.scrollTop).toBe(0);
|
||||
@@ -110,10 +110,10 @@ describe("Markdown Preview only", () => {
|
||||
const el = preview();
|
||||
goTo(20);
|
||||
expect(shown()).toBe(20);
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [path]: "split" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "split" } })));
|
||||
expect(shown()).toBeNull();
|
||||
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
expect(shown()).not.toBeNull();
|
||||
cleanup();
|
||||
expect(shown()).toBeNull();
|
||||
|
||||
@@ -56,7 +56,7 @@ describe("preview-only scroll position", () => {
|
||||
it("restores the preview's own scroll after a remount", async () => {
|
||||
open(mdCtx);
|
||||
activate(views[0]!);
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
const first = render(
|
||||
<MarkdownEditor path={mdCtx.path} tabId="t">
|
||||
<div />
|
||||
@@ -84,7 +84,7 @@ describe("preview-only scroll position", () => {
|
||||
open(mdCtx);
|
||||
activate(views[0]!);
|
||||
act(() => useLiveMarkdown.setState((s) => ({ [mdCtx.path]: { ...s[mdCtx.path]!, previewTop: 300 } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
render(
|
||||
<MarkdownEditor path={mdCtx.path} tabId="t">
|
||||
<div />
|
||||
@@ -105,8 +105,8 @@ describe("preview-only scroll position", () => {
|
||||
});
|
||||
try {
|
||||
// Re-running the restore (mode toggle) hits the clamp…
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "split" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "split" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
expect(preview.scrollTop).toBe(100);
|
||||
// The browser reports the clamped write as a scroll; the saved offset stays.
|
||||
act(() => preview.dispatchEvent(new Event("scroll")));
|
||||
@@ -132,7 +132,7 @@ describe("preview-only scroll position", () => {
|
||||
open(mdCtx);
|
||||
activate(views[0]!);
|
||||
act(() => useLiveMarkdown.setState((s) => ({ [mdCtx.path]: { ...s[mdCtx.path]!, previewTop: 300 } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
render(
|
||||
<MarkdownEditor path={mdCtx.path} tabId="t">
|
||||
<div />
|
||||
|
||||
@@ -13,7 +13,7 @@ const SPLIT_KEY = "openidea.markdown.split";
|
||||
describe("Markdown split resizer", () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
useMarkdownModes.setState({ byPath: {}, fallback: "split" });
|
||||
useMarkdownModes.setState({ byTab: {}, fallback: "split" });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -38,17 +38,17 @@ describe("Markdown split resizer", () => {
|
||||
expect(screen.getByRole("separator", { name: "Resize Markdown preview" })).toBeInTheDocument();
|
||||
expect(mounts).toBe(1);
|
||||
|
||||
act(() => setMarkdownMode(PATH, "preview"));
|
||||
act(() => setMarkdownMode("t", "preview"));
|
||||
expect(screen.queryByRole("separator", { name: "Resize Markdown preview" })).toBeNull();
|
||||
expect(screen.getByTestId("editor-probe")).toBeInTheDocument();
|
||||
expect(mounts).toBe(1);
|
||||
|
||||
act(() => setMarkdownMode(PATH, "editor"));
|
||||
act(() => setMarkdownMode("t", "editor"));
|
||||
expect(screen.queryByRole("separator", { name: "Resize Markdown preview" })).toBeNull();
|
||||
expect(screen.getByTestId("editor-probe")).toBeInTheDocument();
|
||||
expect(mounts).toBe(1);
|
||||
|
||||
act(() => setMarkdownMode(PATH, "split"));
|
||||
act(() => setMarkdownMode("t", "split"));
|
||||
expect(screen.getByRole("separator", { name: "Resize Markdown preview" })).toBeInTheDocument();
|
||||
expect(mounts).toBe(1);
|
||||
});
|
||||
|
||||
@@ -128,7 +128,7 @@ describe("editor font size actions", () => {
|
||||
const md = open(mdCtx);
|
||||
const otherMd = open(otherMdCtx);
|
||||
activate(md);
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "split" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "split" } })));
|
||||
render(
|
||||
<MarkdownEditor path={mdCtx.path} tabId="t">
|
||||
<div />
|
||||
@@ -208,7 +208,7 @@ describe("editor font size actions", () => {
|
||||
views.push(view);
|
||||
activate(view);
|
||||
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
render(
|
||||
<MarkdownEditor path={mdCtx.path} tabId="t">
|
||||
<div />
|
||||
@@ -373,7 +373,7 @@ describe("editor font size actions", () => {
|
||||
|
||||
describe("Markdown preview font size", () => {
|
||||
const preview = () => {
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, [mdCtx.path]: "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
render(
|
||||
<MarkdownEditor path={mdCtx.path} tabId="t">
|
||||
<div />
|
||||
|
||||
@@ -15,8 +15,8 @@ import { tx } from "@/platform/i18n";
|
||||
|
||||
const RELOAD_DELAY = 250;
|
||||
|
||||
export function WebEditor({ path, children }: { path: string; tabId: string; children: ReactNode }) {
|
||||
const preview = useWebPreview((s) => !!s[path]);
|
||||
export function WebEditor({ path, tabId, children }: { path: string; tabId: string; children: ReactNode }) {
|
||||
const preview = useWebPreview((s) => !!s[tabId]);
|
||||
const browsers = useBrowsers((s) => s.list);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
return (
|
||||
@@ -30,7 +30,7 @@ export function WebEditor({ path, children }: { path: string; tabId: string; chi
|
||||
size="small"
|
||||
iconSize={16}
|
||||
action="web.togglePreview"
|
||||
actionArg={path}
|
||||
actionArg={tabId}
|
||||
pressed={preview}
|
||||
title="Built-in Preview"
|
||||
/>
|
||||
|
||||
@@ -33,11 +33,11 @@ export async function loadBrowsers(): Promise<void> {
|
||||
|
||||
export const browserIcon = (id: string) => (hasIcon(`browser-${id}`) ? `browser-${id}` : "web");
|
||||
|
||||
/** Paths shown with the built-in preview beside the editor. */
|
||||
/** Editor tabs showing the built-in preview beside the editor (each split pane has its own). */
|
||||
export const useWebPreview = create<Record<string, boolean>>(() => ({}));
|
||||
|
||||
export function togglePreview(path: string, on = !useWebPreview.getState()[path]) {
|
||||
useWebPreview.setState({ [path]: on });
|
||||
export function togglePreview(tabId: string, on = !useWebPreview.getState()[tabId]) {
|
||||
useWebPreview.setState({ [tabId]: on });
|
||||
}
|
||||
|
||||
/** The built-in server's URL for `path`. */
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
registerTextEditorWrapper,
|
||||
useTextEditorWrappers,
|
||||
} from "@/workbench/contributions";
|
||||
import { registerEditorContribution } from "@/editor/api";
|
||||
import { activeEditor, registerEditorContribution } from "@/editor/api";
|
||||
import { djangoContentWatcher, djangoTemplateBanner } from "./djangoTemplates";
|
||||
import {
|
||||
browserIcon,
|
||||
@@ -44,7 +44,15 @@ function targetPath(arg: unknown): string | null {
|
||||
|
||||
async function showPreview(path: string) {
|
||||
await maybeEditorService()?.openFile(path, { focus: true });
|
||||
togglePreview(path, true);
|
||||
const editor = activeEditor();
|
||||
if (editor?.tabId && editor.ctx.path === path) togglePreview(editor.tabId, true);
|
||||
}
|
||||
|
||||
/** The tab a preview button passes, or the focused HTML editor's. */
|
||||
function previewTab(arg: unknown): string | undefined {
|
||||
if (typeof arg === "string") return arg;
|
||||
const editor = activeEditor();
|
||||
return editor && isHtmlPath(editor.ctx.path) ? editor.tabId : undefined;
|
||||
}
|
||||
|
||||
function browserMenu(path: string): MenuItem {
|
||||
@@ -102,12 +110,12 @@ export function activate(): () => void {
|
||||
when: "textEditorActive && editorLangId == html",
|
||||
keywords: ["browser", "html", "preview", "live"],
|
||||
toggled: () => {
|
||||
const path = getContext().editorPath;
|
||||
return typeof path === "string" && !!useWebPreview.getState()[path];
|
||||
const tabId = previewTab(undefined);
|
||||
return !!tabId && !!useWebPreview.getState()[tabId];
|
||||
},
|
||||
run: ({ arg }) => {
|
||||
const path = targetPath(arg);
|
||||
if (path && isHtmlPath(path)) togglePreview(path);
|
||||
const tabId = previewTab(arg);
|
||||
if (tabId) togglePreview(tabId);
|
||||
},
|
||||
},
|
||||
]),
|
||||
|
||||
@@ -33,7 +33,7 @@ describe("the built-in HTML preview", () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
useProject.setState({ project: { root: "/p" } as never });
|
||||
useWebPreview.setState({ "/p/page.html": true });
|
||||
useWebPreview.setState({ t: true });
|
||||
const { container } = render(
|
||||
<WebEditor path="/p/page.html" tabId="t">
|
||||
<div />
|
||||
|
||||
@@ -11,15 +11,20 @@ describe("auxiliaryWindow", () => {
|
||||
expect(auxiliaryWindow("comparison-project-2-14")).toEqual({ kind: "comparison", parent: "project-2" });
|
||||
expect(auxiliaryWindow("diff-main-0")).toEqual({ kind: "diff", parent: "main" });
|
||||
expect(auxiliaryWindow("diff-project-2-14")).toEqual({ kind: "diff", parent: "project-2" });
|
||||
expect(auxiliaryWindow("editor-main-0")).toEqual({ kind: "editor", parent: "main" });
|
||||
expect(auxiliaryWindow("editor-project-2-14")).toEqual({ kind: "editor", parent: "project-2" });
|
||||
expect(auxiliaryWindow("deployment-project-2")).toEqual({ kind: "deployment", parent: "project-2" });
|
||||
});
|
||||
|
||||
it.each(["settings", "comparison", "diff", "deployment"])("grants %s windows permission to close", (kind) => {
|
||||
expect(capability.windows).toContain(`${kind}-*`);
|
||||
expect(bridgeCapability.windows).toContain(`${kind}-*`);
|
||||
expect(capability.permissions).toContain("core:window:allow-close");
|
||||
expect(capability.permissions).toContain("core:window:allow-destroy");
|
||||
});
|
||||
it.each(["settings", "comparison", "diff", "editor", "deployment"])(
|
||||
"grants %s windows permission to close",
|
||||
(kind) => {
|
||||
expect(capability.windows).toContain(`${kind}-*`);
|
||||
expect(bridgeCapability.windows).toContain(`${kind}-*`);
|
||||
expect(capability.permissions).toContain("core:window:allow-close");
|
||||
expect(capability.permissions).toContain("core:window:allow-destroy");
|
||||
},
|
||||
);
|
||||
|
||||
it("leaves project windows and malformed labels alone", () => {
|
||||
for (const label of ["", "main", "project-1", "settings-", "comparison-main", "comparison-main-x"]) {
|
||||
|
||||
@@ -8,15 +8,25 @@ import { getAllWindows, getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { TauriEvent } from "@tauri-apps/api/event";
|
||||
import { isTauri } from "./ipc";
|
||||
|
||||
export type AuxKind = "settings" | "comparison" | "diff" | "deployment";
|
||||
export type AuxKind = "settings" | "comparison" | "diff" | "editor" | "deployment";
|
||||
|
||||
/** Kinds with several windows per parent (`<kind>-<parent>-<n>`); the others have one (`<kind>-<parent>`). */
|
||||
const MULTIPLE: ReadonlySet<AuxKind> = new Set(["comparison", "diff"]);
|
||||
const KINDS: readonly AuxKind[] = ["settings", "comparison", "diff", "deployment"];
|
||||
const MULTIPLE: ReadonlySet<AuxKind> = new Set(["comparison", "diff", "editor"]);
|
||||
const KINDS: readonly AuxKind[] = ["settings", "comparison", "diff", "editor", "deployment"];
|
||||
|
||||
/** An auxiliary window reports to its parent whether it closed, and which documents it released. */
|
||||
export const AUX_CLOSED = "openidea://auxiliary/closed";
|
||||
|
||||
/** Lightweight editor window reports that it opened (or failed to open) the moved file. */
|
||||
export const EDITOR_READY = "openidea://editor/ready";
|
||||
|
||||
export interface EditorReadyResult {
|
||||
label: string;
|
||||
path: string;
|
||||
ok: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface AuxCloseResult {
|
||||
label: string;
|
||||
closed: boolean;
|
||||
|
||||
@@ -2535,5 +2535,10 @@
|
||||
"60 FPS": "60 FPS",
|
||||
"30 FPS": "30 FPS",
|
||||
"15 FPS": "15 FPS",
|
||||
"10 FPS": "10 FPS"
|
||||
"10 FPS": "10 FPS",
|
||||
"Could not close editor": "Could not close editor",
|
||||
"Missing editor request": "Missing editor request",
|
||||
"The editor’s project is no longer open": "The editor’s project is no longer open",
|
||||
"Timed out opening the editor window": "Timed out opening the editor window",
|
||||
"Could not open the editor window": "Could not open the editor window"
|
||||
}
|
||||
@@ -8909,5 +8909,10 @@
|
||||
"60 FPS": "60 帧/秒",
|
||||
"30 FPS": "30 帧/秒",
|
||||
"15 FPS": "15 帧/秒",
|
||||
"10 FPS": "10 帧/秒"
|
||||
"10 FPS": "10 帧/秒",
|
||||
"Could not close editor": "无法关闭编辑器",
|
||||
"Missing editor request": "缺少编辑器请求",
|
||||
"The editor’s project is no longer open": "编辑器所属的项目已关闭",
|
||||
"Timed out opening the editor window": "打开编辑器窗口超时",
|
||||
"Could not open the editor window": "无法打开编辑器窗口"
|
||||
}
|
||||
@@ -33,7 +33,7 @@ describe("selectable read-only surfaces", () => {
|
||||
},
|
||||
}),
|
||||
);
|
||||
act(() => useMarkdownModes.setState((s) => ({ byPath: { ...s.byPath, "/p/README.md": "preview" } })));
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
|
||||
render(
|
||||
<MarkdownEditor path="/p/README.md" tabId="t">
|
||||
<div />
|
||||
|
||||
Reference in new issue
Заблокувати користувача