feat(ai): add panel shortcut and conversation restore

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-08 22:34:26 +08:00
1 parent b70d4153a4
commit 798733fd29
23 files changed
+165 -2

No files matched your search

@@ -21,6 +21,11 @@ describe("right sidebar panel entry points", () => {
expect(appSource).toContain("@close=\"closeRightSidebarPanel('sqlFile')\"");
});
it("toggles the AI panel through the configured global shortcut", () => {
expect(appSource).toContain("isToggleAiPanelShortcut(e, shortcuts)");
expect(appSource).toContain('toggleRightSidebarPanel("ai");');
});
it("routes welcome, history analysis, selection, and error-fix opens through the same controller", () => {
expect(appSource).toContain("@show-history=\"openRightSidebarPanel('history')\"");
expect(functionSource("fixWithAi", "sendSelectionToAi")).toContain('openRightSidebarPanel("ai")');
@@ -11,6 +11,7 @@ import {
isGoToNextPageShortcut,
isGoToPreviousPageShortcut,
isToggleZenModeShortcut,
isToggleAiPanelShortcut,
matchesModifierOnlyShortcut,
matchesShortcut,
tabSwitcherDirectionFromShortcut,
@@ -122,6 +123,13 @@ describe("keyboard shortcut matching", () => {
expect(isToggleZenModeShortcut(platformModEvent, { toggleZenMode: "" })).toBe(false);
});
it("matches the platform-specific AI panel shortcut", () => {
expect(isToggleAiPanelShortcut({ key: "i", ctrlKey: true, metaKey: true }, undefined, "MacIntel")).toBe(true);
expect(isToggleAiPanelShortcut({ key: "i", ctrlKey: true, altKey: true }, undefined, "Win32")).toBe(true);
expect(isToggleAiPanelShortcut({ key: "a", ctrlKey: true, shiftKey: true }, { toggleAiPanel: "Mod+Shift+A" }, "Win32")).toBe(true);
expect(isToggleAiPanelShortcut({ key: "i", ctrlKey: true, metaKey: true }, { toggleAiPanel: "" }, "MacIntel")).toBe(false);
});
it("matches legacy plus-key shortcuts saved with plus as a separator", () => {
expect(matchesShortcut({ key: "+", ctrlKey: true }, "Mod++", "Win32")).toBe(true);
expect(matchesShortcut({ key: "+", ctrlKey: true, shiftKey: true }, "Shift+Mod++", "Win32")).toBe(true);
@@ -9,6 +9,7 @@ import {
normalizeShortcutSettings,
selectionOccurrenceDefaultShortcut,
shortcutToCodeMirrorKey,
toggleAiPanelDefaultShortcut,
type ShortcutActionId,
} from "@/lib/editor/shortcutRegistry";
@@ -169,6 +170,17 @@ describe("shortcutRegistry editor actions", () => {
expect(findShortcutConflict("toggleZenMode", DEFAULT_SHORTCUT_SETTINGS.toggleZenMode, DEFAULT_SHORTCUT_SETTINGS)).toBeNull();
});
it("uses a platform-specific shortcut for toggling the AI panel", () => {
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "toggleAiPanel");
expect(definition).toMatchObject({ id: "toggleAiPanel", labelKey: "settings.shortcutToggleAiPanel", scope: "global" });
expect(toggleAiPanelDefaultShortcut("MacIntel")).toBe("Ctrl+Mod+I");
expect(toggleAiPanelDefaultShortcut("Win32")).toBe("Ctrl+Alt+I");
expect(normalizeShortcutSettings({ toggleAiPanel: "Ctrl+Alt+I" }, "MacIntel").toggleAiPanel).toBe("Ctrl+Mod+I");
expect(normalizeShortcutSettings({ toggleAiPanel: "Ctrl+Mod+I" }, "Win32").toggleAiPanel).toBe("Ctrl+Alt+I");
expect(findShortcutConflict("toggleAiPanel", normalizeShortcutSettings().toggleAiPanel, normalizeShortcutSettings())).toBeNull();
});
it("uses Shift+Enter for inserting a complete line below", () => {
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "insertLineBelow");
@@ -145,6 +145,10 @@ export function isSendSelectionToAiShortcut(event: ShortcutLikeEvent, shortcuts?
return matchesShortcut(event, actionShortcut("sendSelectionToAi", shortcuts));
}
export function isToggleAiPanelShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>, platform = globalThis.navigator?.platform || ""): boolean {
return matchesShortcut(event, actionShortcut("toggleAiPanel", shortcuts, platform), platform);
}
export function isConvertNamingStyleShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>, platform = globalThis.navigator?.platform || ""): boolean {
return matchesShortcut(event, actionShortcut("convertNamingStyle", shortcuts, platform), platform);
}
@@ -45,6 +45,7 @@ export type ShortcutActionId =
| "closeOtherTabs"
| "focusSearch"
| "quickOpen"
| "toggleAiPanel"
| "navigateTabHistoryBack"
| "navigateTabHistoryForward"
| "tabSwitcher"
@@ -118,12 +119,19 @@ export function tabNavigationHistoryDefaultShortcut(direction: "back" | "forward
return `${modifier}+Alt+${key}`;
}
// Match the shortcut used by VS Code to open its chat sidebar on macOS while
// keeping a reachable, non-conflicting equivalent on Windows/Linux.
export function toggleAiPanelDefaultShortcut(platform = globalThis.navigator?.platform || ""): string {
return isMacShortcutPlatform(platform) ? "Ctrl+Mod+I" : "Ctrl+Alt+I";
}
const PLATFORM_DEFAULT_SHORTCUTS: Partial<Record<ShortcutActionId, ReadonlySet<string>>> = {
closeOtherTabs: new Set(["Alt+Mod+W", "Shift+Alt+W"]),
navigateTabHistoryBack: new Set(["Ctrl+Alt+ArrowLeft", "Mod+Alt+ArrowLeft"]),
navigateTabHistoryForward: new Set(["Ctrl+Alt+ArrowRight", "Mod+Alt+ArrowRight"]),
addNextSelectionOccurrence: new Set(["Ctrl+G", "Alt+J"]),
selectAllSelectionOccurrences: new Set(["Ctrl+Mod+G", "Ctrl+Alt+Shift+J"]),
toggleAiPanel: new Set(["Ctrl+Mod+I", "Ctrl+Alt+I"]),
};
const LEGACY_CLOSE_TAB_DEFAULT = "Meta+W";
const LEGACY_COPY_CURRENT_ROW_DEFAULT = "Mod+D";
@@ -395,6 +403,12 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
scope: "global",
defaultShortcut: "Mod+P",
},
{
id: "toggleAiPanel",
labelKey: "settings.shortcutToggleAiPanel",
scope: "global",
defaultShortcut: toggleAiPanelDefaultShortcut(),
},
{
id: "navigateTabHistoryBack",
labelKey: "settings.shortcutNavigateTabHistoryBack",
@@ -614,6 +628,7 @@ function shortcutDefaultForPlatform(definition: ShortcutDefinition, platform: st
if (definition.id === "closeOtherTabs") return closeOtherTabsDefaultShortcut(platform);
if (definition.id === "navigateTabHistoryBack") return tabNavigationHistoryDefaultShortcut("back", platform);
if (definition.id === "navigateTabHistoryForward") return tabNavigationHistoryDefaultShortcut("forward", platform);
if (definition.id === "toggleAiPanel") return toggleAiPanelDefaultShortcut(platform);
return definition.defaultShortcut;
}