SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Tabs: Ctrl+Tab shows the next design tab, Ctrl+Shift+Tab the previous one (#8565) (#8597)
phanoobba5263298509
diff --git a/assets/locales/pending/next-previous-tab.json b/assets/locales/pending/next-previous-tab.jsonnew file mode 100644index 0000000000..8b65e8fcff--- /dev/null+++ b/assets/locales/pending/next-previous-tab.json@@ -0,0 +1,11 @@+{+ "en": { "cmd.view_next_tab": "Next Tab", "cmd.view_previous_tab": "Previous Tab" },+ "ar": { "cmd.view_next_tab": "علامة التبويب التالية", "cmd.view_previous_tab": "علامة التبويب السابقة" },+ "de": { "cmd.view_next_tab": "Nächster Tab", "cmd.view_previous_tab": "Vorheriger Tab" },+ "es": { "cmd.view_next_tab": "Pestaña siguiente", "cmd.view_previous_tab": "Pestaña anterior" },+ "fr": { "cmd.view_next_tab": "Onglet suivant", "cmd.view_previous_tab": "Onglet précédent" },+ "he": { "cmd.view_next_tab": "הכרטיסייה הבאה", "cmd.view_previous_tab": "הכרטיסייה הקודמת" },+ "ja": { "cmd.view_next_tab": "次のタブ", "cmd.view_previous_tab": "前のタブ" },+ "vi": { "cmd.view_next_tab": "Thẻ tiếp theo", "cmd.view_previous_tab": "Thẻ trước" },+ "zh": { "cmd.view_next_tab": "下一个标签页", "cmd.view_previous_tab": "上一个标签页" }+}diff --git a/crates/engine/src/cmd/view_navigation.rs b/crates/engine/src/cmd/view_navigation.rsindex 90525633df..3a8fb5643a 100644--- a/crates/engine/src/cmd/view_navigation.rs+++ b/crates/engine/src/cmd/view_navigation.rs@@ -4,12 +4,13 @@ use solidcraft_render::{Camera, StandardView};use super::CommandSpec;use crate::params::{bad, num, req_vec2, req_vec3, vec3};-use crate::schema::view_navigation::{RenderBrowser, RenderFocus};+use crate::schema::view_navigation::{RenderBrowser, RenderFocus, TabStep, TabStepParams};use crate::schema::{TypedContract, output_schema_for};use crate::{Result, Sel, Session};const FOCUS_CONTRACT: TypedContract<RenderFocus> = TypedContract::new();const BROWSER_CONTRACT: TypedContract<RenderBrowserRequest> = TypedContract::new();+const TAB_STEP_CONTRACT: TypedContract<TabStepParams> = TypedContract::new();// Both existing request forms share the Browser command and its published schema.#[derive(serde::Deserialize, serde::Serialize, schemars::JsonSchema)]@@ -100,7 +101,13 @@ CommandSpec::new("view.left", "Left View", left).icon("camera").noundo().key("CtCommandSpec::new("view.right", "Right View", right).icon("camera").noundo().key("Ctrl+4").params(STANDARD_PARAMS),CommandSpec::new("view.top", "Top View", top).icon("camera").noundo().key("Ctrl+5").params(STANDARD_PARAMS),CommandSpec::new("view.bottom", "Bottom View", bottom).icon("camera").noundo().key("Ctrl+6").params(STANDARD_PARAMS),-CommandSpec::new("view.isometric", "Isometric View", isometric).icon("camera").noundo().key("Ctrl+7").params(STANDARD_PARAMS)];+CommandSpec::new("view.isometric", "Isometric View", isometric).icon("camera").noundo().key("Ctrl+7").params(STANDARD_PARAMS),+CommandSpec::new("view.next_tab", "Next Tab", crate::checked!("view.next_tab", next_tab))+ .icon("chevron_right").noundo().doc_only().key("Ctrl+Tab").contract(&TAB_STEP_CONTRACT).output(output_schema_for::<TabStep>)+ .params("no parameters → step: 1; the window shows the design tab to the right of the shown one (after the last, the first); never edits the design or opens a dialog"),+CommandSpec::new("view.previous_tab", "Previous Tab", crate::checked!("view.previous_tab", previous_tab))+ .icon("chevron_right").noundo().doc_only().key("Ctrl+Shift+Tab").contract(&TAB_STEP_CONTRACT).output(output_schema_for::<TabStep>)+ .params("no parameters → step: -1; the window shows the design tab to the left of the shown one (before the first, the last); never edits the design or opens a dialog")];const STANDARD_PARAMS: &str = "camera?: Camera (default: current session camera or home view) → camera; turns to that standard view as the view cube does, keeping target, distance and projection";@@ -895,6 +902,19 @@ fn angle_readout(_s: &mut Session, p: &Value) -> Result<Value> {serde_json::to_value(reply).map_err(|e| crate::EngineError::Other(e.to_string()))}+fn next_tab(_s: &mut Session, _p: &Value) -> Result<Value> {+ tab_step(1)+}++fn previous_tab(_s: &mut Session, _p: &Value) -> Result<Value> {+ tab_step(-1)+}++/// The engine holds one design: the window, which holds the tabs, makes the step (#8565).+fn tab_step(step: i8) -> Result<Value> {+ serde_json::to_value(TabStep { step, param_warnings: Vec::new() }).map_err(|e| crate::EngineError::Other(e.to_string()))+}+#[cfg(test)]mod ambient_occlusion_tests {use super::*;diff --git a/crates/engine/src/schema/view_navigation.rs b/crates/engine/src/schema/view_navigation.rsindex fabd0d0d45..7bdae0b296 100644--- a/crates/engine/src/schema/view_navigation.rs+++ b/crates/engine/src/schema/view_navigation.rs@@ -68,6 +68,23 @@ pub struct AngleReadoutResult {pub param_warnings: Vec<String>,}+/// `view.next_tab` and `view.previous_tab` take no parameters (#8565).+#[derive(Debug, Deserialize, JsonSchema)]+#[schemars(deny_unknown_fields)]+pub struct TabStepParams {}++/// What `view.next_tab` and `view.previous_tab` return. The window shows the design tab `step`+/// places along the strip, going round at either end; the design is not changed and nothing is+/// added to undo.+#[derive(Debug, Serialize, JsonSchema)]+pub struct TabStep {+ /// 1: the tab to the right; -1: the tab to the left.+ pub step: i8,+ /// In the warn parameter-check mode: what the call's parameters got wrong.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub param_warnings: Vec<String>,+}+#[cfg(test)]#[path = "view_navigation_tests.rs"]mod tests;diff --git a/crates/engine/src/schema/view_navigation_tests.rs b/crates/engine/src/schema/view_navigation_tests.rsindex 1bf248aa12..b8f7917ac5 100644--- a/crates/engine/src/schema/view_navigation_tests.rs+++ b/crates/engine/src/schema/view_navigation_tests.rs@@ -1,6 +1,6 @@use serde_json::{Value, json};-use super::AngleReadoutParams;+use super::{AngleReadoutParams, TabStep, TabStepParams};use crate::Session;use crate::schema::tests::{assert_keys, assert_strict_keeps_todays_errors, conforms};use crate::schema::{ParamCheck, input_schema_for, output_schema_for};@@ -33,3 +33,22 @@ fn angle_readout_replies_match_the_output_schema() {assert!(!conforms(schema, schema, &json!({"enabled": "yes"})));assert!(!conforms(schema, schema, &json!({})));}++/// #8565: the next and previous tab take nothing, say which way the window goes, and leave the+/// design and its undo as they were.+#[test]+fn next_and_previous_tab_echo_their_step_without_editing_the_design() {+ assert_keys(input_schema_for::<TabStepParams>(), &[]);+ let schema = output_schema_for::<TabStep>();+ let schema = schema.as_value();+ let mut s = Session { param_check: ParamCheck::Strict, ..Session::default() };+ s.execute("solid.box", &json!({"length": 10, "width": 10, "height": 10})).unwrap_or_else(|e| panic!("{e}"));+ let (before, undo) = (s.doc.to_json(), s.undo.len());+ for (id, step) in [("view.next_tab", 1), ("view.previous_tab", -1)] {+ let r = s.execute(id, &json!({})).unwrap_or_else(|e| panic!("{id}: {e}"));+ assert_eq!(r, json!({"step": step}), "{id}");+ assert!(conforms(schema, schema, &r), "{r} doesn't match {schema}");+ assert!(s.execute(id, &json!({"step": 2})).is_err(), "{id} takes no parameters (strict check)");+ }+ assert_eq!((s.doc.to_json(), s.undo.len()), (before, undo), "nothing in the design changes");+}diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex 20edd7ac07..0a217393b1 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -238,6 +238,8 @@ fn execute(app: &mut SolveApp, id: &str, params: Value) -> Result<Value, String>| "view.grid"| "view.ground_shadow"| "view.navigation_bar"+ | "view.next_tab"+ | "view.previous_tab"| "view.layout"| "view.navigate"| "view.ambient_occlusion"@@ -272,9 +274,9 @@ const MAX_BATCH: usize = 10_000;/// bypass.const LOADS_A_FILE: [&str; 4] = ["doc.open", "file.insert_step", "file.insert_mesh", "pointcloud.insert"];-/// Edit in Place and Finish Edit go to another design's tab: a batch's rollback, or a script's-/// later steps, would land in the wrong design.-const SWITCHES_DESIGN: [&str; 2] = ["component.edit_in_place", "component.finish_edit"];+/// Edit in Place, Finish Edit and the next or previous tab go to another design's tab: a batch's+/// rollback, or a script's later steps, would land in the wrong design.+const SWITCHES_DESIGN: [&str; 4] = ["component.edit_in_place", "component.finish_edit", "view.next_tab", "view.previous_tab"];/// `command` names the command `id`, in any of the spellings the engine takes.fn is_command(command: Option<&str>, id: &str) -> bool {diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rsindex b029dce912..bcf20108dd 100644--- a/crates/ui-egui/src/documents.rs+++ b/crates/ui-egui/src/documents.rs@@ -241,6 +241,18 @@ pub fn switch(app: &mut SolveApp, i: usize) {crate::edit_in_place::attach(app);}+/// Show the next design tab (`forward`) or the previous one, going round from the last to the+/// first (Ctrl+Tab and Ctrl+Shift+Tab, #8565). Not while tabs are being closed one after another+/// or a "save changes?" prompt is open, as for `move_tab`.+pub fn cycle(app: &mut SolveApp, forward: bool) {+ let n = app.docs.slots.len();+ if n < 2 || app.docs.closing.is_some() || app.docs.quitting.is_some() || app.docs.batch.is_some() {+ return;+ }+ let a = app.docs.active;+ switch(app, if forward { (a + 1) % n } else { (a + n - 1) % n });+}+/// The open design saved at `path`, shown or in the background.pub(crate) fn session_at<'a>(app: &'a SolveApp, path: &str) -> Option<&'a Session> {let saved_at = |s: &Session| s.path.as_deref().is_some_and(|p| same_path(p, path));@@ -1389,6 +1401,45 @@ mod tests {assert_eq!(drop_slot(260.0, 0.0, &[80.0, 200.0, 80.0], 0, 0), 2);}+ /// #8565: Ctrl+Tab shows the tab to the right and Ctrl+Shift+Tab the one to the left, going+ /// round at either end; both are commands with their keys on the Keyboard Shortcuts page, and+ /// `engine.execute` switches the same way. A "save changes?" prompt keeps the tab shown.+ #[test]+ fn ctrl_tab_and_ctrl_shift_tab_go_round_the_design_tabs() {+ let mut h = crate::scenario::Harness::new();+ h.app.home.open = false;+ for k in 1..3 {+ open_tab(&mut h.app, Session::default()).unwrap();+ for _ in 0..k {+ h.app.run("solid.sphere", json!({"diameter": 4})).unwrap();+ }+ }+ h.frames(2);+ assert_eq!((h.app.docs.active, h.app.session.doc.features.len()), (2, 2));+ let press = |h: &mut crate::scenario::Harness, shift: bool| {+ h.call("ui.key", json!({"key": "Tab", "cmd": true, "shift": shift}));+ h.frames(2);+ (h.app.docs.active, h.app.session.doc.features.len())+ };+ assert_eq!(press(&mut h, false), (0, 0), "after the last tab, the first");+ assert_eq!(press(&mut h, false), (1, 1));+ assert_eq!(press(&mut h, true), (0, 0));+ assert_eq!(press(&mut h, true), (2, 2), "before the first tab, the last");+ assert_eq!(crate::keymap::effective(&h.app, "view.next_tab").as_deref(), Some("Ctrl+Tab"));+ assert_eq!(crate::keymap::effective(&h.app, "view.previous_tab").as_deref(), Some("Ctrl+Shift+Tab"));+ assert_eq!(h.call("engine.execute", json!({"command": "view.next_tab"}))["ok"], true);+ assert_eq!(h.app.docs.active, 0);+ assert_eq!(h.call("engine.execute", json!({"command": "view.previous_tab"}))["ok"], true);+ assert_eq!(h.app.docs.active, 2);+ control(&mut h.app, &json!({"action": "close"}));+ assert_eq!(h.app.docs.closing, Some(2), "the unsaved design asks first");+ assert_eq!(press(&mut h, false).0, 2, "the asking tab stays shown");+ control(&mut h.app, &json!({"answer": "cancel"}));+ let mut one = app();+ cycle(&mut one, true);+ assert_eq!((one.docs.active, one.docs.count()), (0, 1), "a single design: nothing to go to");+ }+/// #3187: dragging a tab along the strip drops it where it is released; a drag mostly down/// the window (it moves the window) or one Escape cancelled leaves the order as it was.#[test]diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 89c658e3c8..fcfcb366af 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1032,8 +1032,9 @@ impl SolveApp {self.big_operation |= now_ms() - t0 >= recovery_ui::BIG_OPERATION_MS;let done = self.command_completed(id, r);// Render focus already applies its semantic selection after clearing object picks.+ // A tab switch brings in the other design's own Render selection.if done.is_ok()- && id != "view.render_select"+ && !matches!(id, "view.render_select" | "view.next_tab" | "view.previous_tab")&& (self.session.selection != selected_before || matches!(id, "select.set" | "select.clear" | "select.same_look")){self.render_workspace.view.selection = if self.session.selection.is_empty() {@@ -1079,6 +1080,7 @@ impl SolveApp {"view.navigation_bar" => {self.ui.show_navigation_bar = v.get("visible").and_then(Value::as_bool).unwrap_or(!self.ui.show_navigation_bar)}+ "view.next_tab" | "view.previous_tab" => documents::cycle(self, id == "view.next_tab"),_ => {}}if id == "view.render_inspector" {@@ -1384,7 +1386,17 @@ impl SolveApp {return;}// A display toggle leaves the current modelling tool and camera in place.- if matches!(id, "view.fit" | "view.home" | "view.spin" | "view.grid" | "view.ground_shadow" | "view.navigation_bar") {+ if matches!(+ id,+ "view.fit"+ | "view.home"+ | "view.spin"+ | "view.grid"+ | "view.ground_shadow"+ | "view.navigation_bar"+ | "view.next_tab"+ | "view.previous_tab"+ ) {let _ = self.run(id, json!({}));return;}