Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions apps/web/src/components/AppSidebarLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"
Expand All @@ -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]);
Expand Down
30 changes: 0 additions & 30 deletions apps/web/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import {
formatShortcutLabel,
isDiffToggleShortcut,
isRichTextBoldShortcut,
modelPickerJumpCommandForIndex,
modelPickerJumpIndexFromCommand,
isOpenFavoriteEditorShortcut,
Expand Down Expand Up @@ -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(
Expand Down
17 changes: 0 additions & 17 deletions apps/web/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading