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): multi-select Add Component union + Escape deselects

esengine977b0217d526
diff --git a/desktop/src/commands/editorCommands.ts b/desktop/src/commands/editorCommands.ts
index 12e79427f..e365f4045 100644
--- a/desktop/src/commands/editorCommands.ts
+++ b/desktop/src/commands/editorCommands.ts
@@ -217,7 +217,10 @@ commands.register({
id: 'entity.deselect',
label: t('cmd.entity.deselect'),
category: t('cat.entity'),
- isEnabled: () => sel().selectedId != null,
+ keybinding: 'escape',
+ // Escape clears the selection — but not while playing, where Escape stops Play
+ // (play.stop shares the binding; guarding here lets forEvent fall through to it).
+ isEnabled: () => !editor().isPlaying && sel().selectedId != null,
run: () => sel().select(null),
});
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index c9b49349f..a92e98c47 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -102,6 +102,18 @@ function fieldEqual(a: InspectorFieldValue, b: InspectorFieldValue): boolean {
return a === b;
}
+/** The union of components addable to ANY entity in a multi-selection — a component
+ * is offered if at least one selected entity lacks it (Add applies per-entity). */
+function unionAddableComponents(ids: readonly number[]): ReturnType<typeof modelAddableComponentEntries> {
+ const byName = new Map<string, ReturnType<typeof modelAddableComponentEntries>[number]>();
+ for (const id of ids) {
+ const e = SceneModel.entityBySource(id);
+ if (!e) continue;
+ for (const entry of modelAddableComponentEntries(e)) if (!byName.has(entry.name)) byName.set(entry.name, entry);
+ }
+ return [...byName.values()].sort((a, b) => a.label.localeCompare(b.label));
+}
+
/** Whether a field differs from its reset target (prefab base, else class default). */
function isModified(f: InspectorField): boolean {
return f.defaultValue !== undefined && !fieldEqual(f.value, f.defaultValue);
@@ -3167,7 +3179,10 @@ function EditorDetails() {
)}
{addOpen && modelEntity && (
<AddComponentMenu
- entries={modelAddableComponentEntries(modelEntity)}
+ // Multi-select: offer any component addable to AT LEAST ONE selected entity
+ // (the union), since Add applies to every entity that lacks it. Using only
+ // the primary's addable set hid components the primary already had.
+ entries={multi ? unionAddableComponents(ids) : modelAddableComponentEntries(modelEntity)}
onAdd={(name) => SceneCommands.addComponentMany(ids, name)}
onClose={() => setAddOpen(false)}
/>