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(content): project-wide recursive search + drag-move assets into folders

esengine7941333720f6
diff --git a/desktop/electron/main.ts b/desktop/electron/main.ts
index 6fefbb026..2ad9601af 100644
--- a/desktop/electron/main.ts
+++ b/desktop/electron/main.ts
@@ -11,6 +11,7 @@ import {
readInRoot,
writeInRoot,
readDirInRoot,
+ listFilesInRoot,
renameInRoot,
mkdirInRoot,
duplicateInRoot,
@@ -245,6 +246,7 @@ ipcMain.handle('fs:write', (_e, relPath: string, contents: string) =>
writeInRoot(requireRoot(), relPath, contents),
);
ipcMain.handle('fs:readdir', (_e, relPath: string) => readDirInRoot(requireRoot(), relPath));
+ipcMain.handle('fs:listFiles', (_e, relDir: string) => listFilesInRoot(requireRoot(), relDir));
ipcMain.handle('fs:rename', (_e, fromRel: string, toRel: string) =>
renameInRoot(requireRoot(), fromRel, toRel),
);
diff --git a/desktop/electron/preload.ts b/desktop/electron/preload.ts
index 426b17f13..c1152ac0b 100644
--- a/desktop/electron/preload.ts
+++ b/desktop/electron/preload.ts
@@ -86,6 +86,8 @@ const api = {
write: (relPath: string, contents: string): Promise<void> =>
ipcRenderer.invoke('fs:write', relPath, contents),
readDir: (relPath: string): Promise<DirEntry[]> => ipcRenderer.invoke('fs:readdir', relPath),
+ /** Project-relative paths of every browsable file under `relDir`, recursively. */
+ listFiles: (relDir: string): Promise<string[]> => ipcRenderer.invoke('fs:listFiles', relDir),
/** Rename / move; a file's `.meta` sidecar travels with it (identity stable). */
rename: (fromRel: string, toRel: string): Promise<void> =>
ipcRenderer.invoke('fs:rename', fromRel, toRel),
diff --git a/desktop/electron/projectFs.ts b/desktop/electron/projectFs.ts
index 53b67eb19..d86b7e1a5 100644
--- a/desktop/electron/projectFs.ts
+++ b/desktop/electron/projectFs.ts
@@ -92,6 +92,25 @@ async function* walkFiles(absDir: string): AsyncGenerator<string> {
}
}
+// Recursively yield project-relative paths of visible files (skips dot dirs/files —
+// `.esengine`, `.meta` sidecars — that aren't browsable assets).
+async function* walkVisible(absDir: string, root: string): AsyncGenerator<string> {
+ for (const e of await readdir(absDir, { withFileTypes: true })) {
+ if (e.name.startsWith('.')) continue;
+ const p = path.join(absDir, e.name);
+ if (e.isDirectory()) yield* walkVisible(p, root);
+ else if (!e.name.endsWith(META_EXT)) yield toRel(root, p);
+ }
+}
+
+/** Project-relative paths of every browsable file under `relDir`, recursively —
+ * backs the Content Browser's project-wide (subtree) search. */
+export async function listFilesInRoot(root: string, relDir: string): Promise<string[]> {
+ const out: string[] = [];
+ for await (const rel of walkVisible(resolveInRoot(root, relDir), root)) out.push(rel);
+ return out;
+}
+
/**
* Rename / move a file or folder within the project. A file's `.meta` sidecar
* travels with it so rename preserves asset identity (uuid). Refuses to clobber
diff --git a/desktop/src/panels/ContentBrowser.tsx b/desktop/src/panels/ContentBrowser.tsx
index 9dfabb35d..cf1c1d5ff 100644
--- a/desktop/src/panels/ContentBrowser.tsx
+++ b/desktop/src/panels/ContentBrowser.tsx
@@ -156,6 +156,14 @@ function AssetTipCard({ path, entry }: { path: string; entry: DirEntry }) {
}
const join = (dir: string, name: string) => (dir ? `${dir}/${name}` : name);
+
+// A browser row: an entry plus its full project-relative path. Folder-view rows
+// derive the path from cwd; recursive-search rows carry their own (cross-folder) path.
+interface Row {
+ path: string;
+ name: string;
+ isDir: boolean;
+}
const parentOf = (p: string) => (p.includes('/') ? p.slice(0, p.lastIndexOf('/')) : '');
// Folder navigation with a back/forward history (the breadcrumb nav arrows).
@@ -266,9 +274,37 @@ export function ContentBrowser() {
// Search supports `type:`/`t:` tokens + free text; the type chips add to the
// token constraint; sort is folders-first, then by name or type.
const parsed = useMemo(() => parseAssetQuery(query), [query]);
+ // With a non-empty query, search the whole cwd subtree (flat, project-wide-style);
+ // otherwise list just the current folder. The recursive file list is fetched
+ // main-side and refreshed on fs mutations (same signal useDir rides).
+ const searching = q.length > 0;
+ const fsVersion = useSyncExternalStore(fsRefresh.subscribe, fsRefresh.get);
+ const [allFiles, setAllFiles] = useState<string[]>([]);
+ useEffect(() => {
+ if (!project || !searching) {
+ setAllFiles([]);
+ return;
+ }
+ let alive = true;
+ window.estella.fs
+ .listFiles(cwd)
+ .then((f) => alive && setAllFiles(f))
+ .catch(() => alive && setAllFiles([]));
+ return () => {
+ alive = false;
+ };
+ }, [project, cwd, searching, fsVersion]);
+
+ const rows = useMemo<Row[]>(
+ () =>
+ searching
+ ? allFiles.map((p) => ({ path: p, name: p.split('/').pop() ?? p, isDir: false }))
+ : entries.map((e) => ({ path: join(cwd, e.name), name: e.name, isDir: e.isDir })),
+ [searching, allFiles, entries, cwd],
+ );
const items = useMemo(
- () => filterAndSortAssets(entries, parsed, filters as ReadonlySet<string>, sort, assetType),
- [entries, parsed, filters, sort],
+ () => filterAndSortAssets(rows, parsed, filters as ReadonlySet<string>, sort, assetType),
+ [rows, parsed, filters, sort],
);
// Double-click: enter folders; otherwise dispatch through the per-type open
@@ -416,6 +452,39 @@ export function ContentBrowser() {
.catch((err) => Toasts.push(`Import failed: ${errMsg(err)}`, 'error'));
};
+ // Move an asset into a folder (drag onto a folder tile / tree node). Rename moves
+ // the `.meta` sidecar too, so uuid refs survive; rejects no-op and self/descendant
+ // moves. Refs are uuid-based, so nothing referencing the asset breaks.
+ const moveAssetToFolder = async (srcPath: string, folderPath: string) => {
+ const name = srcPath.split('/').pop();
+ if (!name) return;
+ const dest = join(folderPath, name);
+ if (dest === srcPath || srcPath === folderPath || folderPath.startsWith(`${srcPath}/`)) return;
+ try {
+ await window.estella.fs.rename(srcPath, dest);
+ refreshFs();
+ if (selected === srcPath) selectAsset(dest);
+ } catch (e) {
+ Toasts.push(`Move failed: ${errMsg(e)}`, 'error');
+ }
+ };
+
+ // Drop-target props for a folder (tile or tree node): accept internal asset drags.
+ const folderDrop = (folderPath: string) => ({
+ onDragOver: (e: React.DragEvent) => {
+ if (!e.dataTransfer.types.includes('application/x-estella-asset')) return;
+ e.preventDefault();
+ e.dataTransfer.dropEffect = 'move';
+ },
+ onDrop: (e: React.DragEvent) => {
+ const src = e.dataTransfer.getData('application/x-estella-asset');
+ if (!src) return;
+ e.preventDefault();
+ e.stopPropagation();
+ void moveAssetToFolder(src, folderPath);
+ },
+ });
+
// Breadcrumb segments: Project › folder › subfolder, each a jump target.
const crumbs = useMemo(() => {
const out = [{ name: project?.name ?? 'Project', path: '' }];
@@ -625,16 +694,18 @@ export function ContentBrowser() {
>
{view === 'grid' ? (
<div className="cb-grid" style={{ ['--tile' as string]: `${tileSize}px` } as React.CSSProperties}>
- {items.map((e) => {
- const path = join(cwd, e.name);
- const type: AssetType = e.isDir ? 'folder' : assetType(e.name);
- const isImg = !e.isDir && IMAGE_RE.test(e.name);
+ {items.map((it) => {
+ const path = it.path;
+ const type: AssetType = it.isDir ? 'folder' : assetType(it.name);
+ const isImg = !it.isDir && IMAGE_RE.test(it.name);
return (
<div
- key={e.name}
- className={`asset${e.isDir ? ' folder' : ''}${selected === path ? ' sel' : ''}`}
- // Files drag onto inspector asset fields / the viewport (assign / instantiate).
- {...bindItem(path, e)}
+ key={path}
+ className={`asset${it.isDir ? ' folder' : ''}${selected === path ? ' sel' : ''}`}
+ // Files drag onto inspector asset fields / the viewport (assign / instantiate);
+ // folders are drop targets that move the dragged asset into them.
+ {...bindItem(path, it)}
+ {...(it.isDir ? folderDrop(path) : null)}
>
<div className="th">
{isImg ? (
@@ -642,20 +713,20 @@ export function ContentBrowser() {
) : (
<AssetIcon type={type} size={30} />
)}
- {!e.isDir && TYPE_CODE[type] && <span className="badge">{TYPE_CODE[type]}</span>}
+ {!it.isDir && TYPE_CODE[type] && <span className="badge">{TYPE_CODE[type]}</span>}
</div>
<div
className="nm"
- style={e.isDir ? undefined : ({ ['--tc' as string]: assetTint(type) } as React.CSSProperties)}
+ style={it.isDir ? undefined : ({ ['--tc' as string]: assetTint(type) } as React.CSSProperties)}
>
{renaming === path ? (
<RenameInput
- name={e.name}
+ name={it.name}
onCommit={(v) => void commitRename(path, v)}
onCancel={() => setRenaming(null)}
/>
) : (
- <span>{e.name}</span>
+ <span>{it.name}</span>
)}
</div>
</div>
@@ -673,24 +744,29 @@ export function ContentBrowser() {
<span>Name</span>
<span>Type</span>
</div>
- {items.map((e) => {
- const path = join(cwd, e.name);
- const type: AssetType = e.isDir ? 'folder' : assetType(e.name);
+ {items.map((it) => {
+ const path = it.path;
+ const type: AssetType = it.isDir ? 'folder' : assetType(it.name);
return (
- <div key={e.name} className={`lr${selected === path ? ' sel' : ''}`} {...bindItem(path, e)}>
+ <div
+ key={path}
+ className={`lr${selected === path ? ' sel' : ''}`}
+ {...bindItem(path, it)}
+ {...(it.isDir ? folderDrop(path) : null)}
+ >
<span className="ln">
<AssetIcon type={type} size={15} />
{renaming === path ? (
<RenameInput
- name={e.name}
+ name={it.name}
onCommit={(v) => void commitRename(path, v)}
onCancel={() => setRenaming(null)}
/>
) : (
- <span className="t">{e.name}</span>
+ <span className="t">{it.name}</span>
)}
</span>
- <span className="c">{e.isDir ? '' : TYPE_CODE[type] || type}</span>
+ <span className="c">{it.isDir ? '' : TYPE_CODE[type] || type}</span>
</div>
);
})}
diff --git a/desktop/src/project/assetFilter.ts b/desktop/src/project/assetFilter.ts
index f4ef5e26b..73e85b1b9 100644
--- a/desktop/src/project/assetFilter.ts
+++ b/desktop/src/project/assetFilter.ts
@@ -7,10 +7,14 @@
* order. Kept engine/DOM-free so it unit-tests; the panel just feeds it the
* current folder's entries and renders the result.
*/
-import type { DirEntry } from './format';
-
export type AssetSort = 'name' | 'type';
+/** The minimal row shape the filter/sort needs (name + folder flag). */
+export interface AssetRowLike {
+ name: string;
+ isDir: boolean;
+}
+
export interface ParsedQuery {
/** Free-text terms joined by spaces (name substring match). */
text: string;
@@ -38,13 +42,13 @@ const matchesType = (actual: string, constraint: string): boolean =>
* first, then by name or type). A type constraint (token or chip) is about files,
* so it hides folders; free text still matches folder names (navigation).
*/
-export function filterAndSortAssets(
- entries: readonly DirEntry[],
+export function filterAndSortAssets<T extends AssetRowLike>(
+ entries: readonly T[],
parsed: ParsedQuery,
chipTypes: ReadonlySet<string>,
sort: AssetSort,
typeOf: (name: string) => string,
-): DirEntry[] {
+): T[] {
const constraints = [...new Set([...chipTypes, ...parsed.types])];
const hasType = constraints.length > 0;
diff --git a/desktop/tests/asset-filter.test.ts b/desktop/tests/asset-filter.test.ts
index 5e807127d..33fb58a86 100644
--- a/desktop/tests/asset-filter.test.ts
+++ b/desktop/tests/asset-filter.test.ts
@@ -61,4 +61,13 @@ describe('filterAndSortAssets', () => {
// material, scene, texture, texture — folders first.
expect(run('', [], 'type')).toEqual(['afolder', 'zfolder', 'ground.esmat', 'main.esscene', 'hero.png', 'villain.png']);
});
+
+ it('is generic — preserves extra row fields (e.g. a full path for recursive search)', () => {
+ const rows = [
+ { path: 'a/hero.png', name: 'hero.png', isDir: false },
+ { path: 'b/sub/villain.png', name: 'villain.png', isDir: false },
+ ];
+ const out = filterAndSortAssets(rows, parseAssetQuery('type:texture'), new Set(), 'name', typeOf);
+ expect(out.map((r) => r.path)).toEqual(['a/hero.png', 'b/sub/villain.png']);
+ });
});