forked from 1b-agent/opencadstudio-upstream
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
ddf576765b
commit
73eabc3aaa
2 files changed
+36
-17
No files matched your search
+7
-3
@@ -1449,7 +1449,11 @@ impl OpenCADStudio {
|
|||||||
text,
|
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();
|
let shift = modifiers.shift();
|
||||||
// Any key that produces a printable glyph types it,
|
// Any key that produces a printable glyph types it,
|
||||||
// even when its logical key resolves to navigation
|
// even when its logical key resolves to navigation
|
||||||
@@ -1459,7 +1463,7 @@ impl OpenCADStudio {
|
|||||||
// those numpad digits aren't swallowed as history
|
// those numpad digits aren't swallowed as history
|
||||||
// navigation. Whitespace / control text (Space,
|
// navigation. Whitespace / control text (Space,
|
||||||
// Enter, Tab) falls through to the named handlers.
|
// 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 let Some(t) = text.as_deref() {
|
||||||
if !t.is_empty()
|
if !t.is_empty()
|
||||||
&& t.chars().all(|c| !c.is_control() && !c.is_whitespace())
|
&& t.chars().all(|c| !c.is_control() && !c.is_whitespace())
|
||||||
@@ -1543,7 +1547,7 @@ impl OpenCADStudio {
|
|||||||
keyboard::Key::Named(keyboard::key::Named::F12) => {
|
keyboard::Key::Named(keyboard::key::Named::F12) => {
|
||||||
Some(Message::ToggleDynInput)
|
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),
|
"n" => Some(Message::TabNew),
|
||||||
"o" => Some(Message::OpenFile),
|
"o" => Some(Message::OpenFile),
|
||||||
"s" if !shift => Some(Message::SaveFile),
|
"s" if !shift => Some(Message::SaveFile),
|
||||||
|
|||||||
+29
-14
@@ -3,6 +3,16 @@
|
|||||||
use crate::app::Message;
|
use crate::app::Message;
|
||||||
use iced::widget::{column, container, row, scrollable, text, Space};
|
use iced::widget::{column, container, row, scrollable, text, Space};
|
||||||
use iced::{Background, Color, Element, Fill, Theme};
|
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 {
|
const TB: Color = Color {
|
||||||
r: 0.13,
|
r: 0.13,
|
||||||
@@ -52,9 +62,12 @@ fn hdivider<'a>() -> Element<'a, Message> {
|
|||||||
.into()
|
.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![
|
row![
|
||||||
text(key)
|
text(key.into())
|
||||||
.size(11)
|
.size(11)
|
||||||
.color(KEY)
|
.color(KEY)
|
||||||
.font(iced::Font::MONOSPACE)
|
.font(iced::Font::MONOSPACE)
|
||||||
@@ -67,8 +80,8 @@ fn shortcut_row<'a>(key: &'static str, action: &'static str) -> Element<'a, Mess
|
|||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn section<'a>(title: &'static str) -> Element<'a, Message> {
|
fn section<'a>(title: impl Into<Cow<'static, str>>) -> Element<'a, Message> {
|
||||||
container(text(title).size(11).color(DIM))
|
container(text(title.into()).size(11).color(DIM))
|
||||||
.padding(iced::Padding {
|
.padding(iced::Padding {
|
||||||
top: 6.0,
|
top: 6.0,
|
||||||
right: 0.0,
|
right: 0.0,
|
||||||
@@ -107,16 +120,18 @@ pub fn view_window<'a>(
|
|||||||
shortcut_row("F10", "Toggle Polar Tracking"),
|
shortcut_row("F10", "Toggle Polar Tracking"),
|
||||||
shortcut_row("F11", "Toggle Object Snap Tracking"),
|
shortcut_row("F11", "Toggle Object Snap Tracking"),
|
||||||
shortcut_row("F12", "Toggle Dynamic Input"),
|
shortcut_row("F12", "Toggle Dynamic Input"),
|
||||||
section("── Ctrl Shortcuts ──────────────────────────────────────"),
|
section(format!(
|
||||||
shortcut_row("Ctrl+N", "New Drawing"),
|
"── {MOD} Shortcuts ──────────────────────────────────────"
|
||||||
shortcut_row("Ctrl+O", "Open File"),
|
)),
|
||||||
shortcut_row("Ctrl+S", "Save"),
|
shortcut_row(format!("{MOD}+N"), "New Drawing"),
|
||||||
shortcut_row("Ctrl+Shift+S", "Save As"),
|
shortcut_row(format!("{MOD}+O"), "Open File"),
|
||||||
shortcut_row("Ctrl+Z", "Undo"),
|
shortcut_row(format!("{MOD}+S"), "Save"),
|
||||||
shortcut_row("Ctrl+Shift+Z / Ctrl+Y", "Redo"),
|
shortcut_row(format!("{MOD}+Shift+S"), "Save As"),
|
||||||
shortcut_row("Ctrl+C", "Copy to Clipboard"),
|
shortcut_row(format!("{MOD}+Z"), "Undo"),
|
||||||
shortcut_row("Ctrl+X", "Cut to Clipboard"),
|
shortcut_row(format!("{MOD}+Shift+Z / {MOD}+Y"), "Redo"),
|
||||||
shortcut_row("Ctrl+V", "Paste from Clipboard"),
|
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 ──────────────────────────────────────────"),
|
section("── Other Keys ──────────────────────────────────────────"),
|
||||||
shortcut_row("Enter / Space", "Finalize command / Repeat last"),
|
shortcut_row("Enter / Space", "Finalize command / Repeat last"),
|
||||||
shortcut_row("Escape", "Cancel active command"),
|
shortcut_row("Escape", "Cancel active command"),
|
||||||
|
|||||||
Reference in new issue
Block a user