Skip to content
Open
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
50 changes: 32 additions & 18 deletions apps/code/src/renderer/components/GlobalEventHandlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { useSidebarStore } from "@features/sidebar/stores/sidebarStore";
import { useTasks } from "@features/tasks/hooks/useTasks";
import { useFocusWorkspace } from "@features/workspace/hooks/useFocusWorkspace";
import { useWorkspaces } from "@features/workspace/hooks/useWorkspace";
import { useShortcut } from "@hooks/useShortcut";
import { SHORTCUTS } from "@renderer/constants/keyboard-shortcuts";
import { useTRPC } from "@renderer/trpc";
import { isMac } from "@renderer/utils/platform";
import type { Task } from "@shared/types";
import { useCommandMenuStore } from "@stores/commandMenuStore";
import { useNavigationStore } from "@stores/navigationStore";
Expand Down Expand Up @@ -157,33 +159,43 @@ export function GlobalEventHandlers({
preventDefault: true,
} as const;

useHotkeys(SHORTCUTS.COMMAND_MENU, onToggleCommandMenu, {
const commandMenuKey = useShortcut("command-menu");
const newTaskKey = useShortcut("new-task");
const settingsKey = useShortcut("settings");
const goBackKey = useShortcut("go-back");
const goForwardKey = useShortcut("go-forward");
const toggleLeftSidebarKey = useShortcut("toggle-left-sidebar");
const toggleReviewPanelKey = useShortcut("toggle-review-panel");
const shortcutsSheetKey = useShortcut("shortcuts");
const inboxKey = useShortcut("inbox");
const prevTaskKey = useShortcut("prev-task");
const nextTaskKey = useShortcut("next-task");
const toggleFocusKey = useShortcut("toggle-focus");

useHotkeys(commandMenuKey, onToggleCommandMenu, {
...globalOptions,
enabled: !commandMenuOpen,
});
useHotkeys(SHORTCUTS.NEW_TASK, handleFocusTaskMode, globalOptions);
useHotkeys(SHORTCUTS.SETTINGS, handleOpenSettings, globalOptions);
useHotkeys(SHORTCUTS.GO_BACK, goBack, globalOptions);
useHotkeys(SHORTCUTS.GO_FORWARD, goForward, globalOptions);
useHotkeys(newTaskKey, handleFocusTaskMode, globalOptions);
useHotkeys(settingsKey, handleOpenSettings, globalOptions);
useHotkeys(goBackKey, goBack, globalOptions);
useHotkeys(goForwardKey, goForward, globalOptions);

const handleToggleReview = useCallback(() => {
if (!currentTaskId) return;
const mode = getReviewMode(currentTaskId);
setReviewMode(currentTaskId, mode === "closed" ? "split" : "closed");
}, [currentTaskId, getReviewMode, setReviewMode]);

useHotkeys(SHORTCUTS.TOGGLE_LEFT_SIDEBAR, toggleLeftSidebar, globalOptions);
useHotkeys(SHORTCUTS.TOGGLE_REVIEW_PANEL, handleToggleReview, globalOptions);
useHotkeys(SHORTCUTS.SHORTCUTS_SHEET, onToggleShortcutsSheet, globalOptions);
useHotkeys(SHORTCUTS.INBOX, navigateToInbox, globalOptions);
useHotkeys(SHORTCUTS.PREV_TASK, handlePrevTask, globalOptions, [
handlePrevTask,
]);
useHotkeys(SHORTCUTS.NEXT_TASK, handleNextTask, globalOptions, [
handleNextTask,
]);
useHotkeys(toggleLeftSidebarKey, toggleLeftSidebar, globalOptions);
useHotkeys(toggleReviewPanelKey, handleToggleReview, globalOptions);
useHotkeys(shortcutsSheetKey, onToggleShortcutsSheet, globalOptions);
useHotkeys(inboxKey, navigateToInbox, globalOptions);
useHotkeys(prevTaskKey, handlePrevTask, globalOptions, [handlePrevTask]);
useHotkeys(nextTaskKey, handleNextTask, globalOptions, [handleNextTask]);

useHotkeys(
SHORTCUTS.TOGGLE_FOCUS,
toggleFocusKey,
handleToggleFocus,
{
...globalOptions,
Expand All @@ -192,11 +204,13 @@ export function GlobalEventHandlers({
[handleToggleFocus],
);

// Task switching with mod+1-9
// Task switching with mod+1-9. On macOS, Ctrl+1..9 is reserved for
// SWITCH_TAB (panel tabs), so ignore plain-Ctrl there; on Windows/Linux,
// Ctrl IS mod, so the same event must trigger task switching.
useHotkeys(
SHORTCUTS.SWITCH_TASK,
(event, handler) => {
if (event.ctrlKey && !event.metaKey) return;
if (isMac && event.ctrlKey && !event.metaKey) return;

const keyPressed = handler.keys?.[0];
if (!keyPressed) return;
Expand Down
Loading