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
5 changes: 3 additions & 2 deletions src-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ pub(crate) fn build_menu<R: tauri::Runtime>(
.build(handle)?;
let check_updates_item =
MenuItemBuilder::with_id("check_for_updates", "Check for Updates...").build(handle)?;
let settings_item =
MenuItemBuilder::with_id("file_open_settings", "Settings...").build(handle)?;
let settings_item = MenuItemBuilder::with_id("file_open_settings", "Settings...")
.accelerator("CmdOrCtrl+,")
.build(handle)?;
let app_menu = Submenu::with_items(
handle,
app_name.clone(),
Expand Down
84 changes: 80 additions & 4 deletions src/features/settings/components/SettingsView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ const renderDisplaySection = (
options.onUpdateAppSettings ?? vi.fn().mockResolvedValue(undefined);
const onToggleTransparency = options.onToggleTransparency ?? vi.fn();
const props: ComponentProps<typeof SettingsView> = {
reduceTransparency: options.reduceTransparency ?? false,
onToggleTransparency,
appSettings: { ...baseSettings, ...options.appSettings },
onUpdateAppSettings,
workspaceGroups: [],
groupedWorkspaces: [],
ungroupedLabel: "Ungrouped",
Expand All @@ -102,10 +106,6 @@ const renderDisplaySection = (
onMoveWorkspaceGroup: vi.fn().mockResolvedValue(null),
onDeleteWorkspaceGroup: vi.fn().mockResolvedValue(null),
onAssignWorkspaceGroup: vi.fn().mockResolvedValue(null),
reduceTransparency: options.reduceTransparency ?? false,
onToggleTransparency,
appSettings: { ...baseSettings, ...options.appSettings },
onUpdateAppSettings,
onRunDoctor: vi.fn().mockResolvedValue(createDoctorResult()),
onUpdateWorkspaceCodexBin: vi.fn().mockResolvedValue(undefined),
scaleShortcutTitle: "Scale shortcut",
Expand Down Expand Up @@ -263,3 +263,79 @@ describe("SettingsView Display", () => {
});
});
});

describe("SettingsView Shortcuts", () => {
it("closes on Cmd+W", () => {
const onClose = vi.fn();
render(
<SettingsView
workspaceGroups={[]}
groupedWorkspaces={[]}
ungroupedLabel="Ungrouped"
onClose={onClose}
onMoveWorkspace={vi.fn()}
onDeleteWorkspace={vi.fn()}
onCreateWorkspaceGroup={vi.fn().mockResolvedValue(null)}
onRenameWorkspaceGroup={vi.fn().mockResolvedValue(null)}
onMoveWorkspaceGroup={vi.fn().mockResolvedValue(null)}
onDeleteWorkspaceGroup={vi.fn().mockResolvedValue(null)}
onAssignWorkspaceGroup={vi.fn().mockResolvedValue(null)}
reduceTransparency={false}
onToggleTransparency={vi.fn()}
appSettings={baseSettings}
onUpdateAppSettings={vi.fn().mockResolvedValue(undefined)}
onRunDoctor={vi.fn().mockResolvedValue(createDoctorResult())}
onUpdateWorkspaceCodexBin={vi.fn().mockResolvedValue(undefined)}
scaleShortcutTitle="Scale shortcut"
scaleShortcutText="Use Command +/-"
onTestNotificationSound={vi.fn()}
dictationModelStatus={null}
onDownloadDictationModel={vi.fn()}
onCancelDictationDownload={vi.fn()}
onRemoveDictationModel={vi.fn()}
/>,
);

window.dispatchEvent(
new KeyboardEvent("keydown", { key: "w", metaKey: true, bubbles: true }),
);

expect(onClose).toHaveBeenCalled();
});

it("closes on Escape", () => {
const onClose = vi.fn();
render(
<SettingsView
workspaceGroups={[]}
groupedWorkspaces={[]}
ungroupedLabel="Ungrouped"
onClose={onClose}
onMoveWorkspace={vi.fn()}
onDeleteWorkspace={vi.fn()}
onCreateWorkspaceGroup={vi.fn().mockResolvedValue(null)}
onRenameWorkspaceGroup={vi.fn().mockResolvedValue(null)}
onMoveWorkspaceGroup={vi.fn().mockResolvedValue(null)}
onDeleteWorkspaceGroup={vi.fn().mockResolvedValue(null)}
onAssignWorkspaceGroup={vi.fn().mockResolvedValue(null)}
reduceTransparency={false}
onToggleTransparency={vi.fn()}
appSettings={baseSettings}
onUpdateAppSettings={vi.fn().mockResolvedValue(undefined)}
onRunDoctor={vi.fn().mockResolvedValue(createDoctorResult())}
onUpdateWorkspaceCodexBin={vi.fn().mockResolvedValue(undefined)}
scaleShortcutTitle="Scale shortcut"
scaleShortcutText="Use Command +/-"
onTestNotificationSound={vi.fn()}
dictationModelStatus={null}
onDownloadDictationModel={vi.fn()}
onCancelDictationDownload={vi.fn()}
onRemoveDictationModel={vi.fn()}
/>,
);

window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));

expect(onClose).toHaveBeenCalled();
});
});
27 changes: 27 additions & 0 deletions src/features/settings/components/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,33 @@ export function SettingsView({
[groupedWorkspaces],
);

useEffect(() => {
const handleEscape = (event: KeyboardEvent) => {
if (event.defaultPrevented || event.key !== "Escape") {
return;
}
event.preventDefault();
onClose();
};

const handleCloseShortcut = (event: KeyboardEvent) => {
if (event.defaultPrevented) {
return;
}
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "w") {
event.preventDefault();
onClose();
}
};

window.addEventListener("keydown", handleEscape);
window.addEventListener("keydown", handleCloseShortcut);
return () => {
window.removeEventListener("keydown", handleEscape);
window.removeEventListener("keydown", handleCloseShortcut);
};
}, [onClose]);

useEffect(() => {
setCodexPathDraft(appSettings.codexBin ?? "");
}, [appSettings.codexBin]);
Expand Down
Loading