@@ -4,10 +4,14 @@ import {
44 ThreadId ,
55 type ScopedThreadRef ,
66 type FilesystemEntryMetadata ,
7+ type ResolvedKeybindingsConfig ,
78} from "@t3tools/contracts" ;
9+ import { compileResolvedKeybindingsConfig , DEFAULT_KEYBINDINGS } from "@t3tools/shared/keybindings" ;
810import { Atom , AsyncResult } from "effect/reactivity" ;
911import type { GhosttyTerminalSurfaceOptions } from "~/terminal/ghostty/surface" ;
1012import { AppAtomRegistryProvider , appAtomRegistry } from "../rpc/atomRegistry" ;
13+ import { useRightPanelStore } from "../rightPanelStore" ;
14+ import { useTerminalUiStateStore } from "../terminalUiStateStore" ;
1115import { extractTerminalLinks } from "../terminal-links" ;
1216import { expect , it , vi } from "vite-plus/test" ;
1317import { act , fakeTimers , render } from "../../test/render" ;
@@ -110,6 +114,7 @@ function Drawer(props: {
110114 threadRef : ScopedThreadRef ;
111115 cwd ?: string ;
112116 onCloseTerminal : ( terminalId : string , threadRef ?: ScopedThreadRef ) => void ;
117+ keybindings ?: ResolvedKeybindingsConfig ;
113118} ) {
114119 return (
115120 < ThreadTerminalDrawer
@@ -128,7 +133,7 @@ function Drawer(props: {
128133 onCloseTerminal = { props . onCloseTerminal }
129134 onHeightChange = { ( ) => { } }
130135 onAddTerminalContext = { ( ) => { } }
131- keybindings = { [ ] }
136+ keybindings = { props . keybindings ?? [ ] }
132137 />
133138 ) ;
134139}
@@ -149,6 +154,8 @@ function setup() {
149154 fixture . pendingSurfaces = [ ] ;
150155 fixture . surfaceOptions = [ ] ;
151156 fixture . metadata . clear ( ) ;
157+ useRightPanelStore . setState ( useRightPanelStore . getInitialState ( ) ) ;
158+ useTerminalUiStateStore . setState ( useTerminalUiStateStore . getInitialState ( ) ) ;
152159 return { original, other } ;
153160}
154161
@@ -170,6 +177,42 @@ it("closes an exited terminal on its own thread after navigating to one reusing
170177 expect ( onCloseTerminal . mock . calls ) . toEqual ( [ [ "term-1" , original ] ] ) ;
171178} ) ;
172179
180+ // Thread navigation defaults have no `!terminalFocus`, so they apply in a focused terminal.
181+ it ( "hands thread navigation shortcuts from a focused terminal back to the app" , async ( ) => {
182+ const { other : threadRef } = setup ( ) ;
183+ using _platform = vi . spyOn ( navigator , "platform" , "get" ) . mockReturnValue ( "Linux x86_64" ) ;
184+ useRightPanelStore . getState ( ) . openBrowser ( threadRef , null ) ;
185+ await using _screen = await render (
186+ < Drawer
187+ threadRef = { threadRef }
188+ onCloseTerminal = { ( ) => { } }
189+ keybindings = { compileResolvedKeybindingsConfig ( [
190+ ...DEFAULT_KEYBINDINGS ,
191+ { key : "ctrl+r" , command : "thread.next" , when : "!previewOpen" } ,
192+ { key : "ctrl+g" , command : "thread.previous" , when : "terminalOpen" } ,
193+ ] ) }
194+ /> ,
195+ ) ;
196+ await act ( async ( ) => {
197+ fixture . pendingSurfaces . shift ( ) ?.( ) ;
198+ } ) ;
199+ const terminalHandles = ( key : string , code : string , shiftKey = true ) =>
200+ fixture . surfaceOptions
201+ . at ( - 1 ) !
202+ . beforeKey ( new KeyboardEvent ( "keydown" , { key, code, ctrlKey : true , shiftKey } ) ) ;
203+
204+ expect ( [ terminalHandles ( "{" , "BracketLeft" ) , terminalHandles ( "}" , "BracketRight" ) ] ) . toEqual ( [
205+ false ,
206+ false ,
207+ ] ) ;
208+ expect ( terminalHandles ( "C" , "KeyC" ) ) . toBe ( true ) ;
209+ // Sidebar sees the open preview and the closed drawer and rejects these, so the shell keeps them.
210+ expect ( [ terminalHandles ( "r" , "KeyR" , false ) , terminalHandles ( "g" , "KeyG" , false ) ] ) . toEqual ( [
211+ true ,
212+ true ,
213+ ] ) ;
214+ } ) ;
215+
173216it ( "only activates terminal paths confirmed to exist on their environment" , async ( ) => {
174217 const { other : threadRef } = setup ( ) ;
175218 const key = ( path : string ) => JSON . stringify ( [ threadRef . environmentId , path ] ) ;
0 commit comments