Tighten Escape agent interrupt shortcut
This commit is contained in:
@@ -11,6 +11,7 @@ const { navigateToWorkspaceMock, routerMock, pathState } = vi.hoisted(() => ({
|
||||
routerMock: {
|
||||
back: vi.fn(),
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
},
|
||||
pathState: {
|
||||
pathname: "/h/srv/workspace/ws-2",
|
||||
@@ -56,6 +57,7 @@ vi.mock("@/hooks/use-workspace-navigation", () => ({
|
||||
}));
|
||||
|
||||
import { useKeyboardShortcuts } from "./use-keyboard-shortcuts";
|
||||
import { keyboardActionDispatcher } from "@/keyboard/keyboard-action-dispatcher";
|
||||
import { useKeyboardShortcutsStore } from "@/stores/keyboard-shortcuts-store";
|
||||
import {
|
||||
activateNavigationWorkspaceSelection,
|
||||
@@ -80,6 +82,7 @@ describe("useKeyboardShortcuts", () => {
|
||||
navigateToWorkspaceMock.mockReset();
|
||||
routerMock.back.mockReset();
|
||||
routerMock.push.mockReset();
|
||||
routerMock.replace.mockReset();
|
||||
pathState.pathname = "/h/srv/workspace/ws-2";
|
||||
syncNavigationActiveWorkspace({ current: null });
|
||||
useKeyboardShortcutsStore.setState({
|
||||
@@ -132,4 +135,57 @@ describe("useKeyboardShortcuts", () => {
|
||||
});
|
||||
expect(event.defaultPrevented).toBe(true);
|
||||
});
|
||||
|
||||
it("dispatches Escape as an agent interrupt action", async () => {
|
||||
const handleInterrupt = vi.fn(() => true);
|
||||
const unregister = keyboardActionDispatcher.registerHandler({
|
||||
handlerId: "test-agent-interrupt",
|
||||
actions: ["agent.interrupt"],
|
||||
enabled: true,
|
||||
priority: 100,
|
||||
isActive: () => true,
|
||||
handle: handleInterrupt,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
root?.render(<Probe />);
|
||||
});
|
||||
|
||||
const event = new KeyboardEvent("keydown", {
|
||||
key: "Escape",
|
||||
code: "Escape",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
|
||||
expect(handleInterrupt).toHaveBeenCalledTimes(1);
|
||||
unregister();
|
||||
});
|
||||
|
||||
it("returns from desktop settings to the retained workspace without browser history back", async () => {
|
||||
syncNavigationActiveWorkspace({
|
||||
current: {
|
||||
getCurrentRoute: () => ({ path: "/h/srv/workspace/ws-2" }),
|
||||
},
|
||||
});
|
||||
pathState.pathname = "/settings/general";
|
||||
|
||||
await act(async () => {
|
||||
root?.render(<Probe />);
|
||||
});
|
||||
|
||||
const event = new KeyboardEvent("keydown", {
|
||||
key: ",",
|
||||
code: "Comma",
|
||||
metaKey: true,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
|
||||
expect(routerMock.replace).toHaveBeenCalledWith("/h/srv/workspace/ws-2");
|
||||
expect(routerMock.back).not.toHaveBeenCalled();
|
||||
expect(event.defaultPrevented).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { getIsElectronRuntime } from "@/constants/layout";
|
||||
import { useKeyboardShortcutsStore } from "@/stores/keyboard-shortcuts-store";
|
||||
import { setCommandCenterFocusRestoreElement } from "@/utils/command-center-focus-restore";
|
||||
import {
|
||||
buildHostWorkspaceRoute,
|
||||
buildSettingsRoute,
|
||||
parseHostAgentRouteFromPathname,
|
||||
parseHostWorkspaceRouteFromPathname,
|
||||
@@ -27,7 +28,10 @@ import { isNative } from "@/constants/platform";
|
||||
import { isImeComposingKeyboardEvent } from "@/utils/keyboard-ime";
|
||||
import { getRelativeSidebarShortcutTarget } from "@/utils/sidebar-shortcuts";
|
||||
import { useActiveServerId } from "@/hooks/use-active-server-id";
|
||||
import { getNavigationActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
|
||||
import {
|
||||
getLastNavigationWorkspaceRouteSelection,
|
||||
getNavigationActiveWorkspaceSelection,
|
||||
} from "@/stores/navigation-active-workspace-store";
|
||||
|
||||
export function useKeyboardShortcuts({
|
||||
enabled,
|
||||
@@ -159,6 +163,11 @@ export function useKeyboardShortcuts({
|
||||
event: KeyboardEvent;
|
||||
}): boolean => {
|
||||
switch (input.action) {
|
||||
case "agent.interrupt":
|
||||
return keyboardActionDispatcher.dispatch({
|
||||
id: "agent.interrupt",
|
||||
scope: "global",
|
||||
});
|
||||
case "agent.new":
|
||||
return openProjectPicker();
|
||||
case "workspace.tab.new":
|
||||
@@ -234,6 +243,15 @@ export function useKeyboardShortcuts({
|
||||
return true;
|
||||
case "settings.toggle":
|
||||
if (pathname.startsWith("/settings")) {
|
||||
if (!isMobile) {
|
||||
const lastWorkspaceRoute = getLastNavigationWorkspaceRouteSelection();
|
||||
if (lastWorkspaceRoute) {
|
||||
router.replace(
|
||||
buildHostWorkspaceRoute(lastWorkspaceRoute.serverId, lastWorkspaceRoute.workspaceId),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
router.back();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user