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(outliner): UE5 interaction parity — reveal-on-select, keyboard nav, token search

esenginebd202b47ade7
diff --git a/desktop/src/components/VirtualTree.tsx b/desktop/src/components/VirtualTree.tsx
index d4d8c2e92..d339e55e8 100644
--- a/desktop/src/components/VirtualTree.tsx
+++ b/desktop/src/components/VirtualTree.tsx
@@ -28,6 +28,10 @@ interface VirtualTreeProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, 'chil
overscan?: number;
renderRow: (item: T, index: number) => ReactNode;
getKey: (item: T, index: number) => Key;
+ /** Row index to scroll into view (only if off-screen); paired with `scrollNonce`. */
+ scrollToIndex?: number;
+ /** Bump to re-trigger a scroll to the SAME index (controlled imperative scroll). */
+ scrollNonce?: number;
}
export function VirtualTree<T>({
@@ -36,6 +40,8 @@ export function VirtualTree<T>({
overscan = 8,
renderRow,
getKey,
+ scrollToIndex,
+ scrollNonce,
onScroll,
...rest
}: VirtualTreeProps<T>) {
@@ -53,6 +59,18 @@ export function VirtualTree<T>({
return () => ro.disconnect();
}, []);
+ // Controlled scroll-into-view (reveal-on-select / keyboard nav): only moves when
+ // the target row is outside the window, so an in-view selection never jumps.
+ useEffect(() => {
+ const el = scrollRef.current;
+ if (!el || scrollToIndex == null || scrollToIndex < 0) return;
+ const top = scrollToIndex * rowHeight;
+ const bottom = top + rowHeight;
+ if (top < el.scrollTop) el.scrollTop = top;
+ else if (bottom > el.scrollTop + el.clientHeight) el.scrollTop = bottom - el.clientHeight;
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [scrollNonce]);
+
const total = items.length;
const start = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan);
const end = Math.min(total, Math.ceil((scrollTop + viewH) / rowHeight) + overscan);
diff --git a/desktop/src/outliner/OutlinerController.ts b/desktop/src/outliner/OutlinerController.ts
index d236964a5..1fa5b2d0f 100644
--- a/desktop/src/outliner/OutlinerController.ts
+++ b/desktop/src/outliner/OutlinerController.ts
@@ -25,6 +25,8 @@ interface OutlinerState {
expanded: Set<string>;
/** Live name filter (raw text; the builder trims/lowercases). */
query: string;
+ /** Keyboard-focus row (item key) — drives ↑↓←→ navigation; null = none. */
+ cursor: string | null;
/** Flip one row's expansion (pass an item key). */
toggleExpanded: (key: string) => void;
@@ -37,6 +39,8 @@ interface OutlinerState {
/** Rewrite expanded folder keys when a folder is renamed/moved (keep it open). */
rebaseFolderKeys: (oldPath: string, newPath: string) => void;
setQuery: (query: string) => void;
+ /** Move the keyboard-focus row. */
+ setCursor: (key: string | null) => void;
/** Prune a removed entity's key (self-heal on the model's `entityRemoved`). */
dropId: (id: EntityId) => void;
@@ -49,6 +53,7 @@ export function createOutlinerStore(model: SceneModelImpl) {
const useStore = create<OutlinerState>((set) => ({
expanded: new Set<string>(),
query: '',
+ cursor: null,
toggleExpanded: (key) =>
set((s) => {
@@ -95,16 +100,18 @@ export function createOutlinerStore(model: SceneModelImpl) {
return { expanded: next };
}),
setQuery: (query) => set({ query }),
+ setCursor: (cursor) => set({ cursor }),
dropId: (id) =>
set((s) => {
const k = entityKey(id);
- if (!s.expanded.has(k)) return s;
+ const cursor = s.cursor === k ? null : s.cursor;
+ if (!s.expanded.has(k)) return s.cursor === k ? { cursor } : s;
const next = new Set(s.expanded);
next.delete(k);
- return { expanded: next };
+ return { expanded: next, cursor };
}),
- reset: () => set({ expanded: new Set(), query: '' }),
+ reset: () => set({ expanded: new Set(), query: '', cursor: null }),
}));
model.subscribe((ev) => {
diff --git a/desktop/src/outliner/OutlinerModel.ts b/desktop/src/outliner/OutlinerModel.ts
index 9c8baf73f..85ef7cd45 100644
--- a/desktop/src/outliner/OutlinerModel.ts
+++ b/desktop/src/outliner/OutlinerModel.ts
@@ -65,11 +65,40 @@ export interface BuildOutlinerOpts {
expandAll?: boolean;
}
-/** Keep a node if its name matches, or any descendant does (matches + ancestors). */
-function filterNode(node: SceneNode, q: string): SceneNode | null {
- if (node.name.toLowerCase().includes(q)) return node;
+/** A parsed search query: bare-word name text + `type:`/`comp:` token filters. */
+export interface ParsedQuery {
+ /** Bare words joined — the name substring + highlight target. */
+ text: string;
+ /** `type:`/`t:` values, matched against a node's kind (OR). */
+ types: string[];
+ /** `comp:`/`c:` values, matched against an entity's component types (OR). */
+ comps: string[];
+}
+
+/** Tokenize a query: `type:sprite comp:RigidBody name` → typed filters + bare text. */
+export function parseQuery(raw: string): ParsedQuery {
+ const text: string[] = [];
+ const types: string[] = [];
+ const comps: string[] = [];
+ for (const tok of (raw ?? '').trim().toLowerCase().split(/\s+/)) {
+ if (!tok) continue;
+ const colon = tok.indexOf(':');
+ const key = colon > 0 ? tok.slice(0, colon) : '';
+ const val = colon > 0 ? tok.slice(colon + 1) : '';
+ if (val && (key === 'type' || key === 't')) types.push(val);
+ else if (val && (key === 'comp' || key === 'c')) comps.push(val);
+ else text.push(tok);
+ }
+ return { text: text.join(' '), types, comps };
+}
+
+const queryActive = (q: ParsedQuery): boolean => q.text !== '' || q.types.length > 0 || q.comps.length > 0;
+
+/** Keep a node if it matches `keep`, or any descendant does (matches + ancestors). */
+function filterNode(node: SceneNode, keep: (n: SceneNode) => boolean): SceneNode | null {
+ if (keep(node)) return node; // self matches → keep the whole subtree
const kids = (node.children ?? [])
- .map((c) => filterNode(c, q))
+ .map((c) => filterNode(c, keep))
.filter((n): n is SceneNode => n != null);
return kids.length ? { ...node, children: kids } : null;
}
@@ -77,9 +106,23 @@ function filterNode(node: SceneNode, q: string): SceneNode | null {
/** Flatten a SceneData to render-ordered outliner rows (the single tree builder). */
export function buildOutlinerItems(data: SceneData | null, opts: BuildOutlinerOpts): OutlinerItem[] {
const roots = buildSceneTree(data);
- const q = opts.query?.trim().toLowerCase() ?? '';
- const shown = q ? roots.map((n) => filterNode(n, q)).filter((n): n is SceneNode => n != null) : roots;
- const expandAll = !!opts.expandAll || !!q;
+ const q = parseQuery(opts.query ?? '');
+ const active = queryActive(q);
+ // Component lookup only when a `comp:` token is present (else skip the scan).
+ const compsOf = q.comps.length
+ ? new Map((data?.entities ?? []).map((e) => [e.id, e.components.map((c) => c.type.toLowerCase())]))
+ : null;
+ const keep = (n: SceneNode): boolean => {
+ if (q.text && !n.name.toLowerCase().includes(q.text)) return false;
+ if (q.types.length && !q.types.includes(n.kind)) return false;
+ if (q.comps.length) {
+ const cs = compsOf?.get(n.id) ?? [];
+ if (!q.comps.some((c) => cs.includes(c))) return false;
+ }
+ return true;
+ };
+ const shown = active ? roots.map((n) => filterNode(n, keep)).filter((n): n is SceneNode => n != null) : roots;
+ const expandAll = !!opts.expandAll || active;
const folderOf = opts.folderOf ?? (() => ROOT_FOLDER);
// Group the shown roots by their folder path, and gather every folder to show:
@@ -92,7 +135,7 @@ export function buildOutlinerItems(data: SceneData | null, opts: BuildOutlinerOp
(rootsByFolder.get(path) ?? rootsByFolder.set(path, []).get(path)!).push(root);
for (const pre of folderPrefixes(path)) allFolders.add(pre);
}
- if (!q) for (const f of opts.folders ?? []) for (const pre of folderPrefixes(normalizeFolder(f))) allFolders.add(pre);
+ if (!active) for (const f of opts.folders ?? []) for (const pre of folderPrefixes(normalizeFolder(f))) allFolders.add(pre);
const childFolders = (path: string): string[] =>
[...allFolders].filter((p) => folderParent(p) === path).sort((a, b) => folderName(a).localeCompare(folderName(b)));
diff --git a/desktop/src/outliner/OutlinerRow.tsx b/desktop/src/outliner/OutlinerRow.tsx
index c5089a8a3..bf5efc4f1 100644
--- a/desktop/src/outliner/OutlinerRow.tsx
+++ b/desktop/src/outliner/OutlinerRow.tsx
@@ -12,9 +12,24 @@
import type React from 'react';
import { ChevronRight, Eye, EyeOff, Lock, LockOpen, Folder, FolderOpen } from 'lucide-react';
import { NodeIcon } from '@/components/icons';
+import type { ReactNode } from 'react';
import type { EntityId, NodeKind } from '@/types';
import type { OutlinerItem } from './OutlinerModel';
+/** Wrap the first case-insensitive match of `hl` in the name with a highlight. */
+function highlightName(name: string, hl?: string): ReactNode {
+ if (!hl) return name;
+ const i = name.toLowerCase().indexOf(hl);
+ if (i < 0) return name;
+ return (
+ <>
+ {name.slice(0, i)}
+ <mark>{name.slice(i, i + hl.length)}</mark>
+ {name.slice(i + hl.length)}
+ </>
+ );
+}
+
/** Entity kind → the label shown in the outliner's right-hand "Type" column. */
const KIND_TYPE: Record<NodeKind, string> = {
camera: 'Camera',
@@ -32,6 +47,10 @@ export interface OutlinerRowProps {
item: OutlinerItem;
/** Entity selection highlight (folders never carry entity selection). */
selected: boolean;
+ /** Keyboard-focus row (shows a focus ring; distinct from selection). */
+ cursored?: boolean;
+ /** Lowercased substring to highlight in the name (the search bare text). */
+ highlight?: string;
renaming?: boolean;
isDrop?: boolean;
/** Prefab-instance member — warm icon tint (entity rows only). */
@@ -82,6 +101,7 @@ export function OutlinerRow(props: OutlinerRowProps) {
<div
className={
`row${selected ? ' sel' : ''}` +
+ `${props.cursored ? ' cursor' : ''}` +
`${expanded ? ' open' : ''}` +
`${visible ? '' : ' hidden'}` +
`${locked ? ' locked' : ''}` +
@@ -137,7 +157,7 @@ export function OutlinerRow(props: OutlinerRowProps) {
className="rname"
onDoubleClick={canRename && props.onStartRename ? () => props.onStartRename!(item) : undefined}
>
- {name}
+ {highlightName(name, props.highlight)}
</span>
)}
diff --git a/desktop/src/panels/Outliner.tsx b/desktop/src/panels/Outliner.tsx
index 241febb5f..29bc4526e 100644
--- a/desktop/src/panels/Outliner.tsx
+++ b/desktop/src/panels/Outliner.tsx
@@ -12,7 +12,7 @@ import { PlayInspect } from '@/engine/PlayInspect';
import { ProjectStore } from '@/project/ProjectStore';
import { ContextMenu, type MenuItem } from '@/components/Menu';
import { VirtualTree } from '@/components/VirtualTree';
-import { buildOutlinerItems, collectExpandableKeys, entityKey, folderKey, type OutlinerItem } from '@/outliner/OutlinerModel';
+import { buildOutlinerItems, collectExpandableKeys, entityKey, folderKey, parseQuery, type OutlinerItem } from '@/outliner/OutlinerModel';
import { useOutliner } from '@/outliner/OutlinerController';
import { OutlinerRow } from '@/outliner/OutlinerRow';
import { joinFolder, folderParent } from '@/outliner/folders';
@@ -69,7 +69,9 @@ export function Outliner() {
const query = useOutliner((s) => s.query);
const setQuery = useOutliner((s) => s.setQuery);
const toggleExpanded = useOutliner((s) => s.toggleExpanded);
+ const cursor = useOutliner((s) => s.cursor);
const selectedIds = useSelection((s) => s.selectedIds);
+ const selectedId = useSelection((s) => s.selectedId);
const isPlaying = useEditorStore((s) => s.isPlaying);
const inspectWorld = useEditorStore((s) => s.inspectWorld);
const setInspectWorld = useEditorStore((s) => s.setInspectWorld);
@@ -79,6 +81,10 @@ export function Outliner() {
const [renaming, setRenaming] = useState<string | null>(null); // item key
const [dropId, setDropId] = useState<string | null>(null); // item key
const [ctx, setCtx] = useState<{ x: number; y: number; item: OutlinerItem } | null>(null);
+ // Controlled scroll for reveal-on-select + keyboard nav (nonce re-fires same index).
+ const [scrollTo, setScrollTo] = useState<{ index: number; nonce: number }>({ index: -1, nonce: 0 });
+ const scrollNonce = useRef(0);
+ const scrollToIndex = (index: number) => setScrollTo({ index, nonce: ++scrollNonce.current });
const sceneCount = useMemo(
() => (engine.status === 'ready' ? (SceneModel.current?.entities.length ?? 0) : 0),
@@ -97,6 +103,7 @@ export function Outliner() {
[engine.status, structRev, expanded, query],
);
const flatIds = useMemo(() => entityIds(items), [items]);
+ const highlight = useMemo(() => parseQuery(query).text, [query]);
// First time entities appear: expand groups + folders, select the first entity.
useEffect(() => {
@@ -113,7 +120,91 @@ export function Outliner() {
const select = (id: EntityId | null) => useSelection.getState().select(id);
+ // Reveal-on-select: when the primary selection changes (e.g. a viewport pick),
+ // expand its ancestors + folder and scroll it into view. If it isn't in the flat
+ // list yet (ancestors collapsed), expand once — items rebuild and this re-runs.
+ const handledSel = useRef<EntityId | null>(null);
+ const expandedSel = useRef<EntityId | null>(null);
+ useEffect(() => {
+ if (selectedId == null) {
+ handledSel.current = expandedSel.current = null;
+ return;
+ }
+ if (handledSel.current === selectedId) return;
+ const idx = items.findIndex((i) => i.kind === 'entity' && i.id === selectedId);
+ if (idx >= 0) {
+ handledSel.current = selectedId;
+ expandedSel.current = null;
+ useOutliner.getState().setCursor(entityKey(selectedId));
+ scrollToIndex(idx);
+ } else if (expandedSel.current !== selectedId) {
+ expandedSel.current = selectedId; // attempt expansion once (avoids a loop when filtered out)
+ useOutliner.getState().revealEntity(selectedId);
+ }
+ }, [selectedId, items]);
+
+ // — Keyboard navigation (↑↓ move · ←→ collapse/expand/jump · Enter toggle · F2/Del) —
+ const cursorItem = (): OutlinerItem | null => items.find((i) => i.key === cursor) ?? null;
+ const focusIndex = (idx: number) => {
+ const it = items[idx];
+ if (!it) return;
+ useOutliner.getState().setCursor(it.key);
+ if (it.kind === 'entity') select(it.id);
+ scrollToIndex(idx);
+ };
+ const moveCursor = (delta: number) => {
+ if (items.length === 0) return;
+ const cur = items.findIndex((i) => i.key === cursor);
+ const next = cur < 0 ? (delta > 0 ? 0 : items.length - 1) : Math.max(0, Math.min(items.length - 1, cur + delta));
+ focusIndex(next);
+ };
+ const onKeyDown = (e: React.KeyboardEvent) => {
+ if ((e.target as HTMLElement).tagName === 'INPUT' || renaming != null) return; // typing
+ switch (e.key) {
+ case 'ArrowDown': e.preventDefault(); moveCursor(1); break;
+ case 'ArrowUp': e.preventDefault(); moveCursor(-1); break;
+ case 'ArrowRight': {
+ e.preventDefault();
+ const it = cursorItem();
+ if (it?.hasChildren && !it.expanded) toggleExpanded(it.key);
+ else if (it?.hasChildren && it.expanded) moveCursor(1); // step into the first child
+ break;
+ }
+ case 'ArrowLeft': {
+ e.preventDefault();
+ const it = cursorItem();
+ if (it?.hasChildren && it.expanded) toggleExpanded(it.key);
+ else if (it?.parentKey) {
+ const pidx = items.findIndex((i) => i.key === it.parentKey);
+ if (pidx >= 0) focusIndex(pidx);
+ }
+ break;
+ }
+ case 'Enter': {
+ const it = cursorItem();
+ if (it?.hasChildren) { e.preventDefault(); toggleExpanded(it.key); }
+ break;
+ }
+ case 'F2': {
+ e.preventDefault();
+ if (cursor) setRenaming(cursor);
+ break;
+ }
+ case 'Delete':
+ case 'Backspace': {
+ const sel = [...useSelection.getState().selectedIds];
+ if (sel.length) {
+ e.preventDefault();
+ sel.forEach((i) => SceneCommands.deleteEntity(i));
+ select(null);
+ }
+ break;
+ }
+ }
+ };
+
const onRowClick = (item: OutlinerItem, e: React.MouseEvent) => {
+ useOutliner.getState().setCursor(item.key);
if (item.kind === 'folder') {
toggleExpanded(item.key);
return;
@@ -290,6 +381,8 @@ export function Outliner() {
<OutlinerRow
item={it}
selected={it.kind === 'entity' && selectedIds.has(it.id)}
+ cursored={cursor === it.key}
+ highlight={highlight}
renaming={renaming === it.key}
isDrop={dropId === it.key}
prefab={it.kind === 'entity' && SceneModel.prefabTag(it.id) != null}
@@ -327,7 +420,7 @@ export function Outliner() {
<div className="search">
<Search size={13} strokeWidth={1.85} />
<input
- placeholder="Search entities"
+ placeholder="Search · type: comp:"
spellCheck={false}
value={query}
onChange={(e) => setQuery(e.target.value)}
@@ -364,10 +457,14 @@ export function Outliner() {
) : (
<VirtualTree
className="pbody"
+ tabIndex={0}
items={items}
rowHeight={ROW_H}
getKey={(it) => it.key}
renderRow={renderRow}
+ scrollToIndex={scrollTo.index}
+ scrollNonce={scrollTo.nonce}
+ onKeyDown={onKeyDown}
onDragOver={onBodyDragOver}
onDrop={onBodyDrop}
/>
diff --git a/desktop/src/theme/outliner.css b/desktop/src/theme/outliner.css
index b2eb0875c..5f3573903 100644
--- a/desktop/src/theme/outliner.css
+++ b/desktop/src/theme/outliner.css
@@ -62,6 +62,9 @@
.row.sel { background: var(--acc); color: #fff; }
.row.sel:hover { background: var(--acc); }
.row.drop { background: var(--acc-soft); box-shadow: inset 0 0 0 1px var(--acc); }
+/* Keyboard-focus ring (distinct from selection; mainly visible on folder rows). */
+.row.cursor:not(.sel) { box-shadow: inset 0 0 0 1px var(--acc-soft); }
+.pbody:focus, .pbody:focus-visible { outline: none; }
.row .twist { width: 16px; height: 100%; display: grid; place-items: center; color: var(--text-mute); flex-shrink: 0; }
.row.sel .twist { color: rgba(255, 255, 255, 0.8); }
.row .twist svg { transition: transform var(--t-fast) var(--e-out); }
@@ -72,6 +75,8 @@
.row.prefab .ricon { color: var(--info-warm); }
.row.sel.prefab .ricon { color: #fff; }
.row .rname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.row .rname mark { background: var(--acc-soft); color: inherit; border-radius: 2px; padding: 0 1px; }
+.row.sel .rname mark { background: rgba(255, 255, 255, 0.28); }
.row .rname-edit {
flex: 1;
min-width: 0;
diff --git a/desktop/tests/outliner-controller.test.ts b/desktop/tests/outliner-controller.test.ts
new file mode 100644
index 000000000..220b099f4
--- /dev/null
+++ b/desktop/tests/outliner-controller.test.ts
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: LicenseRef-PolyForm-Noncommercial-1.0.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file OutlinerController — the outliner's headless view-state (REARCH_OUTLINER
+ * P1/P2/P4). String-keyed expansion + cursor + reveal, model-anchored. Pure
+ * store over a model (no World), so it's unit-testable headless.
+ */
+import { describe, it, expect, beforeEach } from 'vitest';
+import type { SceneData } from 'esengine';
+import { EditorSession } from '@/engine/EditorSession';
+import { createOutlinerStore } from '@/outliner/OutlinerController';
+import { entityKey, folderKey } from '@/outliner/OutlinerModel';
+
+const ent = (id: number, parent: number | null, children: number[]) => ({ id, name: `E${id}`, parent, children, components: [] as unknown[] });
+// 1 ─ 2 ─ 3 (a chain); root 1 lives in folder "A/B".
+const scene = (): SceneData =>
+ ({ version: '1.0', name: 't', entities: [ent(1, null, [2]), ent(2, 1, [3]), ent(3, 2, [])] }) as unknown as SceneData;
+
+describe('OutlinerController', () => {
+ let S: EditorSession;
+ let store: ReturnType<typeof createOutlinerStore>;
+ beforeEach(() => {
+ S = EditorSession.create();
+ S.model.adopt(scene(), new Map());
+ S.model.setFolder(1, 'A/B');
+ store = createOutlinerStore(S.model);
+ });
+
+ it('revealEntity expands transform ancestors + the root folder path', () => {
+ store.getState().revealEntity(3);
+ const exp = store.getState().expanded;
+ expect(exp.has(entityKey(1))).toBe(true); // ancestor
+ expect(exp.has(entityKey(2))).toBe(true); // ancestor
+ expect(exp.has(folderKey('A'))).toBe(true); // root's folder prefixes
+ expect(exp.has(folderKey('A/B'))).toBe(true);
+ expect(exp.has(entityKey(3))).toBe(false); // the node itself isn't expanded
+ });
+
+ it('toggleExpanded / setExpanded / cursor', () => {
+ store.getState().setExpanded([entityKey(1)]);
+ store.getState().toggleExpanded(entityKey(1));
+ expect(store.getState().expanded.has(entityKey(1))).toBe(false);
+ store.getState().setCursor(entityKey(2));
+ expect(store.getState().cursor).toBe(entityKey(2));
+ });
+
+ it('dropId prunes the expansion + clears the cursor for that entity', () => {
+ store.getState().setExpanded([entityKey(2)]);
+ store.getState().setCursor(entityKey(2));
+ store.getState().dropId(2);
+ expect(store.getState().expanded.has(entityKey(2))).toBe(false);
+ expect(store.getState().cursor).toBeNull();
+ });
+
+ it('rebaseFolderKeys re-roots expanded folder keys on rename', () => {
+ store.getState().setExpanded([folderKey('A'), folderKey('A/B'), entityKey(1)]);
+ store.getState().rebaseFolderKeys('A', 'X');
+ const exp = store.getState().expanded;
+ expect(exp.has(folderKey('X'))).toBe(true);
+ expect(exp.has(folderKey('X/B'))).toBe(true);
+ expect(exp.has(entityKey(1))).toBe(true); // entity keys untouched
+ expect(exp.has(folderKey('A'))).toBe(false);
+ });
+
+ it('the model `entityRemoved` event self-heals expansion (subscribed)', () => {
+ store.getState().setExpanded([entityKey(2)]);
+ S.commands.deleteEntity(2); // emits entityRemoved(2) (+ its subtree)
+ expect(store.getState().expanded.has(entityKey(2))).toBe(false);
+ });
+
+ it('reset clears expansion + query + cursor', () => {
+ store.getState().setExpanded([entityKey(1)]);
+ store.getState().setQuery('x');
+ store.getState().setCursor(entityKey(1));
+ store.getState().reset();
+ expect(store.getState().expanded.size).toBe(0);
+ expect(store.getState().query).toBe('');
+ expect(store.getState().cursor).toBeNull();
+ });
+});
diff --git a/desktop/tests/outliner-model.test.ts b/desktop/tests/outliner-model.test.ts
index e9e278166..3ccdaf5f4 100644
--- a/desktop/tests/outliner-model.test.ts
+++ b/desktop/tests/outliner-model.test.ts
@@ -14,6 +14,7 @@ import {
collectExpandableKeys,
entityKey,
folderKey,
+ parseQuery,
type OutlinerItem,
} from '@/outliner/OutlinerModel';
@@ -122,3 +123,40 @@ describe('buildOutlinerItems — folders', () => {
expect(ks.has(entityKey(10))).toBe(false); // leaf, not expandable
});
});
+
+// Kinds come from components (modelKindOf): Sprite→sprite, Camera→camera.
+function compScene(): SceneData {
+ return {
+ version: '1.0',
+ name: 'c',
+ entities: [
+ { id: 1, name: 'Hero', parent: null, children: [], components: [{ type: 'Sprite', data: {} }] },
+ { id: 2, name: 'MainCam', parent: null, children: [], components: [{ type: 'Camera', data: {} }] },
+ { id: 3, name: 'Crate', parent: null, children: [], components: [{ type: 'Sprite', data: {} }, { type: 'RigidBody', data: {} }] },
+ ],
+ } as unknown as SceneData;
+}
+const queryIds = (data: SceneData, query: string) =>
+ buildOutlinerItems(data, { expanded: new Set(), query })
+ .filter((i): i is Extract<OutlinerItem, { kind: 'entity' }> => i.kind === 'entity')
+ .map((i) => i.id);
+
+describe('token search', () => {
+ it('parseQuery splits bare text from type:/comp: tokens', () => {
+ expect(parseQuery('type:sprite comp:RigidBody hero')).toEqual({ text: 'hero', types: ['sprite'], comps: ['rigidbody'] });
+ expect(parseQuery('t:camera c:Camera')).toEqual({ text: '', types: ['camera'], comps: ['camera'] });
+ expect(parseQuery(' big boss ')).toEqual({ text: 'big boss', types: [], comps: [] });
+ expect(parseQuery('')).toEqual({ text: '', types: [], comps: [] });
+ });
+
+ it('type: filters by kind', () => {
+ expect(queryIds(compScene(), 'type:camera')).toEqual([2]);
+ });
+ it('comp: filters by component type (case-insensitive)', () => {
+ expect(queryIds(compScene(), 'comp:rigidbody')).toEqual([3]);
+ });
+ it('bare text AND a token', () => {
+ expect(queryIds(compScene(), 'type:sprite cra')).toEqual([3]); // sprite kind AND name~"cra"
+ expect(queryIds(compScene(), 'type:sprite zzz')).toEqual([]); // name fails → none
+ });
+});