Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a2fc6fcb1 | ||
|
|
d1e958033f | ||
|
|
2d47508c2c | ||
|
|
9b458ef115 |
No files matched your search
@@ -65,6 +65,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
|
||||
{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },
|
||||
{ key: "mod+n", command: "terminal.new", when: "terminalFocus" },
|
||||
{ key: "mod+w", command: "terminal.close", when: "terminalFocus" },
|
||||
{ key: "mod+d", command: "diff.toggle", when: "!terminalFocus" },
|
||||
{ key: "mod+n", command: "chat.new", when: "!terminalFocus" },
|
||||
{ key: "mod+shift+o", command: "chat.new", when: "!terminalFocus" },
|
||||
{ key: "mod+shift+n", command: "chat.newLocal", when: "!terminalFocus" },
|
||||
|
||||
@@ -91,6 +91,7 @@ import { Menu, MenuItem, MenuPopup, MenuShortcut, MenuTrigger } from "./ui/menu"
|
||||
import { CursorIcon, Icon } from "./Icons";
|
||||
import { cn, isMacPlatform, isWindowsPlatform } from "~/lib/utils";
|
||||
import { Badge } from "./ui/badge";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
import { Command, CommandInput, CommandItem, CommandList } from "./ui/command";
|
||||
import { decodeProjectScriptKeybindingRule } from "~/lib/projectScriptKeybindings";
|
||||
import ProjectScriptsControl, { type NewProjectScriptInput } from "./ProjectScriptsControl";
|
||||
@@ -615,6 +616,21 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
() => shortcutLabelForCommand(keybindings, "terminal.close"),
|
||||
[keybindings],
|
||||
);
|
||||
const diffPanelShortcutLabel = useMemo(
|
||||
() => shortcutLabelForCommand(keybindings, "diff.toggle"),
|
||||
[keybindings],
|
||||
);
|
||||
const onToggleDiff = useCallback(() => {
|
||||
void navigate({
|
||||
to: "/$threadId",
|
||||
params: { threadId },
|
||||
replace: true,
|
||||
search: (previous) => {
|
||||
const rest = stripDiffSearchParams(previous);
|
||||
return diffOpen ? rest : { ...rest, diff: "1" };
|
||||
},
|
||||
});
|
||||
}, [diffOpen, navigate, threadId]);
|
||||
|
||||
const envLocked = Boolean(
|
||||
activeThread &&
|
||||
@@ -1147,6 +1163,13 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "diff.toggle") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
onToggleDiff();
|
||||
return;
|
||||
}
|
||||
|
||||
const scriptId = projectScriptIdFromCommand(command);
|
||||
if (!scriptId || !activeProject) return;
|
||||
const script = activeProject.scripts.find((entry) => entry.id === scriptId);
|
||||
@@ -1168,6 +1191,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
runProjectScript,
|
||||
splitTerminal,
|
||||
keybindings,
|
||||
onToggleDiff,
|
||||
toggleTerminalVisibility,
|
||||
]);
|
||||
|
||||
@@ -1612,16 +1636,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const onExpandTimelineImage = useCallback((image: ExpandedImagePreview) => {
|
||||
setExpandedImage(image);
|
||||
}, []);
|
||||
const onToggleDiff = useCallback(() => {
|
||||
void navigate({
|
||||
to: "/$threadId",
|
||||
params: { threadId },
|
||||
search: (previous) => {
|
||||
const rest = stripDiffSearchParams(previous);
|
||||
return diffOpen ? rest : { ...rest, diff: "1" };
|
||||
},
|
||||
});
|
||||
}, [diffOpen, navigate, threadId]);
|
||||
const onOpenTurnDiff = useCallback(
|
||||
(turnId: TurnId, filePath?: string) => {
|
||||
void navigate({
|
||||
@@ -1692,6 +1706,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
activeProject ? (lastInvokedScriptByProjectId[activeProject.id] ?? null) : null
|
||||
}
|
||||
keybindings={keybindings}
|
||||
diffToggleShortcutLabel={diffPanelShortcutLabel}
|
||||
gitCwd={gitCwd}
|
||||
diffOpen={diffOpen}
|
||||
onRunProjectScript={(script) => {
|
||||
@@ -2043,6 +2058,7 @@ interface ChatHeaderProps {
|
||||
activeProjectScripts: ProjectScript[] | undefined;
|
||||
preferredScriptId: string | null;
|
||||
keybindings: ResolvedKeybindingsConfig;
|
||||
diffToggleShortcutLabel: string | null;
|
||||
gitCwd: string | null;
|
||||
diffOpen: boolean;
|
||||
onRunProjectScript: (script: ProjectScript) => void;
|
||||
@@ -2058,6 +2074,7 @@ const ChatHeader = memo(function ChatHeader({
|
||||
activeProjectScripts,
|
||||
preferredScriptId,
|
||||
keybindings,
|
||||
diffToggleShortcutLabel,
|
||||
gitCwd,
|
||||
diffOpen,
|
||||
onRunProjectScript,
|
||||
@@ -2096,16 +2113,27 @@ const ChatHeader = memo(function ChatHeader({
|
||||
<OpenInPicker keybindings={keybindings} activeThreadId={activeThreadId} />
|
||||
)}
|
||||
{activeProjectName && <GitActionsControl gitCwd={gitCwd} activeThreadId={activeThreadId} />}
|
||||
<Toggle
|
||||
className="shrink-0"
|
||||
pressed={diffOpen}
|
||||
onPressedChange={onToggleDiff}
|
||||
aria-label="Toggle diff panel"
|
||||
variant="outline"
|
||||
size="xs"
|
||||
>
|
||||
<DiffIcon className="size-3" />
|
||||
</Toggle>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Toggle
|
||||
className="shrink-0"
|
||||
pressed={diffOpen}
|
||||
onPressedChange={onToggleDiff}
|
||||
aria-label="Toggle diff panel"
|
||||
variant="outline"
|
||||
size="xs"
|
||||
>
|
||||
<DiffIcon className="size-3" />
|
||||
</Toggle>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup side="bottom">
|
||||
{diffToggleShortcutLabel
|
||||
? `Toggle diff panel (${diffToggleShortcutLabel})`
|
||||
: "Toggle diff panel"}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -24,7 +24,6 @@ const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
||||
const SIDEBAR_WIDTH = "16rem";
|
||||
const SIDEBAR_WIDTH_MOBILE = "calc(100vw - var(--spacing(3)))";
|
||||
const SIDEBAR_WIDTH_ICON = "3rem";
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
|
||||
const SIDEBAR_RESIZE_DEFAULT_MIN_WIDTH = 16 * 16;
|
||||
|
||||
type SidebarContextProps = {
|
||||
@@ -129,19 +128,6 @@ function SidebarProvider({
|
||||
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
|
||||
}, [isMobile, setOpen]);
|
||||
|
||||
// Adds a keyboard shortcut to toggle the sidebar.
|
||||
React.useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
|
||||
event.preventDefault();
|
||||
toggleSidebar();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||
}, [toggleSidebar]);
|
||||
|
||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||
// This makes it easier to style the sidebar with Tailwind classes.
|
||||
const state = open ? "expanded" : "collapsed";
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
formatShortcutLabel,
|
||||
isChatNewShortcut,
|
||||
isChatNewLocalShortcut,
|
||||
isDiffToggleShortcut,
|
||||
isOpenFavoriteEditorShortcut,
|
||||
isTerminalClearShortcut,
|
||||
isTerminalCloseShortcut,
|
||||
@@ -91,6 +92,11 @@ const DEFAULT_BINDINGS = compile([
|
||||
command: "terminal.close",
|
||||
whenAst: whenIdentifier("terminalFocus"),
|
||||
},
|
||||
{
|
||||
shortcut: modShortcut("d"),
|
||||
command: "diff.toggle",
|
||||
whenAst: whenNot(whenIdentifier("terminalFocus")),
|
||||
},
|
||||
{ shortcut: modShortcut("o", { shiftKey: true }), command: "chat.new" },
|
||||
{ shortcut: modShortcut("n", { shiftKey: true }), command: "chat.newLocal" },
|
||||
{ shortcut: modShortcut("o"), command: "editor.openFavorite" },
|
||||
@@ -230,6 +236,7 @@ describe("shortcutLabelForCommand", () => {
|
||||
|
||||
it("returns labels for non-terminal commands", () => {
|
||||
assert.strictEqual(shortcutLabelForCommand(DEFAULT_BINDINGS, "chat.new", "MacIntel"), "⇧⌘O");
|
||||
assert.strictEqual(shortcutLabelForCommand(DEFAULT_BINDINGS, "diff.toggle", "Linux"), "Ctrl+D");
|
||||
assert.strictEqual(
|
||||
shortcutLabelForCommand(DEFAULT_BINDINGS, "editor.openFavorite", "Linux"),
|
||||
"Ctrl+O",
|
||||
@@ -276,6 +283,21 @@ describe("chat/editor shortcuts", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("matches diff.toggle shortcut outside terminal focus", () => {
|
||||
assert.isTrue(
|
||||
isDiffToggleShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
|
||||
platform: "MacIntel",
|
||||
context: { terminalFocus: false },
|
||||
}),
|
||||
);
|
||||
assert.isFalse(
|
||||
isDiffToggleShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
|
||||
platform: "MacIntel",
|
||||
context: { terminalFocus: true },
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("cross-command precedence", () => {
|
||||
|
||||
@@ -198,6 +198,14 @@ export function isTerminalCloseShortcut(
|
||||
return matchesCommandShortcut(event, keybindings, "terminal.close", options);
|
||||
}
|
||||
|
||||
export function isDiffToggleShortcut(
|
||||
event: ShortcutEventLike,
|
||||
keybindings: ResolvedKeybindingsConfig,
|
||||
options?: ShortcutMatchOptions,
|
||||
): boolean {
|
||||
return matchesCommandShortcut(event, keybindings, "diff.toggle", options);
|
||||
}
|
||||
|
||||
export function isChatNewShortcut(
|
||||
event: ShortcutEventLike,
|
||||
keybindings: ResolvedKeybindingsConfig,
|
||||
|
||||
@@ -35,6 +35,12 @@ it.effect("parses keybinding rules", () =>
|
||||
});
|
||||
assert.strictEqual(parsedClose.command, "terminal.close");
|
||||
|
||||
const parsedDiffToggle = yield* decode(KeybindingRule, {
|
||||
key: "mod+d",
|
||||
command: "diff.toggle",
|
||||
});
|
||||
assert.strictEqual(parsedDiffToggle.command, "diff.toggle");
|
||||
|
||||
const parsedLocal = yield* decode(KeybindingRule, {
|
||||
key: "mod+shift+n",
|
||||
command: "chat.newLocal",
|
||||
|
||||
@@ -14,6 +14,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
|
||||
"terminal.split",
|
||||
"terminal.new",
|
||||
"terminal.close",
|
||||
"diff.toggle",
|
||||
"chat.new",
|
||||
"chat.newLocal",
|
||||
"editor.openFavorite",
|
||||
|
||||
Reference in new issue
Block a user