fix(shortcuts): honor Cmd as the accelerator modifier on macOS (#202) (#206)

Keyboard accelerators (copy/paste/save/undo/new/open) were gated on
`Modifiers::control()`, which on macOS matches only the physical Control
key. Mac users pressing Cmd+C/V/S/Z got nothing, contrary to platform
convention and every other Mac app.

Switch the gate to `Modifiers::command()`, which iced resolves to the
Logo (Cmd) key on macOS and Ctrl on Windows/Linux. On non-mac targets
this expands to exactly `control()`, so behavior there is unchanged.

Also make the Keyboard Shortcuts reference window display the
platform-correct modifier name (Cmd vs Ctrl) so the help matches the
keys the user actually presses.

Closes #202

Co-authored-by: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Kevin GriffinandClaude Opus 4.8 authored and GitHub committed 2026-06-27 19:33:08 +03:00
1 parent ddf576765b
commit 73eabc3aaa
2 files changed
+36 -17

No files matched your search

+7 -3
View File
@@ -1449,7 +1449,11 @@ impl OpenCADStudio {
text,
..
}) => {
let ctrl = modifiers.control();
// Platform-aware accelerator modifier: Cmd on macOS,
// Ctrl on Windows/Linux. Using `command()` rather than
// `control()` makes Cmd+C/V/S/Z etc. work on Mac, per
// the platform's keyboard conventions.
let accel = modifiers.command();
let shift = modifiers.shift();
// Any key that produces a printable glyph types it,
// even when its logical key resolves to navigation
@@ -1459,7 +1463,7 @@ impl OpenCADStudio {
// those numpad digits aren't swallowed as history
// navigation. Whitespace / control text (Space,
// Enter, Tab) falls through to the named handlers.
if !ctrl && status == Status::Ignored {
if !accel && status == Status::Ignored {
if let Some(t) = text.as_deref() {
if !t.is_empty()
&& t.chars().all(|c| !c.is_control() && !c.is_whitespace())
@@ -1543,7 +1547,7 @@ impl OpenCADStudio {
keyboard::Key::Named(keyboard::key::Named::F12) => {
Some(Message::ToggleDynInput)
}
keyboard::Key::Character(c) if ctrl => match c.as_str() {
keyboard::Key::Character(c) if accel => match c.as_str() {
"n" => Some(Message::TabNew),
"o" => Some(Message::OpenFile),
"s" if !shift => Some(Message::SaveFile),
+29 -14
View File
@@ -3,6 +3,16 @@
use crate::app::Message;
use iced::widget::{column, container, row, scrollable, text, Space};
use iced::{Background, Color, Element, Fill, Theme};
use std::borrow::Cow;
/// Display name of the primary accelerator modifier on this platform.
/// Mirrors the runtime binding in `app::view`, which uses
/// `Modifiers::command()` — the Cmd key on macOS, Ctrl elsewhere — so the
/// reference window shows the key the user actually presses.
#[cfg(target_os = "macos")]
const MOD: &str = "Cmd";
#[cfg(not(target_os = "macos"))]
const MOD: &str = "Ctrl";
const TB: Color = Color {
r: 0.13,
@@ -52,9 +62,12 @@ fn hdivider<'a>() -> Element<'a, Message> {
.into()
}
fn shortcut_row<'a>(key: &'static str, action: &'static str) -> Element<'a, Message> {
fn shortcut_row<'a>(
key: impl Into<Cow<'static, str>>,
action: &'static str,
) -> Element<'a, Message> {
row![
text(key)
text(key.into())
.size(11)
.color(KEY)
.font(iced::Font::MONOSPACE)
@@ -67,8 +80,8 @@ fn shortcut_row<'a>(key: &'static str, action: &'static str) -> Element<'a, Mess
.into()
}
fn section<'a>(title: &'static str) -> Element<'a, Message> {
container(text(title).size(11).color(DIM))
fn section<'a>(title: impl Into<Cow<'static, str>>) -> Element<'a, Message> {
container(text(title.into()).size(11).color(DIM))
.padding(iced::Padding {
top: 6.0,
right: 0.0,
@@ -107,16 +120,18 @@ pub fn view_window<'a>(
shortcut_row("F10", "Toggle Polar Tracking"),
shortcut_row("F11", "Toggle Object Snap Tracking"),
shortcut_row("F12", "Toggle Dynamic Input"),
section("── Ctrl Shortcuts ──────────────────────────────────────"),
shortcut_row("Ctrl+N", "New Drawing"),
shortcut_row("Ctrl+O", "Open File"),
shortcut_row("Ctrl+S", "Save"),
shortcut_row("Ctrl+Shift+S", "Save As"),
shortcut_row("Ctrl+Z", "Undo"),
shortcut_row("Ctrl+Shift+Z / Ctrl+Y", "Redo"),
shortcut_row("Ctrl+C", "Copy to Clipboard"),
shortcut_row("Ctrl+X", "Cut to Clipboard"),
shortcut_row("Ctrl+V", "Paste from Clipboard"),
section(format!(
"── {MOD} Shortcuts ──────────────────────────────────────"
)),
shortcut_row(format!("{MOD}+N"), "New Drawing"),
shortcut_row(format!("{MOD}+O"), "Open File"),
shortcut_row(format!("{MOD}+S"), "Save"),
shortcut_row(format!("{MOD}+Shift+S"), "Save As"),
shortcut_row(format!("{MOD}+Z"), "Undo"),
shortcut_row(format!("{MOD}+Shift+Z / {MOD}+Y"), "Redo"),
shortcut_row(format!("{MOD}+C"), "Copy to Clipboard"),
shortcut_row(format!("{MOD}+X"), "Cut to Clipboard"),
shortcut_row(format!("{MOD}+V"), "Paste from Clipboard"),
section("── Other Keys ──────────────────────────────────────────"),
shortcut_row("Enter / Space", "Finalize command / Repeat last"),
shortcut_row("Escape", "Cancel active command"),