Skip to content
Merged
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
42 changes: 42 additions & 0 deletions src-tauri/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ pub(crate) struct AppSettings {
pub(crate) remote_backend_token: Option<String>,
#[serde(default = "default_access_mode", rename = "defaultAccessMode")]
pub(crate) default_access_mode: String,
#[serde(
default = "default_composer_model_shortcut",
rename = "composerModelShortcut"
)]
pub(crate) composer_model_shortcut: Option<String>,
#[serde(
default = "default_composer_access_shortcut",
rename = "composerAccessShortcut"
)]
pub(crate) composer_access_shortcut: Option<String>,
#[serde(
default = "default_composer_reasoning_shortcut",
rename = "composerReasoningShortcut"
)]
pub(crate) composer_reasoning_shortcut: Option<String>,
#[serde(default, rename = "lastComposerModelId")]
pub(crate) last_composer_model_id: Option<String>,
#[serde(default, rename = "lastComposerReasoningEffort")]
Expand Down Expand Up @@ -269,6 +284,18 @@ fn default_ui_scale() -> f64 {
1.0
}

fn default_composer_model_shortcut() -> Option<String> {
Some("cmd+shift+m".to_string())
}

fn default_composer_access_shortcut() -> Option<String> {
Some("cmd+shift+a".to_string())
}

fn default_composer_reasoning_shortcut() -> Option<String> {
Some("cmd+shift+r".to_string())
}

fn default_notification_sounds_enabled() -> bool {
true
}
Expand Down Expand Up @@ -309,6 +336,9 @@ impl Default for AppSettings {
remote_backend_host: default_remote_backend_host(),
remote_backend_token: None,
default_access_mode: "current".to_string(),
composer_model_shortcut: default_composer_model_shortcut(),
composer_access_shortcut: default_composer_access_shortcut(),
composer_reasoning_shortcut: default_composer_reasoning_shortcut(),
last_composer_model_id: None,
last_composer_reasoning_effort: None,
ui_scale: 1.0,
Expand Down Expand Up @@ -337,6 +367,18 @@ mod tests {
assert_eq!(settings.remote_backend_host, "127.0.0.1:4732");
assert!(settings.remote_backend_token.is_none());
assert_eq!(settings.default_access_mode, "current");
assert_eq!(
settings.composer_model_shortcut.as_deref(),
Some("cmd+shift+m")
);
assert_eq!(
settings.composer_access_shortcut.as_deref(),
Some("cmd+shift+a")
);
assert_eq!(
settings.composer_reasoning_shortcut.as_deref(),
Some("cmd+shift+r")
);
assert!(settings.last_composer_model_id.is_none());
assert!(settings.last_composer_reasoning_effort.is_none());
assert!((settings.ui_scale - 1.0).abs() < f64::EPSILON);
Expand Down
24 changes: 23 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
import { useAppSettings } from "./features/settings/hooks/useAppSettings";
import { useUpdater } from "./features/update/hooks/useUpdater";
import { useComposerImages } from "./features/composer/hooks/useComposerImages";
import { useComposerShortcuts } from "./features/composer/hooks/useComposerShortcuts";
import { useDictationModel } from "./features/dictation/hooks/useDictationModel";
import { useDictation } from "./features/dictation/hooks/useDictation";
import { useHoldToDictate } from "./features/dictation/hooks/useHoldToDictate";
Expand Down Expand Up @@ -177,7 +178,13 @@ function MainApp() {
const [composerInsert, setComposerInsert] = useState<QueuedMessage | null>(
null
);
type SettingsSection = "projects" | "display" | "dictation" | "codex" | "experimental";
type SettingsSection =
| "projects"
| "display"
| "dictation"
| "shortcuts"
| "codex"
| "experimental";
const [settingsOpen, setSettingsOpen] = useState(false);
const [settingsSection, setSettingsSection] = useState<SettingsSection | null>(
null,
Expand Down Expand Up @@ -381,6 +388,21 @@ function MainApp() {
preferredModelId: appSettings.lastComposerModelId,
preferredEffort: appSettings.lastComposerReasoningEffort,
});

useComposerShortcuts({
textareaRef: composerInputRef,
modelShortcut: appSettings.composerModelShortcut,
accessShortcut: appSettings.composerAccessShortcut,
reasoningShortcut: appSettings.composerReasoningShortcut,
models,
selectedModelId,
onSelectModel: setSelectedModelId,
accessMode,
onSelectAccessMode: setAccessMode,
reasoningOptions,
selectedEffort,
onSelectEffort: setSelectedEffort,
});
const {
collaborationModes,
selectedCollaborationMode,
Expand Down
100 changes: 100 additions & 0 deletions src/features/composer/hooks/useComposerShortcuts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { useEffect } from "react";
import type { AccessMode } from "../../../types";
import { matchesShortcut } from "../../../utils/shortcuts";

type ModelOption = { id: string; displayName: string; model: string };

type UseComposerShortcutsOptions = {
textareaRef: React.RefObject<HTMLTextAreaElement | null>;
modelShortcut: string | null;
accessShortcut: string | null;
reasoningShortcut: string | null;
models: ModelOption[];
selectedModelId: string | null;
onSelectModel: (id: string) => void;
accessMode: AccessMode;
onSelectAccessMode: (mode: AccessMode) => void;
reasoningOptions: string[];
selectedEffort: string | null;
onSelectEffort: (effort: string) => void;
};

const ACCESS_ORDER: AccessMode[] = ["read-only", "current", "full-access"];

export function useComposerShortcuts({
textareaRef,
modelShortcut,
accessShortcut,
reasoningShortcut,
models,
selectedModelId,
onSelectModel,
accessMode,
onSelectAccessMode,
reasoningOptions,
selectedEffort,
onSelectEffort,
}: UseComposerShortcutsOptions) {
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.repeat) {
return;
}
if (document.activeElement !== textareaRef.current) {
return;
}
if (matchesShortcut(event, modelShortcut)) {
event.preventDefault();
if (models.length === 0) {
return;
}
const currentIndex = models.findIndex((model) => model.id === selectedModelId);
const nextIndex = currentIndex >= 0 ? (currentIndex + 1) % models.length : 0;
const nextModel = models[nextIndex];
if (nextModel) {
onSelectModel(nextModel.id);
}
return;
}
if (matchesShortcut(event, accessShortcut)) {
event.preventDefault();
const currentIndex = ACCESS_ORDER.indexOf(accessMode);
const nextIndex = currentIndex >= 0 ? (currentIndex + 1) % ACCESS_ORDER.length : 0;
const nextAccess = ACCESS_ORDER[nextIndex];
if (nextAccess) {
onSelectAccessMode(nextAccess);
}
return;
}
if (matchesShortcut(event, reasoningShortcut)) {
event.preventDefault();
if (reasoningOptions.length === 0) {
return;
}
const currentIndex = reasoningOptions.indexOf(selectedEffort ?? "");
const nextIndex =
currentIndex >= 0 ? (currentIndex + 1) % reasoningOptions.length : 0;
const nextEffort = reasoningOptions[nextIndex];
if (nextEffort) {
onSelectEffort(nextEffort);
}
}
};

window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, [
accessMode,
accessShortcut,
modelShortcut,
models,
onSelectAccessMode,
onSelectEffort,
onSelectModel,
reasoningOptions,
reasoningShortcut,
selectedEffort,
selectedModelId,
textareaRef,
]);
}
Loading