diff --git a/apps/web/src/components/AppSidebarLayout.tsx b/apps/web/src/components/AppSidebarLayout.tsx index 05d965d95d06..d3b2d96169ec 100644 --- a/apps/web/src/components/AppSidebarLayout.tsx +++ b/apps/web/src/components/AppSidebarLayout.tsx @@ -11,11 +11,7 @@ import { useLocation, useNavigate, useParams } from "@tanstack/react-router"; import { isElectron } from "../env"; import { getLocalStorageItem, removeLocalStorageItem } from "../hooks/useLocalStorage"; -import { - isRichTextBoldShortcut, - resolveShortcutCommand, - shortcutLabelForCommand, -} from "../keybindings"; +import { resolveShortcutCommand, shortcutLabelForCommand } from "../keybindings"; import { isEditableFocused } from "../lib/editableFocus"; import { isPreviewFocused } from "../lib/previewFocus"; import { isTerminalFocused } from "../lib/terminalFocus"; @@ -100,15 +96,6 @@ function SidebarControl() { ) { return; } - if ( - isRichTextBoldShortcut(event) && - event.target instanceof HTMLElement && - event.target.closest('[data-composer-rich-text="true"]') - ) { - // The rich-text composer claims Mod+B for bold; the toggle stays - // available everywhere else, including the plain-text composer. - return; - } if ( resolveShortcutCommand(event, keybindings, { context: { usagePageOpen } }) !== "sidebar.toggle" @@ -120,7 +107,8 @@ function SidebarControl() { toggleSidebar(); }; - // Capture before focused editors consume commands such as Mod+B for rich-text formatting. + // Capture before focused editors consume the chord: the rich-text composer + // binds Mod+B to bold, and the sidebar toggle wins there too. window.addEventListener("keydown", onKeyDown, true); return () => window.removeEventListener("keydown", onKeyDown, true); }, [keybindings, toggleSidebar, usagePageOpen]); diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts index a5fc2374be56..a04e9e0b5ee7 100644 --- a/apps/web/src/keybindings.test.ts +++ b/apps/web/src/keybindings.test.ts @@ -14,7 +14,6 @@ import { import { formatShortcutLabel, isDiffToggleShortcut, - isRichTextBoldShortcut, modelPickerJumpCommandForIndex, modelPickerJumpIndexFromCommand, isOpenFavoriteEditorShortcut, @@ -1070,35 +1069,6 @@ describe("isTerminalClearShortcut", () => { }); }); -describe("isRichTextBoldShortcut", () => { - it("matches Mod+B without extra modifiers", () => { - assert.isTrue(isRichTextBoldShortcut(event({ key: "b", metaKey: true }))); - assert.isTrue(isRichTextBoldShortcut(event({ key: "B", ctrlKey: true }))); - }); - - it("matches the B key on non-Latin layouts, like the sidebar toggle does", () => { - const cyrillicB = event({ key: "и", code: "KeyB", ctrlKey: true }); - assert.isTrue(isRichTextBoldShortcut(cyrillicB)); - assert.strictEqual( - resolveShortcutCommand(cyrillicB, DEFAULT_BINDINGS, { platform: "Win32" }), - "sidebar.toggle", - ); - }); - - it("follows the letter a Latin layout types, not the physical key", () => { - assert.isFalse(isRichTextBoldShortcut(event({ key: "x", code: "KeyB", ctrlKey: true }))); - assert.isTrue(isRichTextBoldShortcut(event({ key: "b", code: "KeyN", ctrlKey: true }))); - }); - - it("ignores shifted, alted, bare, and non-keydown presses", () => { - assert.isFalse(isRichTextBoldShortcut(event({ key: "b", metaKey: true, shiftKey: true }))); - assert.isFalse(isRichTextBoldShortcut(event({ key: "b", metaKey: true, altKey: true }))); - assert.isFalse(isRichTextBoldShortcut(event({ key: "b" }))); - assert.isFalse(isRichTextBoldShortcut(event({ key: "i", metaKey: true }))); - assert.isFalse(isRichTextBoldShortcut(event({ type: "keyup", key: "b", metaKey: true }))); - }); -}); - describe("terminalDeleteShortcutData", () => { it("maps Cmd+Backspace on macOS to delete-to-line-start", () => { assert.strictEqual( diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.ts index 73b59bc20b29..261f2d3b15b3 100644 --- a/apps/web/src/keybindings.ts +++ b/apps/web/src/keybindings.ts @@ -415,23 +415,6 @@ export function isOpenFavoriteEditorShortcut( return matchesCommandShortcut(event, keybindings, "editor.openFavorite", options); } -/** - * Whether the keypress is the rich-text bold chord (Mod+B without extra - * modifiers). Tiptap binds the same chord, so app shortcuts captured ahead - * of the editor must yield when the rich-text composer is focused. - */ -export function isRichTextBoldShortcut(event: ShortcutEventLike): boolean { - if (event.type !== undefined && event.type !== "keydown") { - return false; - } - return ( - resolveEventKeys(event).has("b") && - (event.metaKey || event.ctrlKey) && - !event.altKey && - !event.shiftKey - ); -} - export function isTerminalClearShortcut( event: ShortcutEventLike, platform = navigator.platform,