Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(palette): reveal a file result in the Explorer panel

enesa337d703bba9
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 3f70183b7..b1ab900be 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -123,6 +123,9 @@ export function Canvas() {
const [scOpen, setScOpen] = useState(false)
const [shortcutsOpen, setShortcutsOpen] = useState(false)
const [explorerOpen, setExplorerOpen] = useState(false)
+ // Reveal-in-Explorer target (relative to the active project cwd). Cleared shortly after so
+ // the same file can be revealed twice in a row.
+ const [revealPath, setRevealPath] = useState<string | null>(null)
// When set, a full-surface remote mirror of a connected host is shown over the local canvas.
const [remoteConnId, setRemoteConnId] = useState<string | null>(null)
const [confirm, setConfirm] = useState<{
@@ -755,6 +758,14 @@ export function Canvas() {
[activeProjectId, openFile]
)
+ /** Reveal a file in the Explorer drawer: open the drawer and hand it the (relative) path.
+ * Cleared after a tick so revealing the same file twice still triggers the effect. */
+ const revealProjectFile = useCallback((relPath: string) => {
+ setExplorerOpen(true)
+ setRevealPath(relPath)
+ setTimeout(() => setRevealPath(null), 1000)
+ }, [])
+
/** Open a git diff editor node for a changed file (from Source Control). */
const openDiff = useCallback(
(relPath: string, staged: boolean) => {
@@ -1831,6 +1842,7 @@ export function Canvas() {
commands={buildCommands()}
fileIndex={fileIndex}
onOpenFile={openProjectFile}
+ onRevealFile={revealProjectFile}
onClose={() => setPaletteOpen(false)}
/>
)}
@@ -1850,7 +1862,7 @@ export function Canvas() {
{shortcutsOpen && <ShortcutsPanel onClose={() => setShortcutsOpen(false)} />}
{explorerOpen && (
- <ExplorerPanel onClose={() => setExplorerOpen(false)} onOpenFile={openFile} />
+ <ExplorerPanel onClose={() => setExplorerOpen(false)} onOpenFile={openFile} revealPath={revealPath} />
)}
{confirm && (
diff --git a/src/renderer/components/ExplorerPanel.tsx b/src/renderer/components/ExplorerPanel.tsx
index 6e5d38012..8b27efcfb 100644
--- a/src/renderer/components/ExplorerPanel.tsx
+++ b/src/renderer/components/ExplorerPanel.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useState } from 'react'
+import { useCallback, useEffect, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import type { DirEntry } from '@shared/types'
import { useProjects } from '../state/projects'
@@ -6,6 +6,8 @@ import { useProjects } from '../state/projects'
interface ExplorerPanelProps {
onClose: () => void
onOpenFile: (path: string) => void
+ /** Absolute-or-relative file path to reveal (expand ancestors + select + scroll). Relative to the active project cwd. */
+ revealPath?: string | null
}
type ContextFn = (x: number, y: number, path: string, isDir: boolean) => void
@@ -30,6 +32,7 @@ function TreeEntry({
path,
depth,
selected,
+ forcedOpen,
onContext,
onOpenFile,
onSelect
@@ -38,12 +41,14 @@ function TreeEntry({
path: string
depth: number
selected: string | null
+ forcedOpen: Set<string>
onContext: ContextFn
onOpenFile: OpenFn
onSelect: SelectFn
}) {
const [open, setOpen] = useState(false)
const [children, setChildren] = useState<DirEntry[] | null>(null)
+ const rowRef = useRef<HTMLDivElement>(null)
const expandDir = useCallback(async () => {
const next = !open
@@ -51,6 +56,19 @@ function TreeEntry({
if (next && children === null) setChildren(await window.nodeTerminal.fs.list(path))
}, [open, children, path])
+ // Reveal: when this directory is force-opened (an ancestor of the reveal target),
+ // lazy-load its children (awaiting the list, like the click path) and expand.
+ useEffect(() => {
+ if (!entry.dir || !forcedOpen.has(path)) return
+ if (children === null) void window.nodeTerminal.fs.list(path).then(setChildren)
+ setOpen(true)
+ }, [forcedOpen, path, entry.dir, children])
+
+ // Reveal: scroll the selected (target) row into view once it has mounted.
+ useEffect(() => {
+ if (selected === path) rowRef.current?.scrollIntoView({ block: 'center' })
+ }, [selected, path])
+
// Files: first click selects, a second click (or double-click) opens the node.
// Directories: a click toggles expansion (and selects for highlight).
const onClick = useCallback(() => {
@@ -67,6 +85,7 @@ function TreeEntry({
return (
<>
<div
+ ref={rowRef}
className={`ex-row${entry.ignored ? ' ignored' : ''}${selected === path ? ' selected' : ''}`}
style={{ paddingLeft: 8 + depth * 14 }}
onClick={onClick}
@@ -91,6 +110,7 @@ function TreeEntry({
path={`${path}/${c.name}`}
depth={depth + 1}
selected={selected}
+ forcedOpen={forcedOpen}
onContext={onContext}
onOpenFile={onOpenFile}
onSelect={onSelect}
@@ -107,12 +127,13 @@ function TreeEntry({
* filesystem yet. Once `canvas:state` carries the host cwd (Task 6), this can switch to
* `remoteFs(connectionId)` (the per-connection `FsApi`) rooted at that path — the Editor already
* proxies over the relay via `data.remote.connectionId`. */
-export function ExplorerPanel({ onClose, onOpenFile }: ExplorerPanelProps) {
+export function ExplorerPanel({ onClose, onOpenFile, revealPath }: ExplorerPanelProps) {
const project = useProjects((s) => s.projects.find((p) => p.id === s.activeProjectId))
const cwd = project?.cwd
const [roots, setRoots] = useState<DirEntry[] | null>(null)
const [version, setVersion] = useState(0)
const [selected, setSelected] = useState<string | null>(null)
+ const [forcedOpen, setForcedOpen] = useState<Set<string>>(new Set())
const [menu, setMenu] = useState<{ x: number; y: number; path: string } | null>(null)
useEffect(() => {
@@ -120,6 +141,26 @@ export function ExplorerPanel({ onClose, onOpenFile }: ExplorerPanelProps) {
else setRoots(null)
}, [cwd, version])
+ // Reveal a file: force-open every ancestor directory under cwd, select the file, and
+ // let the matching row scroll itself into view. Only paths inside cwd are revealed.
+ useEffect(() => {
+ if (!revealPath || !cwd) return
+ const base = cwd.replace(/\/$/, '')
+ const rel = revealPath.startsWith(base + '/') ? revealPath.slice(base.length + 1) : revealPath
+ // Reject paths that escape cwd (absolute outside it, or "../" traversal).
+ if (rel.startsWith('/') || rel.split('/').includes('..')) return
+ const abs = `${base}/${rel}`
+ const parts = rel.split('/')
+ const dirs = new Set<string>()
+ let acc = base
+ for (let i = 0; i < parts.length - 1; i++) {
+ acc = `${acc}/${parts[i]}`
+ dirs.add(acc)
+ }
+ setForcedOpen(dirs)
+ setSelected(abs)
+ }, [revealPath, cwd])
+
const onContext: ContextFn = (x, y, path) => setMenu({ x, y, path })
return createPortal(
@@ -153,6 +194,7 @@ export function ExplorerPanel({ onClose, onOpenFile }: ExplorerPanelProps) {
path={`${cwd}/${e.name}`}
depth={0}
selected={selected}
+ forcedOpen={forcedOpen}
onContext={onContext}
onOpenFile={onOpenFile}
onSelect={setSelected}