77 buildKeybindingCommandOptions ,
88 buildWhenVariableOptions ,
99 commandLabel ,
10+ filterKeybindingRows ,
1011 groupKeybindingRows ,
1112 keybindingConflictLabels ,
1213 keybindingFromKeyboardEvent ,
@@ -19,7 +20,7 @@ import {
1920
2021describe ( "KeybindingsSettings.logic" , ( ) => {
2122 it ( "lists composer, provider, and pull request commands with editable defaults" , ( ) => {
22- const rows = buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS , "" ) ;
23+ const rows = buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS ) ;
2324 for ( const command of [
2425 "composer.sendAlternate" ,
2526 "composer.sendBackground" ,
@@ -43,24 +44,34 @@ describe("KeybindingsSettings.logic", () => {
4344 }
4445 } ) ;
4546 it ( "finds the editable shortcut for sending the first queued message" , ( ) => {
46- expect ( buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS , "first queued" ) ) . toContainEqual (
47+ expect (
48+ filterKeybindingRows ( buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS ) , "first queued" ) ,
49+ ) . toContainEqual (
4750 expect . objectContaining ( {
4851 command : "thread.steerQueuedMessage" ,
4952 key : "mod+shift+enter" ,
5053 } ) ,
5154 ) ;
5255 } ) ;
56+ it ( "filtering keeps the row objects so unchanged rows skip rendering" , ( ) => {
57+ const rows = buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS ) ;
58+ const filtered = filterKeybindingRows ( rows , "terminal" ) ;
59+ expect ( filtered . length ) . toBeGreaterThan ( 0 ) ;
60+ expect ( filtered . length ) . toBeLessThan ( rows . length ) ;
61+ for ( const row of filtered ) expect ( rows ) . toContain ( row ) ;
62+ expect ( filterKeybindingRows ( rows , " " ) ) . toBe ( rows ) ;
63+ } ) ;
5364 it . each ( [ "pu" , "pull request" , "copy link" , "thread id" ] ) (
5465 "finds the copy link shortcut with %s" ,
5566 ( query ) => {
56- const rows = buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS , query ) ;
67+ const rows = filterKeybindingRows ( buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS ) , query ) ;
5768 expect ( rows ) . toContainEqual (
5869 expect . objectContaining ( { command : "thread.copyReference" , key : "mod+shift+c" } ) ,
5970 ) ;
6071 } ,
6172 ) ;
6273 it ( "groups rows by command area in page order and drops empty groups" , ( ) => {
63- const groups = groupKeybindingRows ( buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS , "" ) ) ;
74+ const groups = groupKeybindingRows ( buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS ) ) ;
6475 expect ( groups . map ( ( group ) => group . title ) ) . toEqual ( [
6576 "Navigation" ,
6677 "Threads" ,
@@ -74,9 +85,11 @@ describe("KeybindingsSettings.logic", () => {
7485 expect ( composer ?. rows . map ( ( row ) => row . command ) ) . toEqual (
7586 expect . arrayContaining ( [ "composer.host" , "modelPicker.toggle" ] ) ,
7687 ) ;
77- expect ( groupKeybindingRows ( buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS , "split" ) ) ) . toEqual (
78- [ expect . objectContaining ( { id : "terminal" } ) ] ,
79- ) ;
88+ expect (
89+ groupKeybindingRows (
90+ filterKeybindingRows ( buildKeybindingRows ( DEFAULT_RESOLVED_KEYBINDINGS ) , "split" ) ,
91+ ) ,
92+ ) . toEqual ( [ expect . objectContaining ( { id : "terminal" } ) ] ) ;
8093 } ) ;
8194 it ( "orders Usage bindings and command choices like the page" , ( ) => {
8295 const expected = [
@@ -93,16 +106,18 @@ describe("KeybindingsSettings.logic", () => {
93106 DEFAULT_RESOLVED_KEYBINDINGS ,
94107 DEFAULT_RESOLVED_KEYBINDINGS . toReversed ( ) ,
95108 ] ) {
96- expect ( buildKeybindingRows ( bindings , "usage" ) . map ( ( row ) => row . command ) ) . toEqual ( expected ) ;
109+ expect (
110+ filterKeybindingRows ( buildKeybindingRows ( bindings ) , "usage" ) . map ( ( row ) => row . command ) ,
111+ ) . toEqual ( expected ) ;
97112 expect (
98113 buildKeybindingCommandOptions ( bindings ) . filter ( ( command ) => command . startsWith ( "usage." ) ) ,
99114 ) . toEqual ( expected ) ;
100115 }
101116 } ) ;
102117
103118 it ( "builds searchable rows with readable key and when values" , ( ) => {
104- const rows = buildKeybindingRows (
105- [
119+ const rows = filterKeybindingRows (
120+ buildKeybindingRows ( [
106121 {
107122 command : "terminal.toggle" ,
108123 shortcut : {
@@ -118,7 +133,7 @@ describe("KeybindingsSettings.logic", () => {
118133 node : { type : "identifier" , name : "terminalFocus" } ,
119134 } ,
120135 } ,
121- ] satisfies ResolvedKeybindingsConfig ,
136+ ] satisfies ResolvedKeybindingsConfig ) ,
122137 "terminal" ,
123138 ) ;
124139
@@ -345,81 +360,75 @@ describe("KeybindingsSettings.logic", () => {
345360 } ) ;
346361
347362 it ( "marks each default shortcut for multi-binding commands as default" , ( ) => {
348- const rows = buildKeybindingRows (
349- [
350- {
351- command : "chat.new" ,
352- shortcut : {
353- key : "n" ,
354- modKey : true ,
355- metaKey : false ,
356- ctrlKey : false ,
357- altKey : false ,
358- shiftKey : false ,
359- } ,
360- whenAst : {
361- type : "not" ,
362- node : { type : "identifier" , name : "terminalFocus" } ,
363- } ,
363+ const rows = buildKeybindingRows ( [
364+ {
365+ command : "chat.new" ,
366+ shortcut : {
367+ key : "n" ,
368+ modKey : true ,
369+ metaKey : false ,
370+ ctrlKey : false ,
371+ altKey : false ,
372+ shiftKey : false ,
364373 } ,
365- {
366- command : "chat.new" ,
367- shortcut : {
368- key : "o" ,
369- modKey : true ,
370- metaKey : false ,
371- ctrlKey : false ,
372- altKey : false ,
373- shiftKey : true ,
374- } ,
375- whenAst : {
376- type : "not" ,
377- node : { type : "identifier" , name : "terminalFocus" } ,
378- } ,
374+ whenAst : {
375+ type : "not" ,
376+ node : { type : "identifier" , name : "terminalFocus" } ,
379377 } ,
380- ] satisfies ResolvedKeybindingsConfig ,
381- "" ,
382- ) ;
378+ } ,
379+ {
380+ command : "chat.new" ,
381+ shortcut : {
382+ key : "o" ,
383+ modKey : true ,
384+ metaKey : false ,
385+ ctrlKey : false ,
386+ altKey : false ,
387+ shiftKey : true ,
388+ } ,
389+ whenAst : {
390+ type : "not" ,
391+ node : { type : "identifier" , name : "terminalFocus" } ,
392+ } ,
393+ } ,
394+ ] satisfies ResolvedKeybindingsConfig ) ;
383395
384396 expect ( rows . map ( ( row ) => row . source ) ) . toEqual ( [ "Default" , "Default" ] ) ;
385397 } ) ;
386398
387399 it ( "reports conflicting shortcuts that share an active when context" , ( ) => {
388- const rows = buildKeybindingRows (
389- [
390- {
391- command : "chat.new" ,
392- shortcut : {
393- key : "n" ,
394- modKey : true ,
395- metaKey : false ,
396- ctrlKey : false ,
397- altKey : false ,
398- shiftKey : false ,
399- } ,
400- whenAst : {
401- type : "not" ,
402- node : { type : "identifier" , name : "terminalFocus" } ,
403- } ,
400+ const rows = buildKeybindingRows ( [
401+ {
402+ command : "chat.new" ,
403+ shortcut : {
404+ key : "n" ,
405+ modKey : true ,
406+ metaKey : false ,
407+ ctrlKey : false ,
408+ altKey : false ,
409+ shiftKey : false ,
404410 } ,
405- {
406- command : "chat.newLocal" ,
407- shortcut : {
408- key : "n" ,
409- modKey : true ,
410- metaKey : false ,
411- ctrlKey : false ,
412- altKey : false ,
413- shiftKey : false ,
414- } ,
415- whenAst : {
416- type : "not" ,
417- node : { type : "identifier" , name : "terminalFocus" } ,
418- } ,
411+ whenAst : {
412+ type : "not" ,
413+ node : { type : "identifier" , name : "terminalFocus" } ,
419414 } ,
420- ] satisfies ResolvedKeybindingsConfig ,
421- "" ,
422- ) ;
415+ } ,
416+ {
417+ command : "chat.newLocal" ,
418+ shortcut : {
419+ key : "n" ,
420+ modKey : true ,
421+ metaKey : false ,
422+ ctrlKey : false ,
423+ altKey : false ,
424+ shiftKey : false ,
425+ } ,
426+ whenAst : {
427+ type : "not" ,
428+ node : { type : "identifier" , name : "terminalFocus" } ,
429+ } ,
430+ } ,
431+ ] satisfies ResolvedKeybindingsConfig ) ;
423432
424433 expect ( rows [ 0 ] ?. conflicts ) . toEqual ( [ "Chat: New Local" ] ) ;
425434 expect (
0 commit comments