Skip to content
Closed
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
6 changes: 6 additions & 0 deletions apps/web/src/components/CommandPalette.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
});

Expand Down
10 changes: 7 additions & 3 deletions apps/web/src/components/CommandPalette.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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" });
}
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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,
});
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ import {
getCommandPaletteMode,
ITEM_ICON_CLASS,
RECENT_THREAD_LIMIT,
RECENT_THREADS_GROUP,
createCommandPaletteSearchState,
type CommandPaletteGroup,
resolveAddProjectEntry,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/files/BrowserDocumentFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { primaryServerKeybindingsAtom, serverEnvironment } from "~/state/server"
*/
const HTML_RENDER_SHORTCUT_COMMANDS: ReadonlySet<KeybindingCommand> = new Set([
"commandPalette.toggle",
"commandPalette.recentThreads",
"filePicker.toggle",
"projectSearch.toggle",
"chat.find",
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/composer-rich-text-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
},
});

/**
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/shortcuts/commandPaletteCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
Expand Down
1 change: 1 addition & 0 deletions docs/user/thread-sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
"preview.zoomOut",
"preview.resetZoom",
"commandPalette.toggle",
"commandPalette.recentThreads",
"filePicker.toggle",
"projectSearch.toggle",
"usage.open",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
{ 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" },
Expand Down
Loading