diff --git a/apps/web/src/components/CommandPalette.logic.test.ts b/apps/web/src/components/CommandPalette.logic.test.ts index 7ec1a3e9ac1e3..67966d79c513d 100644 --- a/apps/web/src/components/CommandPalette.logic.test.ts +++ b/apps/web/src/components/CommandPalette.logic.test.ts @@ -104,6 +104,12 @@ describe("reduceCommandPaletteUiState", () => { openIntent: { kind: "add-project" }, session: 2, }); + state = reduceCommandPaletteUiState(state, { _tag: "OpenRecentThreads" }); + expect(state).toMatchObject({ + mode: "command", + openIntent: { kind: "recent-threads" }, + session: 3, + }); }); }); diff --git a/apps/web/src/components/CommandPalette.logic.ts b/apps/web/src/components/CommandPalette.logic.ts index 6102028889369..3159a2359ed7e 100644 --- a/apps/web/src/components/CommandPalette.logic.ts +++ b/apps/web/src/components/CommandPalette.logic.ts @@ -34,6 +34,7 @@ import { type Project, type SidebarThreadSummary, type Thread } from "../types"; import { isSidebarSubagentThread } from "./Sidebar.logic"; export const RECENT_THREAD_LIMIT = 12; +export const RECENT_THREADS_GROUP = "recent-threads"; export const ITEM_ICON_CLASS = "size-4 text-icon-muted"; export const ADDON_ICON_CLASS = "size-4"; @@ -71,7 +72,7 @@ export function browseInputEndPaddingClass(input: { export type SearchOverlayMode = "command" | "files" | "content"; export type CommandPaletteOpenIntent = - | { readonly kind: "add-project" | "new-thread-in" | "change-theme" } + | { readonly kind: "add-project" | "new-thread-in" | "change-theme" | "recent-threads" } | { readonly kind: "search"; readonly query: string; @@ -100,6 +101,7 @@ export type CommandPaletteUiAction = | { readonly _tag: "OpenAddProject" } | { readonly _tag: "OpenNewThreadIn" } | { readonly _tag: "OpenChangeTheme" } + | { readonly _tag: "OpenRecentThreads" } | { readonly _tag: "OpenChildSearch"; readonly mode: "files" | "content"; @@ -157,6 +159,8 @@ export function reduceCommandPaletteUiState( return openWithIntent({ kind: "new-thread-in" }); case "OpenChangeTheme": return openWithIntent({ kind: "change-theme" }); + case "OpenRecentThreads": + return openWithIntent({ kind: "recent-threads" }); } } @@ -569,7 +573,7 @@ export function filterCommandPaletteGroups(input: { if (isActionsFilter) { baseGroups = baseGroups.filter((group) => group.value === "actions"); } else if (!input.isInSubmenu) { - baseGroups = baseGroups.filter((group) => group.value !== "recent-threads"); + baseGroups = baseGroups.filter((group) => group.value !== RECENT_THREADS_GROUP); } const searchableGroups = [...baseGroups]; @@ -756,7 +760,7 @@ export function buildRootGroups(input: { } if (input.recentThreadItems.length > 0) { groups.push({ - value: "recent-threads", + value: RECENT_THREADS_GROUP, label: "Recent Threads", items: input.recentThreadItems, }); diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsx index 50c3452404344..c58bb8ca7c946 100644 --- a/apps/web/src/components/CommandPalette.tsx +++ b/apps/web/src/components/CommandPalette.tsx @@ -180,6 +180,7 @@ import { getCommandPaletteMode, ITEM_ICON_CLASS, RECENT_THREAD_LIMIT, + RECENT_THREADS_GROUP, createCommandPaletteSearchState, type CommandPaletteGroup, resolveAddProjectEntry, @@ -264,6 +265,7 @@ function openIntentView(intent: CommandPaletteOpenIntent | null): CommandPalette groups: [{ value: "themes", label: "Change theme", items: [] }], }; case "search": + case "recent-threads": case undefined: return null; } @@ -385,6 +387,7 @@ function OpenCommandPaletteDialog(props: { }, ); const linkedThreadSearch = initialSearch.linkedThreadSearch; + const [opensOnRecentThreads] = useState(() => props.openIntent?.kind === "recent-threads"); const [searchState, dispatchSearch] = useReducer(reduceCommandPaletteSearchState, null, () => { const view = props.initialContext ? null : openIntentView(props.openIntent); return view @@ -1608,7 +1611,10 @@ function OpenCommandPaletteDialog(props: { ? changeThemeItem.groups : currentView?.groups[0]?.value === "appearance" ? changeAppearanceItem.groups - : (currentView?.groups ?? rootGroups); + : (currentView?.groups ?? + (opensOnRecentThreads && deferredQuery === "" && recentThreadItems.length > 0 + ? rootGroups.filter((group) => group.value === RECENT_THREADS_GROUP) + : rootGroups)); const isLinkedThreadSearch = linkedThreadSearch?.linkedThreads !== undefined && deferredQuery === linkedThreadSearch.query; diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index c59724cccf693..6592dd2451761 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -149,24 +149,43 @@ it.each([ expect(textWithMark(editor, "code")).toEqual(code); }); -it("bolds with Mod+B only when text is selected", async () => { - await using screen = await mountEditor("ship it"); - const { editor } = screen; - const modB = isMacPlatform(navigator.platform) ? "{Meta>}b{/Meta}" : "{Control>}b{/Control}"; - await act(async () => { - editor.commands.focus("end"); - }); - await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom)); - await userEvent.keyboard(modB); - // Without the guard, Tiptap stores bold for the next typed text. - expect(editor.state.storedMarks).toBeNull(); +it.each([ + // The sidebar toggle claims Mod+B in the capture phase, so the composer may swallow it. + { key: "b", mark: "bold", passesThrough: false }, + { key: "e", mark: "code", passesThrough: true }, +])( + "applies $mark with Mod+$key only when text is selected", + async ({ key, mark, passesThrough }) => { + await using screen = await mountEditor("ship it"); + const { editor } = screen; + const chord = isMacPlatform(navigator.platform) + ? `{Meta>}${key}{/Meta}` + : `{Control>}${key}{/Control}`; + await act(async () => { + editor.commands.focus("end"); + }); + await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom)); + const consumed: boolean[] = []; + const onKeyDown = (event: KeyboardEvent) => { + if (event.key === key) consumed.push(event.defaultPrevented); + }; + using listener = new DisposableStack(); + window.addEventListener("keydown", onKeyDown); + listener.defer(() => window.removeEventListener("keydown", onKeyDown)); + + await userEvent.keyboard(chord); + // Without the guard, Tiptap stores the mark for the next typed text. + expect(editor.state.storedMarks).toBeNull(); + expect(consumed).toEqual([!passesThrough]); - await act(async () => { - editor.commands.setTextSelection({ from: 1, to: 5 }); - }); - await userEvent.keyboard(modB); - await vi.waitFor(() => expect(textWithMark(editor, "bold")).toEqual(["ship"])); -}); + await act(async () => { + editor.commands.setTextSelection({ from: 1, to: 5 }); + }); + await userEvent.keyboard(chord); + await vi.waitFor(() => expect(textWithMark(editor, mark)).toEqual(["ship"])); + expect(consumed).toEqual([!passesThrough, true]); + }, +); it.each([false, true])( "composes an umlaut without wrapping the preedit text (rich text: %s)", diff --git a/apps/web/src/components/files/BrowserDocumentFrame.tsx b/apps/web/src/components/files/BrowserDocumentFrame.tsx index e8d3139a8ae70..0c0d3950e4767 100644 --- a/apps/web/src/components/files/BrowserDocumentFrame.tsx +++ b/apps/web/src/components/files/BrowserDocumentFrame.tsx @@ -51,6 +51,7 @@ import { primaryServerKeybindingsAtom, serverEnvironment } from "~/state/server" */ const HTML_RENDER_SHORTCUT_COMMANDS: ReadonlySet = new Set([ "commandPalette.toggle", + "commandPalette.recentThreads", "filePicker.toggle", "projectSearch.toggle", "chat.find", diff --git a/apps/web/src/composer-rich-text-doc.ts b/apps/web/src/composer-rich-text-doc.ts index c0e0a653016e3..d9d036ab3dcdc 100644 --- a/apps/web/src/composer-rich-text-doc.ts +++ b/apps/web/src/composer-rich-text-doc.ts @@ -138,6 +138,13 @@ export const ComposerCodeExtension = Code.extend({ addProseMirrorPlugins() { return [...(this.parent?.() ?? []), codePairCaretPlugin(this.type)]; }, + // Mod+E formats selected text only; without a selection the key falls + // through to the Recent Threads shortcut. + addKeyboardShortcuts() { + return { + "Mod-e": () => !this.editor.state.selection.empty && this.editor.commands.toggleCode(), + }; + }, }); /** diff --git a/apps/web/src/shortcuts/commandPaletteCommands.ts b/apps/web/src/shortcuts/commandPaletteCommands.ts index 716717061e868..aa63f9c2c5ae4 100644 --- a/apps/web/src/shortcuts/commandPaletteCommands.ts +++ b/apps/web/src/shortcuts/commandPaletteCommands.ts @@ -93,6 +93,11 @@ export function installCommandPaletteCommands( void router.navigate({ to: "/usage" }); }, "commandPalette.toggle": toggleOverlay("commandPalette.toggle"), + "commandPalette.recentThreads": (event) => { + consume(event); + if (event.repeat) return; + dispatchCommandPalette({ _tag: "OpenRecentThreads" }); + }, "filePicker.toggle": toggleOverlay("filePicker.toggle"), "projectSearch.toggle": toggleOverlay("projectSearch.toggle"), }, diff --git a/docs/user/thread-sidebar.md b/docs/user/thread-sidebar.md index fb5e12b08372b..14180f7d59def 100644 --- a/docs/user/thread-sidebar.md +++ b/docs/user/thread-sidebar.md @@ -220,6 +220,7 @@ you last picked for a query ranks higher when you type that query again. Threads whose messages contain all your words appear below, under **In messages**, and open at the matching message. Message search needs at least one word of three or more letters, or two for Chinese, Japanese, and Korean. +`Cmd/Ctrl+E` opens the palette straight to your recent threads. On mobile, the thread list search also lists message matches and opens them at the matching message; on an iPad with a keyboard, `Cmd+K` opens the same palette. diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.ts index 714e0a1d486a1..30078ed9a1645 100644 --- a/packages/contracts/src/keybindings.ts +++ b/packages/contracts/src/keybindings.ts @@ -80,6 +80,7 @@ export const STATIC_KEYBINDING_COMMANDS = [ "preview.zoomOut", "preview.resetZoom", "commandPalette.toggle", + "commandPalette.recentThreads", "filePicker.toggle", "projectSearch.toggle", "usage.open", diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.ts index 32292c0f9ef21..7f3a4f026a9af 100644 --- a/packages/shared/src/keybindings.ts +++ b/packages/shared/src/keybindings.ts @@ -172,6 +172,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray = [ { key: "mod+-", command: "preview.zoomOut", when: "previewFocus" }, { key: "mod+0", command: "preview.resetZoom", when: "previewFocus" }, { key: "mod+k", command: "commandPalette.toggle", when: "!terminalFocus" }, + { key: "mod+e", command: "commandPalette.recentThreads", when: "!terminalFocus" }, { key: "mod+p", command: "filePicker.toggle", when: "!terminalFocus" }, { key: "mod+shift+f", command: "projectSearch.toggle", when: "!terminalFocus" }, { key: "mod+u", command: "usage.open", when: "!terminalFocus" },