1- import React , { useState , useEffect , useCallback } from "react" ;
1+ import React , { useState , useCallback , useEffect } from "react" ;
22import { Link } from "@tanstack/react-router" ;
33import { SettingsIcon , BotIcon , CodeIcon , Sparkles } from "lucide-react" ;
44import { SettingsModal } from "@/components/SettingsModal" ;
@@ -7,33 +7,53 @@ import { Button } from "@/components/ui/button";
77import { ToggleGroup , ToggleGroupItem } from "@/components/ui/toggle-group" ;
88import { useEditorContentStore } from "@/stores/editor-content" ;
99
10+ import { useCommandManager , useKeyBindingManager } from "@/services/keymaps/main" ;
11+
1012export default function WorkspaceHeader ( ) {
1113 const [ settingsOpen , setSettingsOpen ] = useState ( false ) ;
1214 const { view, setView } = useEditorContentStore ( ) ;
1315
14- // Cycle views: code -> agents -> auto -> code ...
16+ // Use keymap system for cycling views
1517 const views = [ "code" , "agents" , "auto" ] ;
16- const handleCycleView = useCallback ( ( ) => {
17- const idx = views . indexOf ( view ) ;
18- const nextView = views [ ( idx + 1 ) % views . length ] ;
19- setView ( nextView as typeof view ) ;
20- } , [ view , setView ] ) ;
18+ const { registerCommand, unregisterCommand } = useCommandManager ( ) ;
19+ const { addKeyBinding, removeKeyBinding } = useKeyBindingManager ( ) ;
2120
21+ // Register the cycle view command and key binding
2222 useEffect ( ( ) => {
23- function handleKeyDown ( e ) {
24- const isMac = navigator . platform . toLowerCase ( ) . includes ( "mac" ) ;
25- const cmdOrCtrl = isMac ? e . metaKey : e . ctrlKey ;
26- if ( cmdOrCtrl && e . key === "5" ) {
27- e . preventDefault ( ) ;
28- handleCycleView ( ) ;
29- }
30- }
31- window . addEventListener ( "keydown" , handleKeyDown ) ;
32- return ( ) => window . removeEventListener ( "keydown" , handleKeyDown ) ;
33- } , [ handleCycleView ] ) ;
23+ // Register command
24+ registerCommand ( "view.cycleView" , {
25+ execute : ( ) => {
26+ console . log ( "registered keymap, view.cycleView" )
27+ const idx = views . indexOf ( view ) ;
28+ const nextView = views [ ( idx + 1 ) % views . length ] ;
29+ setView ( nextView as typeof view ) ;
30+ } ,
31+ canExecute : ( ) => true ,
32+ } ) ;
33+
34+ // Register key binding for Cmd/Ctrl+5 (global context)
35+ addKeyBinding ( {
36+ id : "view.cycleView.binding" ,
37+ description : "Cycle editor views" ,
38+ key : "cmd+5" ,
39+ altKeys : [ "ctrl+5" ] ,
40+ command : "view.cycleView" ,
41+ enabled : true ,
42+ category : "view" ,
43+ context : "global" ,
44+ } ) ;
45+
46+ // Cleanup on unmount
47+ return ( ) => {
48+ unregisterCommand ( "view.cycleView" ) ;
49+ removeKeyBinding ( "view.cycleView.binding" ) ;
50+ } ;
51+ // eslint-disable-next-line react-hooks/exhaustive-deps
52+ } , [ view , setView ] ) ;
3453
3554 return (
3655 < >
56+ { /* Keymap handles Cmd/Ctrl+5 for cycling views */ }
3757 < div className = "draglayer relative z-950 flex w-screen items-stretch border-b py-1" >
3858 < div className = "flex flex-1 items-center px-4" >
3959 < div className = "no-drag" >
0 commit comments