Skip to content

Commit c441956

Browse files
fix(web): a declined capture command no longer blocks composer formatting
Capture-phase scopes run before the composer sees the keydown, so one still in play has already declined it (editor.openFavorite with no enabled button). Only bubble-phase commands, which have not run yet, now make the composer yield Mod+B/I/E. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ed7ffe0 commit c441956

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@ it.each([
225225
);
226226

227227
it.each([
228-
["e", false],
229-
["i", false],
230-
["e", true],
228+
["e", false, false],
229+
["i", false, false],
230+
["e", true, false],
231+
["e", false, true],
231232
])(
232-
"leaves Mod+%s to an app command bound to it instead of formatting (composer command: %s)",
233-
async (key, composerClaimsKey) => {
233+
"leaves Mod+%s to an app command bound to it instead of formatting (composer command: %s, declined capture command: %s)",
234+
async (key, composerClaimsKey, declinedCapture) => {
234235
const openUsage = vi.fn((event: KeyboardEvent) => {
236+
if (declinedCapture) return false;
235237
event.preventDefault();
236238
});
237239
using _commands = {
@@ -251,6 +253,7 @@ it.each([
251253
},
252254
},
253255
],
256+
capture: declinedCapture,
254257
},
255258
),
256259
};
@@ -266,7 +269,7 @@ it.each([
266269
await userEvent.keyboard(`{${modifier}>}${key}{/${modifier}}`);
267270
expect(composerCommand).toHaveBeenCalled();
268271
expect(openUsage).toHaveBeenCalledTimes(composerClaimsKey ? 0 : 1);
269-
expect(serializeEditorDoc(editor.state.doc).value).toBe("word");
272+
expect(serializeEditorDoc(editor.state.doc).value).toBe(declinedCapture ? "`word`" : "word");
270273
},
271274
);
272275

‎apps/web/src/shortcuts/dispatcher.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ function runScope(scope: CommandScope, event: KeyboardEvent): boolean {
8080
return handler(event) !== false;
8181
}
8282

83-
/** Whether a registered command is bound to this keydown, for widgets that would otherwise consume it. */
83+
/**
84+
* Whether a bubble-phase command is bound to this keydown, for widgets that would otherwise
85+
* consume it. Capture scopes have already run (and declined) by the time a widget sees it.
86+
*/
8487
export function hasCommandForKeyDown(event: KeyboardEvent): boolean {
85-
return [...captureScopes, ...globalScopes].some(
88+
return globalScopes.some(
8689
(scope) =>
8790
(!scope.options.when || scope.options.when(event)) &&
8891
scopeCommandHandler(scope, event) !== undefined,

0 commit comments

Comments
 (0)