The best way to control Claude Code, Codex and more from any computer or phone
fix(web): app keybindings on Mod+B, Mod+I and Mod+E win over composer formatting (#34493)
Julius Marminge committed
Nov 11, 2026 at 16:52 UTC
6a03ef6568da3f962714b1ea8f0de91a947c9014
4 files changed
+104
-5
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
+61
-1
@@ -19,6 +19,7 @@ import { act, fakeTimers, render } from "../../test/render";
19
20
import { flatToMarkdown, pmToFlat, serializeEditorDoc } from "~/composer-rich-text-doc";
21
import { isMacPlatform } from "~/lib/utils";
22
+import { registerCommands } from "~/shortcuts/dispatcher";
23
import {
24
ComposerPromptEditorTiptap as ComposerPromptEditor,
25
type ComposerPromptEditorHandle,
@@ -36,11 +37,13 @@ function Composer({
37
richTextEnabled,
38
skills,
39
onChange,
40
+ onCommandKeyDown = () => false,
41
}: {
42
value: string;
43
richTextEnabled: boolean;
44
skills: ReadonlyArray<ServerProviderSkill>;
45
onChange?: ComposerPromptEditorProps["onChange"] | undefined;
46
+ onCommandKeyDown?: ComposerPromptEditorProps["onCommandKeyDown"] | undefined;
47
}) {
48
const [prompt, setPrompt] = useState({ value, cursor: value.length });
49
return (
@@ -58,6 +61,7 @@ function Composer({
61
onChange?.(...args);
62
}}
63
onPaste={() => {}}
64
+ onCommandKeyDown={onCommandKeyDown}
65
/>
66
);
67
}
@@ -67,9 +71,16 @@ function composer(
71
richTextEnabled = true,
72
skills: ReadonlyArray<ServerProviderSkill> = [],
73
onChange?: ComposerPromptEditorProps["onChange"],
74
+ onCommandKeyDown?: ComposerPromptEditorProps["onCommandKeyDown"],
75
) {
76
return (
72
- <Composer value={value} richTextEnabled={richTextEnabled} skills={skills} onChange={onChange} />
77
+ <Composer
78
+ value={value}
79
+ richTextEnabled={richTextEnabled}
80
+ skills={skills}
81
+ onChange={onChange}
82
+ onCommandKeyDown={onCommandKeyDown}
83
+ />
84
);
85
}
86
@@ -254,6 +265,55 @@ it.each([
265
},
266
);
267
268
+it.each([
269
+ ["e", false, false],
270
+ ["i", false, false],
271
+ ["e", true, false],
272
+ ["e", false, true],
273
+])(
274
+ "leaves Mod+%s to an app command bound to it instead of formatting (composer command: %s, declined capture command: %s)",
275
+ async (key, composerClaimsKey, declinedCapture) => {
276
+ const openUsage = vi.fn((event: KeyboardEvent) => {
277
+ if (declinedCapture) return false;
278
+ event.preventDefault();
279
+ });
280
+ using _commands = {
281
+ [Symbol.dispose]: registerCommands(
282
+ { "usage.open": openUsage },
283
+ {
284
+ keybindings: () => [
285
+ {
286
+ command: "usage.open",
287
+ shortcut: {
288
+ key,
289
+ metaKey: false,
290
+ ctrlKey: false,
291
+ shiftKey: false,
292
+ altKey: false,
293
+ modKey: true,
294
+ },
295
+ },
296
+ ],
297
+ capture: declinedCapture,
298
+ },
299
+ ),
300
+ };
301
+ const composerCommand = vi.fn(() => composerClaimsKey);
302
+ await using screen = await mountEditor("word", true, [], undefined, composerCommand);
303
+ const { editor } = screen;
304
+ await act(async () => {
305
+ editor.commands.focus();
306
+ editor.commands.setTextSelection({ from: 1, to: 5 });
307
+ });
308
+ await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom));
309
+ const modifier = isMacPlatform(navigator.platform) ? "Meta" : "Control";
310
+ await userEvent.keyboard(`{${modifier}>}${key}{/${modifier}}`);
311
+ expect(composerCommand).toHaveBeenCalled();
312
+ expect(openUsage).toHaveBeenCalledTimes(composerClaimsKey ? 0 : 1);
313
+ expect(serializeEditorDoc(editor.state.doc).value).toBe(declinedCapture ? "`word`" : "word");
314
+ },
315
+);
316
+
317
it.each([false, true])(
318
"composes an umlaut without wrapping the preedit text (rich text: %s)",
319
async (richTextEnabled) => {
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+15
@@ -112,7 +112,9 @@ import {
112
} from "~/composer-undo-grouping";
113
import { collectInlineContextIds } from "~/lib/composerContextReferences";
114
import { resolveDiffThemeName } from "~/lib/diffRendering";
115
+import { isRichTextFormattingShortcut } from "~/keybindings";
116
import { cn, isMacPlatform } from "~/lib/utils";
117
+import { hasCommandForKeyDown } from "~/shortcuts/dispatcher";
118
import { basenameOfPath } from "~/pierre-icons";
119
import { WorkspaceEntryTooltip } from "./chat/WorkspaceEntryIcon";
120
import { FileTagChipContent } from "./chat/FileTagChip";
@@ -1107,6 +1109,19 @@ function ComposerPromptEditorTiptapInner(
1109
editable: !disabled,
1110
editorProps: {
1111
attributes: editorAttributes,
1112
+ handleDOMEvents: {
1113
+ // Composer commands keep precedence; otherwise true skips the editor's keymaps without
1114
+ // preventDefault, so a bound app command still runs.
1115
+ keydown: (_view, event) => {
1116
+ if (!isRichTextFormattingShortcut(event)) return false;
1117
+ if (readCallbacks().onCommandKeyDown?.(event.key, event)) {
1118
+ event.preventDefault();
1119
+ event.stopPropagation();
1120
+ return true;
1121
+ }
1122
+ return hasCommandForKeyDown(event);
1123
+ },
1124
+ },
1125
handleKeyDown: (view, event) => {
1126
// In a right-to-left line the start is on the right.
1127
const backArrow = caretLineDirection(view.state) === "rtl" ? "ArrowRight" : "ArrowLeft";
apps/web/src/keybindings.ts
+7
@@ -398,6 +398,13 @@ export function isRichTextBoldShortcut(
398
);
399
}
400
401
+/** Mod+B, Mod+I and Mod+E, the mark chords the rich-text composer binds. */
402
+export function isRichTextFormattingShortcut(event: ShortcutEventLike): boolean {
403
+ if (!(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey) return false;
404
+ const keys = resolveEventKeys(event);
405
+ return keys.has("b") || keys.has("i") || keys.has("e");
406
+}
407
+
408
export function isTerminalClearShortcut(
409
event: ShortcutEventLike,
410
platform = navigator.platform,
apps/web/src/shortcuts/dispatcher.ts
+21
-4
@@ -57,16 +57,21 @@ function isInsideConfirmation(target: EventTarget | null): boolean {
57
return target instanceof Element && target.closest('[role="alertdialog"]') !== null;
58
}
59
60
-function runScope(scope: CommandScope, event: KeyboardEvent): boolean {
60
+function scopeCommandHandler(scope: CommandScope, event: KeyboardEvent) {
61
const { commands, options } = scope;
62
- if (options.when && !options.when(event)) return false;
63
- if (options.onKeyDown && options.onKeyDown(event) !== false) return true;
62
const command = resolveShortcutCommand(
63
event,
64
options.keybindings?.() ?? appAtomRegistry.get(primaryServerKeybindingsAtom),
65
{ context: { ...readFocusContext(event), ...options.context?.() } },
66
);
69
- const handler = command === null ? undefined : commands[command];
67
+ return command === null ? undefined : commands[command];
68
+}
69
+
70
+function runScope(scope: CommandScope, event: KeyboardEvent): boolean {
71
+ const { options } = scope;
72
+ if (options.when && !options.when(event)) return false;
73
+ if (options.onKeyDown && options.onKeyDown(event) !== false) return true;
74
+ const handler = scopeCommandHandler(scope, event);
75
if (handler === undefined) return false;
76
if (isInsideConfirmation(event.target)) {
77
event.preventDefault();
@@ -75,6 +80,18 @@ function runScope(scope: CommandScope, event: KeyboardEvent): boolean {
80
return handler(event) !== false;
81
}
82
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
+ */
87
+export function hasCommandForKeyDown(event: KeyboardEvent): boolean {
88
+ return globalScopes.some(
89
+ (scope) =>
90
+ (!scope.options.when || scope.options.when(event)) &&
91
+ scopeCommandHandler(scope, event) !== undefined,
92
+ );
93
+}
94
+
95
function runScopes(scopes: readonly CommandScope[], event: KeyboardEvent): boolean {
96
for (let index = scopes.length - 1; index >= 0; index -= 1) {
97
if (event.defaultPrevented) return true;