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): stop Delete leaking to the scene from Tileset/Flipbook editors

yhh8477b65c0f3a
diff --git a/desktop/src/panels/FlipbookEditor.tsx b/desktop/src/panels/FlipbookEditor.tsx
index 8e6c158a9..4f16e88e4 100644
--- a/desktop/src/panels/FlipbookEditor.tsx
+++ b/desktop/src/panels/FlipbookEditor.tsx
@@ -164,7 +164,23 @@ export function FlipbookEditor() {
}
return (
- <div className="fb-editor">
+ <div
+ className="fb-editor"
+ tabIndex={0}
+ onKeyDown={(e) => {
+ // A field owns its own typing/backspace.
+ const el = e.target as HTMLElement;
+ if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable) return;
+ // This editor OWNS Delete/Backspace — remove the current frame, and never let
+ // the key fall through to the global entity-delete and wipe the scene
+ // selection sitting behind the panel.
+ if (e.key === 'Delete' || e.key === 'Backspace') {
+ e.preventDefault();
+ e.stopPropagation();
+ if (asset.frames.length) AnimClipCommands.removeFrame(curFrame);
+ }
+ }}
+ >
<div className="fb-toolbar">
{sheet && (
<>
diff --git a/desktop/src/panels/TilesetEditor.tsx b/desktop/src/panels/TilesetEditor.tsx
index 3ba5e4cbc..b172a94cd 100644
--- a/desktop/src/panels/TilesetEditor.tsx
+++ b/desktop/src/panels/TilesetEditor.tsx
@@ -527,7 +527,21 @@ export function TilesetEditor() {
const solidCount = Object.values(asset.tiles).filter((t) => t.collision).length;
return (
- <div className="ts-editor">
+ <div
+ className="ts-editor"
+ tabIndex={0}
+ onKeyDown={(e) => {
+ // A field owns its own typing/backspace.
+ const el = e.target as HTMLElement;
+ if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable) return;
+ // Consume Delete/Backspace so they can't fall through to the global
+ // entity-delete and silently wipe the scene selection behind this panel.
+ if (e.key === 'Delete' || e.key === 'Backspace') {
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ }}
+ >
<div className="ts-toolbar">
<GridField label={t('tile.field.tileW')} value={tw} min={1} onCommit={(n) => editGrid({ tileWidth: n })} />
<GridField label={t('tile.field.tileH')} value={th} min={1} onCommit={(n) => editGrid({ tileHeight: n })} />