@@ -219,7 +219,7 @@ import {
219219 deriveAgentPanelModel ,
220220 foldSubagentActivities ,
221221} from "@t3tools/client-runtime/state/subagentRuntime" ;
222- import { BranchToolbar } from "./BranchToolbar" ;
222+ import { BranchToolbar , type BranchToolbarHandle } from "./BranchToolbar" ;
223223import { resolveShortcutCommand , shortcutLabelForCommand } from "../keybindings" ;
224224import ThreadTerminalDrawer from "./ThreadTerminalDrawer" ;
225225import {
@@ -1617,6 +1617,7 @@ export default function ChatView(props: ChatViewProps) {
16171617 const composerTerminalContextsRef = useRef < TerminalContextDraft [ ] > ( [ ] ) ;
16181618 const localComposerRef = useRef < ChatComposerHandle | null > ( null ) ;
16191619 const composerRef = useComposerHandleContext ( ) ?? localComposerRef ;
1620+ const branchToolbarRef = useRef < BranchToolbarHandle > ( null ) ;
16201621 const pasteAsTextShortcutUntilRef = useRef ( 0 ) ;
16211622 const [ restingComposerControlsHost , setRestingComposerControlsHost ] =
16221623 useState < HTMLDivElement | null > ( null ) ;
@@ -6397,6 +6398,17 @@ export default function ChatView(props: ChatViewProps) {
63976398 terminalUiOpenByThreadRef . current [ activeThreadKey ] = current ;
63986399 } , [ activeThreadKey , focusComposer , terminalUiState . terminalOpen ] ) ;
63996400
6401+ const getShortcutContext = useCallback (
6402+ ( ) => ( {
6403+ terminalFocus : getTerminalFocusOwner ( ) !== null ,
6404+ terminalOpen : Boolean ( terminalUiState . terminalOpen ) ,
6405+ previewFocus : isPreviewFocused ( ) ,
6406+ previewOpen : previewPanelOpen ,
6407+ modelPickerOpen : composerRef . current ?. isModelPickerOpen ( ) ?? false ,
6408+ } ) ,
6409+ [ composerRef , previewPanelOpen , terminalUiState . terminalOpen ] ,
6410+ ) ;
6411+
64006412 useEffect ( ( ) => {
64016413 const handler = ( event : globalThis . KeyboardEvent ) => {
64026414 if ( preventRepeatedTerminalCloseShortcut ( event , keybindings ) ) {
@@ -6417,13 +6429,7 @@ export default function ChatView(props: ChatViewProps) {
64176429 if ( event . defaultPrevented && terminalFocusOwner === null ) {
64186430 return ;
64196431 }
6420- const shortcutContext = {
6421- terminalFocus : terminalFocusOwner !== null ,
6422- terminalOpen : Boolean ( terminalUiState . terminalOpen ) ,
6423- previewFocus : isPreviewFocused ( ) ,
6424- previewOpen : previewPanelOpen ,
6425- modelPickerOpen : composerRef . current ?. isModelPickerOpen ( ) ?? false ,
6426- } ;
6432+ const shortcutContext = getShortcutContext ( ) ;
64276433
64286434 if (
64296435 ! shortcutContext . terminalFocus &&
@@ -6588,7 +6594,33 @@ export default function ChatView(props: ChatViewProps) {
65886594 if ( command === "modelPicker.toggle" ) {
65896595 event . preventDefault ( ) ;
65906596 event . stopPropagation ( ) ;
6591- composerRef . current ?. toggleModelPicker ( ) ;
6597+ if ( ! event . repeat ) composerRef . current ?. toggleModelPicker ( ) ;
6598+ return ;
6599+ }
6600+
6601+ if (
6602+ command === "composer.host" ||
6603+ command === "composer.effort" ||
6604+ command === "composer.mode" ||
6605+ command === "composer.workspace"
6606+ ) {
6607+ event . preventDefault ( ) ;
6608+ event . stopPropagation ( ) ;
6609+ if ( ! event . repeat ) composerRef . current ?. openControl ( command ) ;
6610+ return ;
6611+ }
6612+
6613+ if ( command === "composer.branch" ) {
6614+ event . preventDefault ( ) ;
6615+ event . stopPropagation ( ) ;
6616+ if ( ! event . repeat ) branchToolbarRef . current ?. openBranchPicker ( ) ;
6617+ return ;
6618+ }
6619+
6620+ if ( command === "composer.previousWorktree" ) {
6621+ event . preventDefault ( ) ;
6622+ event . stopPropagation ( ) ;
6623+ if ( ! event . repeat ) branchToolbarRef . current ?. usePreviousWorktree ( ) ;
65926624 return ;
65936625 }
65946626
@@ -6643,7 +6675,7 @@ export default function ChatView(props: ChatViewProps) {
66436675 supportsSettlement ,
66446676 confirmAndUnpinThread ,
66456677 copyActiveThreadReference ,
6646- previewPanelOpen ,
6678+ getShortcutContext ,
66476679 toggleRightPanel ,
66486680 toggleRightPanelMaximized ,
66496681 toggleTerminalVisibility ,
@@ -8708,6 +8740,10 @@ export default function ChatView(props: ChatViewProps) {
87088740 // reader's feet. A link the agent wrote can open any other one here, and that one has to be
87098741 // checkable out like it is anywhere else.
87108742 < PullRequestDetailPanel
8743+ getShortcutContext = { getShortcutContext }
8744+ shortcutsEnabled = {
8745+ rightPanelOpen && activeRightPanelSurface ?. id === renderedRightPanelSurface . id
8746+ }
87118747 key = { `${ renderedRightPanelSurface . host ?? "" } :${ renderedRightPanelSurface . repository } #${ renderedRightPanelSurface . number } ` }
87128748 environmentId = { activeThread . environmentId }
87138749 onSelectPullRequest = { ( reference ) => {
@@ -9231,6 +9267,7 @@ export default function ChatView(props: ChatViewProps) {
92319267 { mountComposerContextStrip && (
92329268 < div className = "pointer-events-auto" >
92339269 < BranchToolbar
9270+ ref = { branchToolbarRef }
92349271 environmentId = { activeThread . environmentId }
92359272 threadId = { activeThread . id }
92369273 showGitControls = { isGitRepo }
0 commit comments