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): asset ref fields locate their asset in the Content Browser

yhh4bc0aeee7e21
diff --git a/desktop/src/panels/ContentBrowser.tsx b/desktop/src/panels/ContentBrowser.tsx
index f911d8e39..927a61aac 100644
--- a/desktop/src/panels/ContentBrowser.tsx
+++ b/desktop/src/panels/ContentBrowser.tsx
@@ -18,6 +18,7 @@ import { BUILTIN_SHADER_TEMPLATES } from 'esengine';
import { createMaterial, createMaterialInstance } from '@/material/openMaterial';
import { createMaterialGraph } from '@/material/openMaterialGraph';
import { createStateMachine } from '@/fsm/openStateMachine';
+import { onAssetReveal } from '@/project/assetReveal';
import { createBehaviorTree } from '@/bt/openBehaviorTree';
import { createAnimationClip } from '@/timeline/openClip';
import { fsRefresh } from '@/project/fsWatch';
@@ -276,6 +277,21 @@ export function ContentBrowser() {
// Selection doesn't survive a folder change.
useEffect(() => selectAsset(null), [cwd, selectAsset]);
+ // Cross-panel locate (revealAsset): navigate to the containing folder first;
+ // selection + scroll happen in a second phase once the folder's rows are in
+ // (and after the cwd-change effect above has done its clearing).
+ const [pendingReveal, setPendingReveal] = useState<string | null>(null);
+ useEffect(
+ () =>
+ onAssetReveal((path) => {
+ setQuery('');
+ setFilters(new Set());
+ setPendingReveal(path);
+ go(parentOf(path));
+ }),
+ [go],
+ );
+
const entries = useDir(project ? cwd : null);
const q = query.trim();
// Search supports `type:`/`t:` tokens + free text; the type chips add to the
@@ -314,6 +330,15 @@ export function ContentBrowser() {
[rows, parsed, filters, sort],
);
+ useEffect(() => {
+ if (!pendingReveal || !items.some((it) => it.path === pendingReveal)) return;
+ selectAsset(pendingReveal);
+ setPendingReveal(null);
+ requestAnimationFrame(() => {
+ document.querySelector(`[data-path="${CSS.escape(pendingReveal)}"]`)?.scrollIntoView({ block: 'nearest' });
+ });
+ }, [pendingReveal, items, selectAsset]);
+
// Double-click: enter folders; otherwise dispatch through the per-type open
// table (scene/clip/tileset editors).
const onOpen = (path: string, isDir: boolean, name: string) => {
@@ -742,6 +767,7 @@ export function ContentBrowser() {
return (
<div
key={path}
+ data-path={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.
@@ -791,6 +817,7 @@ export function ContentBrowser() {
return (
<div
key={path}
+ data-path={path}
className={`lr${selected === path ? ' sel' : ''}`}
{...bindItem(path, it)}
{...(it.isDir ? folderDrop(path) : null)}
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index 9944997b6..82c3d375c 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -31,6 +31,7 @@ import {
import { AssetIcon } from '@/components/icons';
import { Toasts } from '@/store/Toasts';
import { baseName, assetTypeOf, IMAGE_RE } from '@/project/assetMeta';
+import { revealAsset } from '@/project/assetReveal';
import { useSelection } from '@/store/selectionStore';
import { useEditorStore } from '@/store/editorStore';
import { useOutliner } from '@/outliner/OutlinerController';
@@ -963,14 +964,23 @@ export function AssetControl({
onDragLeave={() => setOver(false)}
onDrop={onDrop}
>
- <span className="th">
- {assetType === 'texture' && info ? (
- <img src={`estella://project/${info.path}`} alt="" draggable={false} />
- ) : (
- <Box size={11} strokeWidth={1.7} />
- )}
- </span>
- <span className="an">{info ? info.name : 'None'}</span>
+ <button
+ type="button"
+ className="loc"
+ title={info ? `Locate ${info.path} in the Content Browser` : undefined}
+ disabled={!info}
+ onMouseDown={(e) => e.stopPropagation()}
+ onClick={() => info && revealAsset(info.path)}
+ >
+ <span className="th">
+ {assetType === 'texture' && info ? (
+ <img src={`estella://project/${info.path}`} alt="" draggable={false} />
+ ) : (
+ <Box size={11} strokeWidth={1.7} />
+ )}
+ </span>
+ <span className="an">{info ? info.name : 'None'}</span>
+ </button>
<button type="button" className="pk" title="Pick asset" onMouseDown={(e) => e.stopPropagation()} onClick={openPick}>
<Search size={11} strokeWidth={2} />
</button>
diff --git a/desktop/src/project/assetReveal.ts b/desktop/src/project/assetReveal.ts
new file mode 100644
index 000000000..1a61703c6
--- /dev/null
+++ b/desktop/src/project/assetReveal.ts
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file Cross-panel "locate asset" door: anything holding an asset path
+ * (inspector ref fields, log links, …) calls revealAsset; the Content
+ * Browser subscribes and finishes the job (navigate, select, scroll).
+ */
+import { dockApi } from '@/layout/dockApi';
+
+type Listener = (path: string) => void;
+const listeners = new Set<Listener>();
+
+export function onAssetReveal(fn: Listener): () => void {
+ listeners.add(fn);
+ return () => {
+ listeners.delete(fn);
+ };
+}
+
+export function revealAsset(path: string): void {
+ dockApi.revealAndExpand('content');
+ for (const fn of listeners) fn(path);
+}
diff --git a/desktop/src/theme/inspector.css b/desktop/src/theme/inspector.css
index 06f0840bc..7401ac3a9 100644
--- a/desktop/src/theme/inspector.css
+++ b/desktop/src/theme/inspector.css
@@ -214,6 +214,9 @@
.assetref { flex: 1; min-width: 0; height: 22px; display: flex; align-items: center; gap: 6px; padding: 0 6px 0 3px; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); transition: border-color var(--t-fast); cursor: pointer; }
.assetref:hover { border-color: var(--border-line); }
.assetref.is-over { border-color: var(--acc); background: var(--acc-soft); }
+.assetref .loc { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; text-align: left; }
+.assetref .loc:disabled { cursor: default; }
+.assetref .loc:not(:disabled):hover .an { color: var(--acc-hi); text-decoration: underline; text-underline-offset: 2px; }
.assetref .th { width: 16px; height: 16px; border-radius: 2px; background: var(--srf-4); display: grid; place-items: center; color: var(--text-mute); flex-shrink: 0; overflow: hidden; }
.assetref .th img { width: 100%; height: 100%; object-fit: contain; }
.assetref .an { flex: 1; font-size: var(--fs-xs); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }