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.

feat(editor): Content Browser multi-select + batch delete

yhh1ff3edf37fcd
diff --git a/desktop/src/i18n/messages/content.ts b/desktop/src/i18n/messages/content.ts
index 29dc7f441..0a41a6453 100644
--- a/desktop/src/i18n/messages/content.ts
+++ b/desktop/src/i18n/messages/content.ts
@@ -100,6 +100,10 @@ export const contentMessages = defineMessages({
en: 'Delete “{name}”? It will be moved to the trash.',
zh: '确定删除“{name}”?它将被移入回收站。',
},
+ 'cb.deleteBodyMany': {
+ en: 'Delete {count} items? They will be moved to the trash.',
+ zh: '确定删除 {count} 项?它们将被移入回收站。',
+ },
'cb.deleteRefListOne': {
en: 'It is referenced by {count} document; that reference will break:',
zh: '它被 {count} 个文档引用;该引用将会失效:',
@@ -110,6 +114,7 @@ export const contentMessages = defineMessages({
},
'cb.usagesMore': { en: '…and {count} more', zh: '……以及另外 {count} 个' },
'cb.deletedName': { en: 'Deleted “{name}”', zh: '已删除“{name}”' },
+ 'cb.deletedCount': { en: 'Deleted {count} items', zh: '已删除 {count} 项' },
'cb.menuFindUsages': { en: 'Find Usages', zh: '查找引用' },
'cb.findUsagesTitle': { en: 'Usages of “{name}”', zh: '“{name}”的引用' },
'cb.findUsagesScanning': { en: 'Scanning…', zh: '正在扫描……' },
diff --git a/desktop/src/panels/ContentBrowser.tsx b/desktop/src/panels/ContentBrowser.tsx
index bfdbc1c5a..09909d547 100644
--- a/desktop/src/panels/ContentBrowser.tsx
+++ b/desktop/src/panels/ContentBrowser.tsx
@@ -323,7 +323,10 @@ export function ContentBrowser() {
// Asset selection lives in the shared store (unified inspector): selecting an
// asset drives the Details panel + clears any entity selection.
const selected = useSelection((s) => s.selectedAsset);
+ const selectedAssets = useSelection((s) => s.selectedAssets);
const selectAsset = useSelection((s) => s.selectAsset);
+ const toggleAsset = useSelection((s) => s.toggleAsset);
+ const selectAssets = useSelection((s) => s.selectAssets);
const [view, setView] = useState<'grid' | 'list'>('grid');
const [tileSize, setTileSize] = useState<number>(() => {
const v = Number(localStorage.getItem(TILE_KEY));
@@ -502,40 +505,52 @@ export function ContentBrowser() {
// Delete = themed confirm (Enter confirms, Esc cancels) → trash. The dialog
// body lists WHICH scenes/prefabs reference the asset (disk dep graph + the
// unsaved in-memory scene — a ref added since the last save would break too).
- const [confirmDel, setConfirmDel] = useState<{ path: string; name: string; usages: AssetUsage[] } | null>(null);
+ const [confirmDel, setConfirmDel] = useState<{ paths: string[]; names: string[]; usages: AssetUsage[] } | null>(null);
const [usagesPath, setUsagesPath] = useState<string | null>(null);
- const remove = async (path: string, name: string) => {
- let usages: AssetUsage[] = [];
- try {
- usages = await findAssetUsages(path);
- } catch {
- // Best-effort: if the scan fails, confirm without the reference warning.
+ // Confirm deletion of one OR many assets (multi-select) behind a SINGLE dialog —
+ // aggregating each one's references so nothing gets deleted out from under a scene.
+ const remove = async (paths: string[]) => {
+ if (paths.length === 0) return;
+ const usages: AssetUsage[] = [];
+ for (const p of paths) {
+ try {
+ usages.push(...(await findAssetUsages(p)));
+ } catch {
+ // Best-effort: if the scan fails, confirm without that asset's warning.
+ }
}
- setConfirmDel({ path, name, usages });
+ setConfirmDel({ paths, names: paths.map((p) => baseName(p)), usages });
};
const doRemove = async () => {
const target = confirmDel;
setConfirmDel(null);
if (!target) return;
- try {
- const token = await window.estella.fs.trash(target.path);
- refreshFs();
- if (selected === target.path) selectAsset(null);
- Toasts.push(t('cb.deletedName', { name: target.name }), 'info', 6000, {
- label: t('cb.undo'),
- run: async () => {
+ // Trash each; remember (path, token) pairs so one Undo restores the whole batch.
+ const trashed: { path: string; token: string }[] = [];
+ for (const path of target.paths) {
+ try {
+ trashed.push({ path, token: await window.estella.fs.trash(path) });
+ } catch (e) {
+ Toasts.push(t('cb.deleteFailed', { error: errMsg(e) }), 'error');
+ }
+ }
+ refreshFs();
+ selectAsset(null);
+ if (trashed.length === 0) return;
+ const msg = trashed.length === 1 ? t('cb.deletedName', { name: target.names[0] }) : t('cb.deletedCount', { count: trashed.length });
+ Toasts.push(msg, 'info', 6000, {
+ label: t('cb.undo'),
+ run: async () => {
+ for (const { path, token } of trashed) {
try {
- await window.estella.fs.restoreTrashed(target.path, token);
- refreshFs();
- selectAsset(target.path);
+ await window.estella.fs.restoreTrashed(path, token);
} catch (e) {
Toasts.push(t('cb.undoFailed', { error: errMsg(e) }), 'error');
}
- },
- });
- } catch (e) {
- Toasts.push(t('cb.deleteFailed', { error: errMsg(e) }), 'error');
- }
+ }
+ refreshFs();
+ },
+ });
};
// Keyboard, scoped to the focused item area (it carries tabIndex, so clicking a
@@ -556,10 +571,12 @@ export function ContentBrowser() {
const el = e.target as HTMLElement;
if (el.tagName === 'INPUT' || renaming != null) return; // typing / inline rename
const idx = items.findIndex((it) => it.path === selected);
- const focusIndex = (i: number) => {
+ const focusIndex = (i: number, extend = false) => {
const it = items[Math.max(0, Math.min(items.length - 1, i))];
if (!it) return;
- selectAsset(it.path);
+ // Shift+arrow grows the multi-selection to the new item; plain arrow replaces.
+ if (extend) selectAssets([...new Set([...selectedAssets, it.path])], it.path);
+ else selectAsset(it.path);
requestAnimationFrame(() => {
scrollRef.current
?.querySelector(`[data-path="${CSS.escape(it.path)}"]`)
@@ -576,7 +593,7 @@ export function ContentBrowser() {
const rowStep = view === 'grid' ? gridColumns() : 1;
const step =
e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : e.key === 'ArrowDown' ? rowStep : -rowStep;
- focusIndex(idx < 0 ? 0 : idx + step);
+ focusIndex(idx < 0 ? 0 : idx + step, e.shiftKey);
break;
}
case 'Home': {
@@ -610,8 +627,19 @@ export function ContentBrowser() {
case 'Backspace': {
e.preventDefault();
e.stopPropagation();
- const it = items[idx];
- if (it) void remove(it.path, it.name);
+ // Delete the whole multi-selection at once (one confirm), else the focused item.
+ const paths = selectedAssets.size > 0 ? [...selectedAssets] : items[idx] ? [items[idx].path] : [];
+ if (paths.length) void remove(paths);
+ break;
+ }
+ case 'a':
+ case 'A': {
+ if (e.ctrlKey || e.metaKey) {
+ e.preventDefault();
+ e.stopPropagation(); // select all IN the browser, not the scene's entities
+ const paths = items.map((it) => it.path);
+ if (paths.length) selectAssets(paths, paths[paths.length - 1]);
+ }
break;
}
case 'd':
@@ -851,7 +879,20 @@ export function ContentBrowser() {
clearDropState();
setDragPath(null);
},
- onClick: () => selectAsset(path),
+ // Ctrl/Cmd toggles one item; Shift ranges from the primary; plain replaces —
+ // the Outliner's multi-select gestures, so batch file ops are possible.
+ onClick: (ev: React.MouseEvent) => {
+ if (ev.ctrlKey || ev.metaKey) return toggleAsset(path);
+ if (ev.shiftKey && selected) {
+ const a = items.findIndex((it) => it.path === selected);
+ const b = items.findIndex((it) => it.path === path);
+ if (a >= 0 && b >= 0) {
+ const [lo, hi] = a < b ? [a, b] : [b, a];
+ return selectAssets(items.slice(lo, hi + 1).map((it) => it.path), path);
+ }
+ }
+ selectAsset(path);
+ },
onDoubleClick: () => onOpen(path, e.isDir, e.name),
// Suppress the hover card while any inline rename is active.
...(renaming ? null : tip.bind({ path, entry: e })),
@@ -936,7 +977,7 @@ export function ContentBrowser() {
...(entry.isDir ? [] : [{ label: t('cb.menuFindUsages'), onClick: () => setUsagesPath(path) }]),
{ label: t('cb.menuShowInExplorer'), onClick: () => void showInExplorer(path) },
{ sep: true },
- { label: t('ui.delete'), danger: true, onClick: () => void remove(path, entry.name) },
+ { label: t('ui.delete'), danger: true, onClick: () => void remove(selectedAssets.has(path) && selectedAssets.size > 1 ? [...selectedAssets] : [path]) },
];
})();
@@ -1108,7 +1149,7 @@ export function ContentBrowser() {
<div
key={path}
data-path={path}
- className={`asset${it.isDir ? ' folder' : ''}${selected === path ? ' sel' : ''}${it.isDir && dropFolder === path ? ' is-drop' : ''}${dragPath === path ? ' is-dragging' : ''}`}
+ className={`asset${it.isDir ? ' folder' : ''}${selectedAssets.has(path) ? ' sel' : ''}${it.isDir && dropFolder === path ? ' is-drop' : ''}${dragPath === path ? ' is-dragging' : ''}`}
// Files drag onto inspector asset fields / the viewport (assign / instantiate);
// folders are drop targets that move the dragged asset into them.
{...bindItem(path, it)}
@@ -1174,7 +1215,7 @@ export function ContentBrowser() {
<div
key={path}
data-path={path}
- className={`lr${selected === path ? ' sel' : ''}${it.isDir && dropFolder === path ? ' is-drop' : ''}${dragPath === path ? ' is-dragging' : ''}`}
+ className={`lr${selectedAssets.has(path) ? ' sel' : ''}${it.isDir && dropFolder === path ? ' is-drop' : ''}${dragPath === path ? ' is-dragging' : ''}`}
{...bindItem(path, it)}
{...(it.isDir ? folderDrop(path) : null)}
>
@@ -1234,7 +1275,9 @@ export function ContentBrowser() {
confirmLabel={t('ui.delete')}
body={
<>
- {t('cb.deleteBody', { name: confirmDel.name })}
+ {confirmDel.paths.length === 1
+ ? t('cb.deleteBody', { name: confirmDel.names[0] })
+ : t('cb.deleteBodyMany', { count: confirmDel.paths.length })}
{confirmDel.usages.length > 0 && (
<>
{'\n\n' +
diff --git a/desktop/src/store/selectionStore.ts b/desktop/src/store/selectionStore.ts
index 05fe052e1..c66227eef 100644
--- a/desktop/src/store/selectionStore.ts
+++ b/desktop/src/store/selectionStore.ts
@@ -26,8 +26,12 @@ import type { EntityId, InspectSource } from '@/types';
interface SelectionState {
selectedId: EntityId | null;
selectedIds: Set<EntityId>;
- /** The selected asset (project-relative path), mutually exclusive with entities. */
+ /** The PRIMARY selected asset (project-relative path), mutually exclusive with
+ * entities — drives the unified inspector. */
selectedAsset: string | null;
+ /** The full multi-asset selection (Content Browser ctrl/shift-select). Batch
+ * file ops (delete/move) act over this; the inspector shows `selectedAsset`. */
+ selectedAssets: Set<string>;
/** Replace the selection with a single entity (or clear it with null). */
select: (id: EntityId | null) => void;
/** Ctrl/Cmd-click: add/remove one entity from the selection. */
@@ -36,6 +40,10 @@ interface SelectionState {
selectMany: (ids: EntityId[], primary: EntityId) => void;
/** Select an asset (or clear with null); clears any entity selection. */
selectAsset: (path: string | null) => void;
+ /** Ctrl/Cmd-click an asset: add/remove it from the multi-asset selection. */
+ toggleAsset: (path: string) => void;
+ /** Shift-click / select-all assets: replace the asset set, with a primary. */
+ selectAssets: (paths: string[], primary: string) => void;
/**
* An editor-context inspection source (the open timeline's clip settings, a
* track…), shown in Details as a FALLBACK when nothing else is selected — it
@@ -62,6 +70,7 @@ export function createSelectionStore(model: SceneModelImpl) {
selectedId: null,
selectedIds: new Set<EntityId>(),
selectedAsset: null,
+ selectedAssets: new Set<string>(),
inspectSource: null,
setInspectSource: (inspectSource) => set({ inspectSource }),
@@ -72,6 +81,7 @@ export function createSelectionStore(model: SceneModelImpl) {
selectedId,
selectedIds: selectedId != null ? new Set([selectedId]) : new Set(),
selectedAsset: null,
+ selectedAssets: new Set(),
}),
),
@@ -83,19 +93,38 @@ export function createSelectionStore(model: SceneModelImpl) {
next.delete(id);
const primary =
s.selectedId === id ? (next.size ? [...next][next.size - 1] : null) : s.selectedId;
- return { selectedIds: next, selectedId: primary, selectedAsset: null };
+ return { selectedIds: next, selectedId: primary, selectedAsset: null, selectedAssets: new Set() };
}
next.add(id);
- return { selectedIds: next, selectedId: id, selectedAsset: null };
+ return { selectedIds: next, selectedId: id, selectedAsset: null, selectedAssets: new Set() };
}),
),
selectMany: (ids, primary) =>
- PerfMonitor.measure('select', () => set({ selectedIds: new Set(ids), selectedId: primary, selectedAsset: null })),
+ PerfMonitor.measure('select', () => set({ selectedIds: new Set(ids), selectedId: primary, selectedAsset: null, selectedAssets: new Set() })),
// Selecting an asset clears any entity selection (mutually exclusive).
selectAsset: (selectedAsset) =>
- PerfMonitor.measure('select', () => set({ selectedAsset, selectedId: null, selectedIds: new Set() })),
+ PerfMonitor.measure('select', () =>
+ set({ selectedAsset, selectedAssets: selectedAsset ? new Set([selectedAsset]) : new Set(), selectedId: null, selectedIds: new Set() })),
+
+ toggleAsset: (path) =>
+ PerfMonitor.measure('select', () =>
+ set((s) => {
+ const next = new Set(s.selectedAssets);
+ if (next.has(path)) {
+ next.delete(path);
+ const primary =
+ s.selectedAsset === path ? (next.size ? [...next][next.size - 1] : null) : s.selectedAsset;
+ return { selectedAssets: next, selectedAsset: primary, selectedId: null, selectedIds: new Set() };
+ }
+ next.add(path);
+ return { selectedAssets: next, selectedAsset: path, selectedId: null, selectedIds: new Set() };
+ }),
+ ),
+
+ selectAssets: (paths, primary) =>
+ PerfMonitor.measure('select', () => set({ selectedAssets: new Set(paths), selectedAsset: primary, selectedId: null, selectedIds: new Set() })),
dropId: (id) =>
set((s) => {