@@ -76,49 +76,37 @@ describe("CommandRegistry", () => {
7676
7777 it ( "does not throw when command is not found" , async ( ) => {
7878 const registry = createRegistry ( ) ;
79- await expect (
80- registry . executeCommand ( "nonexistent.command" ) ,
81- ) . resolves . toBeUndefined ( ) ;
79+ await expect ( registry . executeCommand ( "nonexistent.command" ) ) . resolves . toBeUndefined ( ) ;
8280 } ) ;
8381
84- it ( "prefers active-scoped handlers over inactive ones " , async ( ) => {
82+ it ( "executes the last registered handler " , async ( ) => {
8583 const registry = createRegistry ( ) ;
8684 const results : string [ ] = [ ] ;
8785
88- registry . registerCommand ( "test.scope" , ( ) => results . push ( "default" ) ) ;
89-
90- registry . registerCommand (
91- "test.scope" ,
92- ( ) => results . push ( "active" ) ,
93- { isActive : ( ) => true } ,
94- ) ;
86+ registry . registerCommand ( "test.override" , ( ) => {
87+ results . push ( "first" ) ;
88+ } ) ;
9589
96- registry . registerCommand (
97- "test.scope" ,
98- ( ) => results . push ( "inactive" ) ,
99- { isActive : ( ) => false } ,
100- ) ;
90+ registry . registerCommand ( "test.override" , ( ) => {
91+ results . push ( "second" ) ;
92+ } ) ;
10193
102- await registry . executeCommand ( "test.scope " ) ;
103- expect ( results ) . toEqual ( [ "active " ] ) ;
94+ await registry . executeCommand ( "test.override " ) ;
95+ expect ( results ) . toEqual ( [ "second " ] ) ;
10496 } ) ;
10597
106- it ( "falls back to the last registered handler when no active scope matches " , async ( ) => {
98+ it ( "unregister removes the handler" , async ( ) => {
10799 const registry = createRegistry ( ) ;
108- const results : string [ ] = [ ] ;
100+ let called = false ;
109101
110- registry . registerCommand (
111- "test.fallback" ,
112- ( ) => results . push ( "inactive" ) ,
113- { isActive : ( ) => false } ,
114- ) ;
102+ const unregister = registry . registerCommand ( "test.unreg" , ( ) => {
103+ called = true ;
104+ } ) ;
115105
116- registry . registerCommand ( "test.fallback" , ( ) =>
117- results . push ( "fallback" ) ,
118- ) ;
106+ unregister ( ) ;
119107
120- await registry . executeCommand ( "test.fallback " ) ;
121- expect ( results ) . toEqual ( [ "fallback" ] ) ;
108+ await registry . executeCommand ( "test.unreg " ) ;
109+ expect ( called ) . toBe ( false ) ;
122110 } ) ;
123111 } ) ;
124112
@@ -130,34 +118,22 @@ describe("CommandRegistry", () => {
130118
131119 it ( "adds and retrieves keybindings for a layer" , ( ) => {
132120 const registry = createRegistry ( ) ;
133- registry . registerKeybinding (
134- { command : "test.cmd" , key : "ctrl+a" } ,
135- "default" ,
136- ) ;
121+ registry . registerKeybinding ( { command : "test.cmd" , key : "ctrl+a" } , "default" ) ;
137122 const bindings = registry . getKeybindings ( ) ;
138123 expect ( bindings ) . toHaveLength ( 1 ) ;
139124 expect ( bindings [ 0 ] ! . key ) . toBe ( "ctrl+a" ) ;
140125 } ) ;
141126
142127 it ( "filters out keybindings with empty command" , ( ) => {
143128 const registry = createRegistry ( ) ;
144- registry . registerKeybinding (
145- { command : "" , key : "ctrl+a" } ,
146- "default" ,
147- ) ;
129+ registry . registerKeybinding ( { command : "" , key : "ctrl+a" } , "default" ) ;
148130 expect ( registry . getKeybindings ( ) ) . toHaveLength ( 0 ) ;
149131 } ) ;
150132
151133 it ( "resolves keybindings for a specific layer" , ( ) => {
152134 const registry = createRegistry ( ) ;
153- registry . registerKeybinding (
154- { command : "cmd.a" , key : "ctrl+x" } ,
155- "default" ,
156- ) ;
157- registry . registerKeybinding (
158- { command : "cmd.b" , key : "ctrl+y" } ,
159- "user" ,
160- ) ;
135+ registry . registerKeybinding ( { command : "cmd.a" , key : "ctrl+x" } , "default" ) ;
136+ registry . registerKeybinding ( { command : "cmd.b" , key : "ctrl+y" } , "user" ) ;
161137
162138 const defaultBindings = registry . getKeybindingsForLayer ( "default" ) ;
163139 expect ( defaultBindings ) . toHaveLength ( 1 ) ;
0 commit comments