Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(editor): seal three unguarded data-loss paths in the global chrome

yhh6e834643c94a
diff --git a/desktop/src/App.tsx b/desktop/src/App.tsx
index bee6a7909..1419dde77 100644
--- a/desktop/src/App.tsx
+++ b/desktop/src/App.tsx
@@ -22,6 +22,7 @@ import { SettingsDialog } from '@/components/SettingsDialog';
import { TilemapPickerDialog } from '@/components/TilemapPickerDialog';
import { CommandPalette } from '@/components/CommandPalette';
import { useEditorStore } from '@/store/editorStore';
+import { ConfirmService } from '@/components/confirm';
import { commands } from '@/commands';
import { handleTilePaintKey } from '@/tools/tileMode';
import { suggestedMode } from '@/mode/activeMode';
@@ -61,6 +62,14 @@ export function App() {
// (main + each popped-out panel) so shortcuts fire whichever one has focus.
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
+ // A modal / confirm dialog owns the keyboard while open. Don't let global
+ // shortcuts (Delete, Ctrl+Z, Ctrl+D, F5…) reach the scene behind it — worst
+ // case they'd mutate the very scene a "Discard unsaved changes?" dialog is
+ // protecting. Each dialog runs its own key handling (Escape to close, etc.).
+ const ui = useEditorStore.getState();
+ if (ui.settingsOpen || ui.paletteOpen || ui.buildOpen || ui.tilemapPickerOpen || ConfirmService.getSnapshot().length > 0) {
+ return;
+ }
// Ctrl+Space summons the Content Drawer — works even from a field.
if ((e.ctrlKey || e.metaKey) && e.code === 'Space') {
e.preventDefault();
diff --git a/desktop/src/i18n/messages/common.ts b/desktop/src/i18n/messages/common.ts
index d33a5ad13..4129c6683 100644
--- a/desktop/src/i18n/messages/common.ts
+++ b/desktop/src/i18n/messages/common.ts
@@ -38,6 +38,7 @@ export const commonMessages = defineMessages({
'discard.closeProject': { en: 'Closing the project will discard them', zh: '关闭项目将丢弃这些更改' },
'discard.openProject': { en: 'Opening another project will discard them', zh: '打开其他项目将丢弃这些更改' },
'discard.openScene': { en: 'Opening {name} will discard them', zh: '打开 {name} 将丢弃这些更改' },
+ 'discard.resetLayout': { en: 'Resetting the layout will discard them', zh: '重置布局将丢弃这些更改' },
'discard.openPrefab': { en: 'Editing prefab {name} will discard them', zh: '编辑预制体 {name} 将丢弃这些更改' },
'discard.exitPrefab': { en: 'Leaving prefab mode will discard them', zh: '退出预制体编辑将丢弃这些更改' },
'discard.openAsset': { en: 'Opening {name} will discard them', zh: '打开 {name} 将丢弃这些更改' },
diff --git a/desktop/src/layout/DockLayout.tsx b/desktop/src/layout/DockLayout.tsx
index ca762cfa2..b9ec85587 100644
--- a/desktop/src/layout/DockLayout.tsx
+++ b/desktop/src/layout/DockLayout.tsx
@@ -88,6 +88,25 @@ const components: Record<string, FC<IDockviewPanelProps>> = {
// matching UE/Unity. The Content Drawer (Ctrl+Space) is a separate overlay.
export const LAYOUT_KEY = 'estella.editor.layout.v6';
+// The live dockview api, held for the Window ▸ Reset Layout command. Set on ready.
+let liveApi: DockviewReadyEvent['api'] | null = null;
+
+/**
+ * Rebuild the default dock arrangement in place — the same clear+rebuild the
+ * ready handler runs when a saved layout fails to parse, so it's a proven-safe
+ * path. Rebuilding beats a `location.reload()`: it resets ONLY the layout,
+ * keeping the open scene, engine, and undo history intact (a full reload would
+ * discard unsaved work and reboot the engine).
+ */
+export function resetLayout() {
+ const api = liveApi;
+ if (!api) return;
+ api.clear();
+ buildDefaultLayout(api);
+ ensureBottomTabs(api);
+ api.getPanel('content')?.api.setActive();
+}
+
function buildDefaultLayout(api: DockviewReadyEvent['api']) {
// Viewport is the anchor; the right column stacks Outliner over Details.
api.addPanel({ id: 'viewport', component: 'viewport', title: t('layout.panel.viewport') });
@@ -282,6 +301,7 @@ export function DockLayout() {
const onReady = (event: DockviewReadyEvent) => {
const { api } = event;
dockApi.set(api); // expose to the activity bar (reveal/focus panels)
+ liveApi = api; // expose to Window ▸ Reset Layout
// Every popout group (a manual pop-out AND one dockview reopens while restoring a
// saved layout) is registered here: re-theme its window (dockview copies only the
diff --git a/desktop/src/layout/MenuBar.tsx b/desktop/src/layout/MenuBar.tsx
index b2944b628..7cd195ee2 100644
--- a/desktop/src/layout/MenuBar.tsx
+++ b/desktop/src/layout/MenuBar.tsx
@@ -8,7 +8,8 @@
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
import { WindowControls } from '@/layout/WindowControls';
import { DirtyDot } from '@/components/DirtyDot';
-import { LAYOUT_KEY } from '@/layout/DockLayout';
+import { resetLayout } from '@/layout/DockLayout';
+import { confirmDiscard } from '@/project/discardGuard';
import { useEditorStore } from '@/store/editorStore';
import { ProjectStore } from '@/project/ProjectStore';
import { EditorHistory } from '@/engine/EditorHistory';
@@ -60,7 +61,6 @@ export function MenuBar() {
checked: commands.isChecked(id),
};
};
- const openLauncher = () => useEditorStore.getState().openLauncher();
// Close the open menu on an outside click or Escape (Escape hands focus back
// to the menu's own button so keyboard flow continues at the menubar).
@@ -163,9 +163,13 @@ export function MenuBar() {
{
title: t('menu.window'),
items: [
- { label: t('menu.resetLayout'), onClick: () => { localStorage.removeItem(LAYOUT_KEY); location.reload(); } },
+ // Reset only the dock layout — rebuild in place (keeps scene/engine/undo),
+ // guarded so a wedged dirty asset-editor tab can't vanish unwarned.
+ { label: t('menu.resetLayout'), onClick: () => void confirmDiscard(t('discard.resetLayout')).then((ok) => ok && resetLayout()) },
{ sep: true },
- { label: t('menu.backToLauncher'), onClick: openLauncher },
+ // Same destination as File ▸ Close Project — run the guarded command so
+ // leaving a project can't silently drop unsaved scene + asset edits.
+ { label: t('menu.backToLauncher'), onClick: () => commands.run('project.close') },
],
},
{