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
8 changes: 8 additions & 0 deletions src-tauri/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ pub(crate) struct AppSettings {
rename = "composerReasoningShortcut"
)]
pub(crate) composer_reasoning_shortcut: Option<String>,
#[serde(default = "default_interrupt_shortcut", rename = "interruptShortcut")]
pub(crate) interrupt_shortcut: Option<String>,
#[serde(default = "default_new_agent_shortcut", rename = "newAgentShortcut")]
pub(crate) new_agent_shortcut: Option<String>,
#[serde(
Expand Down Expand Up @@ -446,6 +448,10 @@ fn default_composer_reasoning_shortcut() -> Option<String> {
Some("cmd+shift+r".to_string())
}

fn default_interrupt_shortcut() -> Option<String> {
Some("ctrl+c".to_string())
}

fn default_new_agent_shortcut() -> Option<String> {
Some("cmd+n".to_string())
}
Expand Down Expand Up @@ -569,6 +575,7 @@ impl Default for AppSettings {
composer_model_shortcut: default_composer_model_shortcut(),
composer_access_shortcut: default_composer_access_shortcut(),
composer_reasoning_shortcut: default_composer_reasoning_shortcut(),
interrupt_shortcut: default_interrupt_shortcut(),
new_agent_shortcut: default_new_agent_shortcut(),
new_worktree_agent_shortcut: default_new_worktree_agent_shortcut(),
new_clone_agent_shortcut: default_new_clone_agent_shortcut(),
Expand Down Expand Up @@ -635,6 +642,7 @@ mod tests {
settings.composer_reasoning_shortcut.as_deref(),
Some("cmd+shift+r")
);
assert_eq!(settings.interrupt_shortcut.as_deref(), Some("ctrl+c"));
assert_eq!(
settings.toggle_debug_panel_shortcut.as_deref(),
Some("cmd+shift+d")
Expand Down
9 changes: 9 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import { useAppMenuEvents } from "./features/app/hooks/useAppMenuEvents";
import { useWorkspaceActions } from "./features/app/hooks/useWorkspaceActions";
import { useWorkspaceCycling } from "./features/app/hooks/useWorkspaceCycling";
import { useThreadRows } from "./features/app/hooks/useThreadRows";
import { useInterruptShortcut } from "./features/app/hooks/useInterruptShortcut";
import { useCopyThread } from "./features/threads/hooks/useCopyThread";
import { useTerminalController } from "./features/terminal/hooks/useTerminalController";
import { useGitCommitController } from "./features/app/hooks/useGitCommitController";
Expand Down Expand Up @@ -1118,6 +1119,14 @@ function MainApp() {
onDropPaths: handleDropWorkspacePaths,
});

useInterruptShortcut({
isEnabled: canInterrupt,
shortcut: appSettings.interruptShortcut,
onTrigger: () => {
void interruptTurn();
},
});

const {
handleSelectPullRequest,
resetPullRequestSelection,
Expand Down
32 changes: 32 additions & 0 deletions src/features/app/hooks/useInterruptShortcut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect } from "react";
import { matchesShortcut } from "../../../utils/shortcuts";

type UseInterruptShortcutOptions = {
isEnabled: boolean;
shortcut: string | null;
onTrigger: () => void | Promise<void>;
};

export function useInterruptShortcut({
isEnabled,
shortcut,
onTrigger,
}: UseInterruptShortcutOptions) {
useEffect(() => {
if (!isEnabled || !shortcut) {
return;
}
const handleKeyDown = (event: KeyboardEvent) => {
if (event.repeat) {
return;
}
if (!matchesShortcut(event, shortcut)) {
return;
}
event.preventDefault();
void onTrigger();
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, [isEnabled, onTrigger, shortcut]);
}
1 change: 1 addition & 0 deletions src/features/settings/components/SettingsView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const baseSettings: AppSettings = {
composerModelShortcut: null,
composerAccessShortcut: null,
composerReasoningShortcut: null,
interruptShortcut: null,
newAgentShortcut: null,
newWorktreeAgentShortcut: null,
newCloneAgentShortcut: null,
Expand Down
30 changes: 30 additions & 0 deletions src/features/settings/components/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type ShortcutSettingKey =
| "composerModelShortcut"
| "composerAccessShortcut"
| "composerReasoningShortcut"
| "interruptShortcut"
| "newAgentShortcut"
| "newWorktreeAgentShortcut"
| "newCloneAgentShortcut"
Expand All @@ -149,6 +150,7 @@ type ShortcutDraftKey =
| "model"
| "access"
| "reasoning"
| "interrupt"
| "newAgent"
| "newWorktreeAgent"
| "newCloneAgent"
Expand All @@ -165,6 +167,7 @@ const shortcutDraftKeyBySetting: Record<ShortcutSettingKey, ShortcutDraftKey> =
composerModelShortcut: "model",
composerAccessShortcut: "access",
composerReasoningShortcut: "reasoning",
interruptShortcut: "interrupt",
newAgentShortcut: "newAgent",
newWorktreeAgentShortcut: "newWorktreeAgent",
newCloneAgentShortcut: "newCloneAgent",
Expand Down Expand Up @@ -230,6 +233,7 @@ export function SettingsView({
model: appSettings.composerModelShortcut ?? "",
access: appSettings.composerAccessShortcut ?? "",
reasoning: appSettings.composerReasoningShortcut ?? "",
interrupt: appSettings.interruptShortcut ?? "",
newAgent: appSettings.newAgentShortcut ?? "",
newWorktreeAgent: appSettings.newWorktreeAgentShortcut ?? "",
newCloneAgent: appSettings.newCloneAgentShortcut ?? "",
Expand Down Expand Up @@ -317,6 +321,7 @@ export function SettingsView({
model: appSettings.composerModelShortcut ?? "",
access: appSettings.composerAccessShortcut ?? "",
reasoning: appSettings.composerReasoningShortcut ?? "",
interrupt: appSettings.interruptShortcut ?? "",
newAgent: appSettings.newAgentShortcut ?? "",
newWorktreeAgent: appSettings.newWorktreeAgentShortcut ?? "",
newCloneAgent: appSettings.newCloneAgentShortcut ?? "",
Expand All @@ -333,6 +338,7 @@ export function SettingsView({
appSettings.composerAccessShortcut,
appSettings.composerModelShortcut,
appSettings.composerReasoningShortcut,
appSettings.interruptShortcut,
appSettings.newAgentShortcut,
appSettings.newWorktreeAgentShortcut,
appSettings.newCloneAgentShortcut,
Expand Down Expand Up @@ -1755,6 +1761,30 @@ export function SettingsView({
Default: {formatShortcut("cmd+shift+r")}
</div>
</div>
<div className="settings-field">
<div className="settings-field-label">Stop active run</div>
<div className="settings-field-row">
<input
className="settings-input settings-input--shortcut"
value={formatShortcut(shortcutDrafts.interrupt)}
onKeyDown={(event) =>
handleShortcutKeyDown(event, "interruptShortcut")
}
placeholder="Type shortcut"
readOnly
/>
<button
type="button"
className="ghost settings-button-compact"
onClick={() => void updateShortcut("interruptShortcut", null)}
>
Clear
</button>
</div>
<div className="settings-help">
Default: {formatShortcut("ctrl+c")}
</div>
</div>
<div className="settings-divider" />
<div className="settings-subsection-title">Panels</div>
<div className="settings-subsection-subtitle">
Expand Down
1 change: 1 addition & 0 deletions src/features/settings/hooks/useAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const defaultSettings: AppSettings = {
composerModelShortcut: "cmd+shift+m",
composerAccessShortcut: "cmd+shift+a",
composerReasoningShortcut: "cmd+shift+r",
interruptShortcut: "ctrl+c",
newAgentShortcut: "cmd+n",
newWorktreeAgentShortcut: "cmd+shift+n",
newCloneAgentShortcut: "cmd+alt+n",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export type AppSettings = {
composerModelShortcut: string | null;
composerAccessShortcut: string | null;
composerReasoningShortcut: string | null;
interruptShortcut: string | null;
newAgentShortcut: string | null;
newWorktreeAgentShortcut: string | null;
newCloneAgentShortcut: string | null;
Expand Down
Loading