From 72a76edcf7282828f976dd541e67441e1d43edfd Mon Sep 17 00:00:00 2001 From: Homero Thompson Date: Mon, 26 Oct 2026 11:14:07 +0000 Subject: [PATCH] Shortcuts: Ctrl+Shift+S opens Save As in the workspace (#6558) (#6567) * claim: #6558 * Shortcuts: Ctrl+Shift+S opens Save As in the workspace (#6558) The Home page already opened Save As with Ctrl+Shift+S, but the design workspace matched Ctrl+S, so the chord saved over the current file instead of offering another one. The workspace now routes the chord to Save As, and the File menu shows that shortcut next to Save As, taken from the command registry. --- crates/engine/src/cmd/file.rs | 1 + crates/ui-egui/src/keymap.rs | 1 + crates/ui-egui/src/toolbar.rs | 34 +++++++++++++++++++++++++++++++- docs/book/src/guide/shortcuts.md | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index 785ecdf03..c1728044c 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -36,6 +36,7 @@ pub static COMMANDS: &[CommandSpec] = &[ .params("path? (default: current file); format?: container|json (default: json for .json, otherwise container); compression?: fast|compact (default: fast); cache?: bool (the evaluated model, so the design opens without rebuilding; default: true); preview?: bool (saved display meshes, default: false); overwrite?: bool (replace the design's file even though another program or computer changed it since it was opened or saved; without it that save is refused)"), CommandSpec::new("file.save_as", "Save As", save_as) .icon("save") + .key("Ctrl+Shift+S") .noundo() .params("path; format?: container|json (default: json for .json, otherwise container); compression?: fast|compact (default: fast); cache?: bool (the evaluated model, so the design opens without rebuilding; default: true); preview?: bool (saved display meshes, default: false); overwrite?: bool (as file.save, when `path` is the design's own file)"), CommandSpec::new("doc.recovery_list", "Recoverable Designs", recovery_list).icon("restore") diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rs index 825136b0b..2e1bb4258 100644 --- a/crates/ui-egui/src/keymap.rs +++ b/crates/ui-egui/src/keymap.rs @@ -27,6 +27,7 @@ pub const RESERVED: &[&str] = &[ "Ctrl+Z", "Ctrl+Y", "Ctrl+S", + "Ctrl+Shift+S", "Ctrl+N", "Ctrl+O", "Ctrl+Comma", diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 308a1c1b2..723dd4059 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -642,7 +642,9 @@ fn file_menu(app: &mut SolveApp, ctx: &egui::Context) { FileAction::Save.run(app); close = true; } - if item_if(ui, &format!("{}…", app.tr("ui.save_as")), "", "save", shown) { + // Save As shows the shortcut of the command it runs, from the app's own registry. + let save_as_key = crate::keymap::effective(app, "file.save_as").unwrap_or_default(); + if item_if(ui, &format!("{}…", app.tr("ui.save_as")), &save_as_key, "save", shown) { FileAction::SaveAs.run(app); close = true; } @@ -2043,6 +2045,8 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) { Key::Y => drop(app.run("edit.redo", json!({}))), // Copy, Cut and Paste (`edit_clipboard::handle`). Key::C | Key::X | Key::V if !mods.shift && !mods.alt => {} + // Ctrl+Shift+S is Save As; Ctrl+S keeps saving over the current file (#6558). + Key::S if mods.shift && !mods.alt => save_as(app), Key::S => save(app), _ => crate::keymap::press(app, &crate::keymap::key_name(k, mods), repeat), } @@ -2347,6 +2351,34 @@ mod header_report_tests { assert!(h.app.session.path.is_none(), "a download is no save: the design keeps no file"); } + /// Ctrl+Shift+S opens Save As in the design workspace (it never saves over the current file), + /// and the File menu shows that shortcut next to Save As (#6558). + #[test] + fn ctrl_shift_s_opens_save_as_in_the_workspace_and_the_file_menu_shows_the_shortcut() { + let mut h = crate::scenario::Harness::new(); + h.app.run("solid.box", json!({"length":2,"width":3,"height":4})).unwrap(); + let source = h.dir.join("source.solidcraft"); + h.app.run("file.save_as", json!({"path":source})).unwrap(); + let bytes = std::fs::read(&source).unwrap(); + h.app.session.doc_mut().name = "Copy".into(); + h.frames(3); + h.step(&json!({"key":"S","cmd":true,"shift":true})).unwrap(); + h.frames(3); + h.settle(); + assert_eq!( + h.app.session.path.as_deref(), + h.dir.join("Copy.solidcraft").to_str(), + "Ctrl+Shift+S must open Save As, not save over the current file" + ); + assert_eq!(std::fs::read(&source).unwrap(), bytes, "Save As keeps the file the design came from"); + // The File menu shows the shortcut of the command it runs. + let spec = solidcraft_engine::find_command("file.save_as").expect("file.save_as is a command"); + assert_eq!(spec.shortcut, Some("Ctrl+Shift+S"), "the File menu shows the shortcut of Save As"); + h.frames(3); + h.step(&json!({"click":{"handle":"appbar:file"}})).unwrap(); + assert!(h.widget("Save As…").is_some(), "the File menu has a Save As row"); + } + fn sizes(buttons: &[usize]) -> Vec { buttons.iter().map(|&b| PanelSize { buttons: vec![ButtonSize { width: BUTTON_MIN_WIDTH, min_width: BUTTON_MIN_WIDTH }; b] }).collect() } diff --git a/docs/book/src/guide/shortcuts.md b/docs/book/src/guide/shortcuts.md index 4b0b8fdfa..42d4f190a 100644 --- a/docs/book/src/guide/shortcuts.md +++ b/docs/book/src/guide/shortcuts.md @@ -41,6 +41,7 @@ if that happens; recording is cancelled if the app loses focus. | Ctrl+Z | Undo | Ctrl+Y | Redo | | Ctrl+N | New Design | Ctrl+O | Open | | Ctrl+S | Save | Delete | Delete the selection | +| Ctrl+Shift+S | Save As | | | | Ctrl+1 | Front View | Ctrl+2 | Back View | | Ctrl+3 | Left View | Ctrl+4 | Right View | | Ctrl+5 | Top View | Ctrl+6 | Bottom View |