@@ -25,6 +25,7 @@ export default function RepoPicker({
2525 const [ activeIndex , setActiveIndex ] = useState ( - 1 ) ;
2626 const rootRef = useRef < HTMLDivElement > ( null ) ;
2727 const searchInputRef = useRef < HTMLInputElement > ( null ) ;
28+ const worktreeToggleRef = useRef < HTMLButtonElement > ( null ) ;
2829 const optionRefs = useRef < Array < HTMLButtonElement | null > > ( [ ] ) ;
2930 const openFocusModeRef = useRef < "select" | "preserve-end" > ( "select" ) ;
3031 const menuId = useId ( ) ;
@@ -129,6 +130,17 @@ export default function RepoPicker({
129130 return Math . max ( 0 , Math . min ( filteredDirs . length - 1 , baseIndex + step ) ) ;
130131 }
131132
133+ function commitSelection ( dir : string , nextIndex ?: number ) {
134+ onSelect ( dir ) ;
135+ if ( typeof nextIndex === "number" ) {
136+ setActiveIndex ( nextIndex ) ;
137+ }
138+ setOpen ( false ) ;
139+ requestAnimationFrame ( ( ) => {
140+ worktreeToggleRef . current ?. focus ( ) ;
141+ } ) ;
142+ }
143+
132144 function isTypeaheadKey ( event : ReactKeyboardEvent < HTMLButtonElement > ) {
133145 return event . key . length === 1 && ! event . metaKey && ! event . ctrlKey && ! event . altKey ;
134146 }
@@ -204,8 +216,7 @@ export default function RepoPicker({
204216 if ( activeIndex >= 0 ) {
205217 const dir = filteredDirs [ activeIndex ] ;
206218 if ( dir ) {
207- onSelect ( dir ) ;
208- setOpen ( false ) ;
219+ commitSelection ( dir , activeIndex ) ;
209220 }
210221 }
211222 return ;
@@ -269,11 +280,7 @@ export default function RepoPicker({
269280 ref = { ( element ) => {
270281 optionRefs . current [ index ] = element ;
271282 } }
272- onClick = { ( ) => {
273- onSelect ( dir ) ;
274- setActiveIndex ( index ) ;
275- setOpen ( false ) ;
276- } }
283+ onClick = { ( ) => commitSelection ( dir , index ) }
277284 >
278285 { dir }
279286 </ button >
@@ -287,6 +294,7 @@ export default function RepoPicker({
287294 </ Button >
288295 < button
289296 type = "button"
297+ ref = { worktreeToggleRef }
290298 className = { `${ styles . toggle } ${ worktreeEnabled ? styles . toggleActive : "" } ` }
291299 onClick = { ( ) => onToggleWorktree ( ! worktreeEnabled ) }
292300 aria-pressed = { worktreeEnabled }
0 commit comments