The best way to control Claude Code, Codex and more from any computer or phone
fix(web): Cmd+B toggles the sidebar unless text is selected (#24063)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 23, 2026 at 03:21 UTC
7d6b5bec87a4df0d2a2e6bb60e8a1efefda0ba86
6 files changed
+65
-10
apps/web/src/components/AppSidebarLayout.tsx
+3
-3
@@ -149,12 +149,12 @@ function SidebarControl() {
149
return;
150
}
151
if (
152
- isRichTextBoldShortcut(event) &&
152
+ isRichTextBoldShortcut(event, window.getSelection()) &&
153
event.target instanceof HTMLElement &&
154
event.target.closest('[data-composer-rich-text="true"]')
155
) {
156
- // The rich-text composer claims Mod+B for bold; the toggle stays
157
- // available everywhere else, including the plain-text composer.
156
+ // The rich-text composer claims Mod+B only to bold selected text;
157
+ // the toggle stays available everywhere else.
158
return;
159
}
160
if (
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
+20
@@ -16,6 +16,7 @@ import { userEvent } from "vite-plus/test/browser";
16
import { act, render } from "../../test/render";
17
18
import { serializeEditorDoc } from "~/composer-rich-text-doc";
19
+import { isMacPlatform } from "~/lib/utils";
20
import {
21
ComposerPromptEditor,
22
type ComposerPromptEditorHandle,
@@ -148,6 +149,25 @@ it.each([
149
expect(textWithMark(editor, "code")).toEqual(code);
150
});
151
152
+it("bolds with Mod+B only when text is selected", async () => {
153
+ await using screen = await mountEditor("ship it");
154
+ const { editor } = screen;
155
+ const modB = isMacPlatform(navigator.platform) ? "{Meta>}b{/Meta}" : "{Control>}b{/Control}";
156
+ await act(async () => {
157
+ editor.commands.focus("end");
158
+ });
159
+ await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom));
160
+ await userEvent.keyboard(modB);
161
+ // Without the guard, Tiptap stores bold for the next typed text.
162
+ expect(editor.state.storedMarks).toBeNull();
163
+
164
+ await act(async () => {
165
+ editor.commands.setTextSelection({ from: 1, to: 5 });
166
+ });
167
+ await userEvent.keyboard(modB);
168
+ await vi.waitFor(() => expect(textWithMark(editor, "bold")).toEqual(["ship"]));
169
+});
170
+
171
it.each([false, true])(
172
"composes an umlaut without wrapping the preedit text (rich text: %s)",
173
async (richTextEnabled) => {
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+2
@@ -68,6 +68,7 @@ import {
68
ComposerListExtensions,
69
buildTiptapContent,
70
caretTakesMarksBefore,
71
+ ComposerBoldSelectionOnlyExtension,
72
convertBulletItemToTask,
73
ComposerCodeExtension,
74
ComposerItalicExtension,
@@ -874,6 +875,7 @@ function createComposerExtensions(richText: boolean) {
875
ComposerMarkersExtension,
876
...(richText
877
? [
878
+ ComposerBoldSelectionOnlyExtension,
879
ComposerItalicExtension,
880
ComposerCodeExtension,
881
ComposerCodeBlockExtension.extend({
apps/web/src/composer-rich-text-doc.ts
+15
@@ -15,6 +15,7 @@ import { Italic, starInputRegex, starPasteRegex } from "@tiptap/extension-italic
15
import {
16
type Command,
17
type Editor,
18
+ Extension,
19
markInputRule,
20
markPasteRule,
21
mergeAttributes,
@@ -153,6 +154,20 @@ export const ComposerItalicExtension = Italic.extend({
154
},
155
});
156
157
+/**
158
+ * Mod+B bolds selected text only. Without a selection Tiptap would toggle bold
159
+ * for the next typed text, which users hit by accident when they mean the
160
+ * sidebar toggle. Runs ahead of the Bold extension and swallows the chord.
161
+ */
162
+export const ComposerBoldSelectionOnlyExtension = Extension.create({
163
+ name: "composerBoldSelectionOnly",
164
+ priority: 1000,
165
+ addKeyboardShortcuts() {
166
+ const ignoreWithoutSelection = () => this.editor.state.selection.empty;
167
+ return { "Mod-b": ignoreWithoutSelection, "Mod-B": ignoreWithoutSelection };
168
+ },
169
+});
170
+
171
/**
172
* Tiptap's block extensions each bind a chord that turns the current block into
173
* their node (Mod-Shift-8 for a list, Mod-Alt-c for a fence, and so on). The
apps/web/src/keybindings.test.ts
+15
-3
@@ -713,9 +713,11 @@ describe("resolveShortcutCommand", () => {
713
});
714
715
describe("isRichTextBoldShortcut", () => {
716
+ const selected = { isCollapsed: false };
717
+
718
it("matches the B key on non-Latin layouts, like the sidebar toggle does", () => {
719
const cyrillicB = event({ key: "и", code: "KeyB", ctrlKey: true });
718
- assert.isTrue(isRichTextBoldShortcut(cyrillicB));
720
+ assert.isTrue(isRichTextBoldShortcut(cyrillicB, selected));
721
assert.strictEqual(
722
resolveShortcutCommand(cyrillicB, DEFAULT_BINDINGS, { platform: "Win32" }),
723
"sidebar.toggle",
@@ -723,8 +725,18 @@ describe("isRichTextBoldShortcut", () => {
725
});
726
727
it("follows the letter a Latin layout types, not the physical key", () => {
726
- assert.isFalse(isRichTextBoldShortcut(event({ key: "x", code: "KeyB", ctrlKey: true })));
727
- assert.isTrue(isRichTextBoldShortcut(event({ key: "b", code: "KeyN", ctrlKey: true })));
728
+ assert.isFalse(
729
+ isRichTextBoldShortcut(event({ key: "x", code: "KeyB", ctrlKey: true }), selected),
730
+ );
731
+ assert.isTrue(
732
+ isRichTextBoldShortcut(event({ key: "b", code: "KeyN", ctrlKey: true }), selected),
733
+ );
734
+ });
735
+
736
+ it("leaves the chord to the sidebar toggle when no text is selected", () => {
737
+ const modB = event({ key: "b", metaKey: true });
738
+ assert.isFalse(isRichTextBoldShortcut(modB, { isCollapsed: true }));
739
+ assert.isFalse(isRichTextBoldShortcut(modB, null));
740
});
741
});
742
apps/web/src/keybindings.ts
+10
-4
@@ -371,15 +371,21 @@ export function isOpenFavoriteEditorShortcut(
371
}
372
373
/**
374
- * Whether the keypress is the rich-text bold chord (Mod+B without extra
375
- * modifiers). Tiptap binds the same chord, so app shortcuts captured ahead
376
- * of the editor must yield when the rich-text composer is focused.
374
+ * Whether the keypress should bold text in the rich-text composer: Mod+B
375
+ * without extra modifiers, with text selected. Tiptap binds the same chord, so
376
+ * app shortcuts captured ahead of the editor yield only in that case. With no
377
+ * selection the chord stays with the app (the sidebar toggle by default).
378
*/
378
-export function isRichTextBoldShortcut(event: ShortcutEventLike): boolean {
379
+export function isRichTextBoldShortcut(
380
+ event: ShortcutEventLike,
381
+ selection: Pick<Selection, "isCollapsed"> | null,
382
+): boolean {
383
if (event.type !== undefined && event.type !== "keydown") {
384
return false;
385
}
386
return (
387
+ selection !== null &&
388
+ !selection.isCollapsed &&
389
resolveEventKeys(event).has("b") &&
390
(event.metaKey || event.ctrlKey) &&
391
!event.altKey &&