@@ -10,7 +10,7 @@ import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
1010import * as AsyncResult from "effect/reactivity/AsyncResult" ;
1111import * as Cause from "effect/Cause" ;
1212import { ChevronsDownUpIcon , ChevronsUpDownIcon } from "lucide-react" ;
13- import { useEffect , useRef , useState } from "react" ;
13+ import { type Ref , useEffect , useEffectEvent , useRef , useState } from "react" ;
1414
1515import { Button } from "~/components/ui/button" ;
1616import { InputGroup , InputGroupInput } from "~/components/ui/input-group" ;
@@ -33,6 +33,8 @@ import { buildFileTreePathUpdates } from "./fileTreePathReconciliation";
3333import { loadFileAncestors } from "./loadFileAncestors" ;
3434import { useDirectoryEntries } from "./useDirectoryEntries" ;
3535import { useProjectPathSearch } from "~/state/queries" ;
36+ import { isMacPlatform } from "~/lib/utils" ;
37+ import { type PreviewAction , subscribePreviewAction } from "../preview/previewActionBus" ;
3638
3739interface FileBrowserPanelProps {
3840 environmentId : EnvironmentId ;
@@ -46,6 +48,7 @@ interface FileBrowserPanelProps {
4648 hostFolder ?: boolean ;
4749 onRefreshSelectedFile ?: ( ) => void ;
4850 workspaceMutationId : string | null ;
51+ answersPanelFind ?: boolean ;
4952}
5053
5154function treePath ( entry : ProjectEntry ) : string {
@@ -73,16 +76,21 @@ function RefreshFilesButton(props: { isPending: boolean; onRefresh: () => void }
7376 ) ;
7477}
7578
76- function FileSearchField ( props : {
79+ function FileSearchField ( {
80+ ref,
81+ ...props
82+ } : {
7783 ariaLabel : string ;
7884 name : string ;
7985 onClose : ( ) => void ;
8086 onValueChange : ( value : string ) => void ;
87+ ref : Ref < HTMLInputElement > ;
8188 value : string ;
8289} ) {
8390 return (
8491 < InputGroup variant = "ghost" className = "h-7 min-w-0 flex-1" >
8592 < InputGroupInput
93+ ref = { ref }
8694 type = "search"
8795 name = { props . name }
8896 size = "sm"
@@ -142,6 +150,7 @@ export default function FileBrowserPanel({
142150 onRefreshSelectedFile,
143151 workspaceMutationId,
144152 hostFolder = false ,
153+ answersPanelFind = false ,
145154} : FileBrowserPanelProps ) {
146155 const panelPath = ( relativePath : string ) =>
147156 hostFolder ? joinHostPath ( cwd , relativePath ) : relativePath ;
@@ -320,6 +329,20 @@ export default function FileBrowserPanel({
320329 setQuery ( "" ) ;
321330 search . close ( ) ;
322331 } ;
332+ const searchInputRef = useRef < HTMLInputElement > ( null ) ;
333+ const focusSearch = ( ) => {
334+ searchInputRef . current ?. focus ( ) ;
335+ searchInputRef . current ?. select ( ) ;
336+ } ;
337+ const onPanelAction = useEffectEvent ( ( action : PreviewAction ) => {
338+ // Hidden panel tabs stay mounted; only the visible Files tab answers.
339+ if ( action === "find" && searchInputRef . current ?. getClientRects ( ) . length ) focusSearch ( ) ;
340+ } ) ;
341+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to the panel find command, which fires while focus is anywhere in the right panel
342+ useEffect ( ( ) => {
343+ if ( ! answersPanelFind ) return ;
344+ return subscribePreviewAction ( onPanelAction ) ;
345+ } , [ answersPanelFind ] ) ;
323346 const expandedPathsRef = useRef ( new Set < string > ( ) ) ;
324347 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to the Pierre tree model to load directories as they are expanded
325348 useEffect ( ( ) => {
@@ -482,13 +505,21 @@ export default function FileBrowserPanel({
482505 // Capture dragstart before the tree selects the row so selection sees the drag flag.
483506 onDragStartCapture = { ( event ) => dragMention . handleDragStart ( event . nativeEvent ) }
484507 onDragEnd = { ( ) => dragMention . handleDragEnd ( ( path ) => model . getItem ( path ) ?. deselect ( ) ) }
508+ onKeyDown = { ( event ) => {
509+ const isModPressed = isMacPlatform ( navigator . platform ) ? event . metaKey : event . ctrlKey ;
510+ if ( ! isModPressed || event . altKey || event . shiftKey || event . key . toLowerCase ( ) !== "f" )
511+ return ;
512+ event . preventDefault ( ) ;
513+ focusSearch ( ) ;
514+ } }
485515 >
486516 < div
487517 className = "flex h-10 min-h-10 shrink-0 items-center gap-1 border-b border-border/60 bg-background px-2 in-data-[preview-panel-mode=inline]:mb-1 in-data-[preview-panel-mode=inline]:h-9 in-data-[preview-panel-mode=inline]:min-h-9 in-data-[preview-panel-mode=inline]:border-b-transparent"
488518 data-surface-subheader
489519 >
490520 < RefreshFilesButton isPending = { isPending } onRefresh = { handleRefresh } />
491521 < FileSearchField
522+ ref = { searchInputRef }
492523 name = "project-files-search"
493524 ariaLabel = { `Search ${ projectName } files` }
494525 value = { search . value }
0 commit comments