@@ -102,17 +102,41 @@ describe("composerSubmissionIntentForKey", () => {
102102 metaKey : platform === "MacIntel" ,
103103 ctrlKey : platform !== "MacIntel" ,
104104 } ;
105- for ( const sendShortcut of [ "enter" , "mod-enter" , "mod-enter-multiline" ] as const ) {
106- const running = { ...input , platform, sendShortcut, prompt : "two\nlines" , isRunning : true } ;
105+ for ( const [ sendShortcut , prompt , requiresModifier ] of [
106+ [ "enter" , "one line" , false ] ,
107+ [ "enter" , "two\nlines" , false ] ,
108+ [ "mod-enter" , "one line" , true ] ,
109+ [ "mod-enter" , "two\nlines" , true ] ,
110+ [ "mod-enter-multiline" , "one line" , false ] ,
111+ [ "mod-enter-multiline" , "two\nlines" , true ] ,
112+ ] as const ) {
113+ const running = { ...input , platform, sendShortcut, prompt, isRunning : true } ;
107114 const intent = composerSubmissionIntentForKey ( { ...running , event : modEnter } ) ;
108- expect ( intent ) . toBe ( "alternate" ) ;
115+ expect ( intent ) . toBe ( requiresModifier ? "foreground" : "alternate" ) ;
116+ const alternateIntent = composerSubmissionIntentForKey ( {
117+ ...running ,
118+ event : { ...modEnter , shiftKey : requiresModifier } ,
119+ } ) ;
120+ expect ( alternateIntent ) . toBe ( "alternate" ) ;
121+ expect ( composerSubmissionIntentForKey ( { ...running , event : enter } ) ) . toBe (
122+ requiresModifier ? null : "foreground" ,
123+ ) ;
109124 for ( const activeTurnDefault of [ "queue" , "steer" ] as const ) {
110125 expect (
111126 resolveComposerDispatchMode ( {
112127 running : true ,
113128 alternateModifier : intent === "alternate" ,
114129 activeTurnDefault,
115130 } ) ,
131+ ) . toBe (
132+ requiresModifier ? activeTurnDefault : activeTurnDefault === "queue" ? "steer" : "queue" ,
133+ ) ;
134+ expect (
135+ resolveComposerDispatchMode ( {
136+ running : true ,
137+ alternateModifier : alternateIntent === "alternate" ,
138+ activeTurnDefault,
139+ } ) ,
116140 ) . toBe ( activeTurnDefault === "queue" ? "steer" : "queue" ) ;
117141 }
118142 expect (
@@ -137,6 +161,7 @@ describe("composerSubmissionIntentForKey", () => {
137161 ...input ,
138162 platform,
139163 sendShortcut,
164+ prompt,
140165 isDraftThread : true ,
141166 event : modEnter ,
142167 } ) ,
@@ -157,6 +182,28 @@ describe("composerSubmissionIntentForKey", () => {
157182 ) . toBeNull ( ) ;
158183 } ) ;
159184
185+ it ( "honors the send preference with an existing install's saved alternate binding" , ( ) => {
186+ const keybindings = mergeWithDefaultKeybindings (
187+ compileResolvedKeybindingsConfig ( [
188+ {
189+ key : "mod+enter" ,
190+ command : "composer.sendAlternate" ,
191+ when : "composerFocus && turnRunning" ,
192+ } ,
193+ ] ) ,
194+ ) ;
195+ const running = { ...input , keybindings, isRunning : true , sendShortcut : "mod-enter" as const } ;
196+ expect ( composerSubmissionIntentForKey ( { ...running , event : { ...enter , ctrlKey : true } } ) ) . toBe (
197+ "foreground" ,
198+ ) ;
199+ expect (
200+ composerSubmissionIntentForKey ( {
201+ ...running ,
202+ event : { ...enter , ctrlKey : true , shiftKey : true } ,
203+ } ) ,
204+ ) . toBe ( "alternate" ) ;
205+ } ) ;
206+
160207 it ( "does not start a background thread with the queued-message shortcut" , ( ) => {
161208 expect (
162209 composerSubmissionIntentForKey ( {
@@ -186,54 +233,64 @@ describe("composerSubmissionIntentForKey", () => {
186233 ) . toBe ( "background" ) ;
187234 } ) ;
188235
189- it ( "uses remapped keys and removes the old action bindings" , ( ) => {
190- const keybindings = mergeWithDefaultKeybindings (
191- compileResolvedKeybindingsConfig ( [
192- {
193- key : "alt+q" ,
194- command : "composer.sendAlternate" ,
195- when : "composerFocus && turnRunning" ,
196- } ,
197- {
198- key : "alt+b" ,
199- command : "composer.sendBackground" ,
200- when : "composerFocus && draftThreadRoute" ,
201- } ,
202- ] ) ,
203- ) ;
204- const custom = { ...input , keybindings } ;
205- expect (
206- composerSubmissionIntentForKey ( {
207- ...custom ,
208- isRunning : true ,
209- event : { ...enter , key : "q" , altKey : true } ,
210- } ) ,
211- ) . toBe ( "alternate" ) ;
212- expect (
213- composerSubmissionIntentForKey ( {
214- ...custom ,
215- isDraftThread : true ,
216- event : { ...enter , key : "b" , altKey : true } ,
217- } ) ,
218- ) . toBe ( "background" ) ;
219- expect (
220- composerSubmissionIntentForKey ( {
221- ...custom ,
222- isRunning : true ,
223- event : { ...enter , ctrlKey : true } ,
224- } ) ,
225- ) . toBe ( "foreground" ) ;
226- expect (
227- composerSubmissionIntentForKey ( {
228- ...custom ,
229- isDraftThread : true ,
230- event : { ...enter , ctrlKey : true , shiftKey : true } ,
231- } ) ,
232- ) . toBeNull ( ) ;
233- expect (
234- composerSubmissionIntentForKey ( { ...custom , event : { ...enter , key : "b" , altKey : true } } ) ,
235- ) . toBeNull ( ) ;
236- } ) ;
236+ it . each ( [ "enter" , "mod-enter" , "mod-enter-multiline" ] as const ) (
237+ "uses remapped keys and removes the old action bindings with %s" ,
238+ ( sendShortcut ) => {
239+ const keybindings = mergeWithDefaultKeybindings (
240+ compileResolvedKeybindingsConfig ( [
241+ {
242+ key : "alt+q" ,
243+ command : "composer.sendAlternate" ,
244+ when : "composerFocus && turnRunning" ,
245+ } ,
246+ {
247+ key : "alt+b" ,
248+ command : "composer.sendBackground" ,
249+ when : "composerFocus && draftThreadRoute" ,
250+ } ,
251+ ] ) ,
252+ ) ;
253+ const custom = { ...input , keybindings, sendShortcut, prompt : "two\nlines" } ;
254+ expect (
255+ composerSubmissionIntentForKey ( {
256+ ...custom ,
257+ isRunning : true ,
258+ event : { ...enter , key : "q" , altKey : true } ,
259+ } ) ,
260+ ) . toBe ( "alternate" ) ;
261+ expect (
262+ composerSubmissionIntentForKey ( {
263+ ...custom ,
264+ isDraftThread : true ,
265+ event : { ...enter , key : "b" , altKey : true } ,
266+ } ) ,
267+ ) . toBe ( "background" ) ;
268+ expect (
269+ composerSubmissionIntentForKey ( {
270+ ...custom ,
271+ isRunning : true ,
272+ event : { ...enter , ctrlKey : true } ,
273+ } ) ,
274+ ) . toBe ( "foreground" ) ;
275+ expect (
276+ composerSubmissionIntentForKey ( {
277+ ...custom ,
278+ isDraftThread : true ,
279+ event : { ...enter , ctrlKey : true , shiftKey : true } ,
280+ } ) ,
281+ ) . toBeNull ( ) ;
282+ expect (
283+ composerSubmissionIntentForKey ( {
284+ ...custom ,
285+ isRunning : true ,
286+ event : { ...enter , ctrlKey : true , shiftKey : true } ,
287+ } ) ,
288+ ) . toBeNull ( ) ;
289+ expect (
290+ composerSubmissionIntentForKey ( { ...custom , event : { ...enter , key : "b" , altKey : true } } ) ,
291+ ) . toBeNull ( ) ;
292+ } ,
293+ ) ;
237294
238295 it . each ( [
239296 { isMobileViewport : true } ,
0 commit comments