SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
View: hold a shortcut to drag and zoom (#11701) (#11706)
PaddleStroke22f8da2689dd
diff --git a/assets/locales/pending/drag-to-zoom.json b/assets/locales/pending/drag-to-zoom.jsonnew file mode 100644index 0000000000..de39fa37c8--- /dev/null+++ b/assets/locales/pending/drag-to-zoom.json@@ -0,0 +1,34 @@+{+ "ar": {+ "cmd.view_tool_zoom": "التكبير والتصغير بالسحب",+ "navbar.zoom_hold_tip": "التكبير والتصغير (أبقِ مفتاح الاختصار مضغوطًا)"+ },+ "de": {+ "cmd.view_tool_zoom": "Durch Ziehen zoomen",+ "navbar.zoom_hold_tip": "Zoomen (Tastenkürzel gedrückt halten)"+ },+ "en": {+ "cmd.view_tool_zoom": "Drag to Zoom",+ "navbar.zoom_hold_tip": "Zoom (hold shortcut)"+ },+ "he": {+ "cmd.view_tool_zoom": "שינוי הזום בגרירה",+ "navbar.zoom_hold_tip": "זום (החזקת קיצור המקשים)"+ },+ "ja": {+ "cmd.view_tool_zoom": "ドラッグでズーム",+ "navbar.zoom_hold_tip": "ズーム(ショートカットを長押し)"+ },+ "ko": {+ "cmd.view_tool_zoom": "드래그로 확대/축소",+ "navbar.zoom_hold_tip": "확대/축소 (단축키 누르고 있기)"+ },+ "vi": {+ "cmd.view_tool_zoom": "Kéo để thu phóng",+ "navbar.zoom_hold_tip": "Thu phóng (giữ phím tắt)"+ },+ "zh": {+ "cmd.view_tool_zoom": "拖动缩放",+ "navbar.zoom_hold_tip": "缩放(按住快捷键)"+ }+}diff --git a/attribution/pending/drag-to-zoom.md b/attribution/pending/drag-to-zoom.mdnew file mode 100644index 0000000000..664f4ec40e--- /dev/null+++ b/attribution/pending/drag-to-zoom.md@@ -0,0 +1 @@+| assets/locales/pending/drag-to-zoom.json | SolidCraft contributors | Original drag-to-zoom labels and translations | MIT OR Apache-2.0 |diff --git a/crates/engine/src/cmd/view_navigation.rs b/crates/engine/src/cmd/view_navigation.rsindex fd0fcaa22b..c8b6d43569 100644--- a/crates/engine/src/cmd/view_navigation.rs+++ b/crates/engine/src/cmd/view_navigation.rs@@ -7,11 +7,12 @@ use super::CommandSpec;use crate::params::{bad, num, req_vec2, req_vec3, vec3};use crate::schema::view_navigation::{CameraReply, NavigatorParams, NormalToParams, RenderBrowser, RenderFocus, RenderSelect, RibbonTabsOnly, RibbonTabsOnlyParams, StandardViewParams,- TabStep, TabStepParams,+ TabStep, TabStepParams, ZoomTool,};use crate::schema::{TypedContract, output_schema_for};use crate::{Result, Sel, Session};+const ZOOM_TOOL_CONTRACT: TypedContract<ZoomTool> = TypedContract::new();const FOCUS_CONTRACT: TypedContract<RenderFocus> = TypedContract::new();const NAVIGATOR_CONTRACT: TypedContract<NavigatorParams> = TypedContract::new();const BROWSER_CONTRACT: TypedContract<RenderBrowserRequest> = TypedContract::new();@@ -57,6 +58,10 @@ CommandSpec::new("view.home", "Home View", home).icon("home").noundo().doc_only().params("no parameters → home orientation framing the active canvas; display only"),CommandSpec::new("view.tool", "Navigation Tool", tool).icon("orbit").noundo().doc_only().params("tool: orbit|pan|zoom|none → tool; latch a camera tool, none releases it"),+CommandSpec::new("view.tool.zoom", "Drag to Zoom", crate::checked!("view.tool.zoom", zoom_tool))+ .icon("zoom").noundo().doc_only()+ .contract(&ZOOM_TOOL_CONTRACT).output(output_schema_for::<ZoomTool>)+ .params("on?: bool (omitted: toggle) → on?; latch the Zoom tool for left-button drags. A shortcut assigned in the UI zooms while held"),CommandSpec::new("view.spin", "Continuous Orbit", spin).icon("spin").noundo().doc_only().params("on?: bool (omitted: toggle) → on?; continuous orbit until the next click or key"),CommandSpec::new("view.visual_style", "Visual Style", visual_style)@@ -312,6 +317,10 @@ fn view_toggle(p: &Value, cmd: &str, key: &str) -> Result<Value> {}}+fn zoom_tool(_s: &mut Session, p: &Value) -> Result<Value> {+ view_toggle(p, "view.tool.zoom", "on")+}+fn spin(_s: &mut Session, p: &Value) -> Result<Value> {view_toggle(p, "view.spin", "on")}@@ -641,7 +650,9 @@ mod tests {assert!(s.execute(id, &json!({key:value})).is_err(), "{id}: {value}");}}- for (id, key) in [("view.spin", "on"), ("view.grid", "on"), ("view.ground_shadow", "on"), ("view.navigation_bar", "visible")] {+ for (id, key) in+ [("view.tool.zoom", "on"), ("view.spin", "on"), ("view.grid", "on"), ("view.ground_shadow", "on"), ("view.navigation_bar", "visible")]+ {assert_eq!(s.execute(id, &json!({})).unwrap(), json!({}));assert_eq!(s.execute(id, &Value::Null).unwrap(), json!({}));for on in [false, true] {@@ -651,7 +662,17 @@ mod tests {assert!(s.execute(id, &json!({key:value})).is_err(), "{id}: {value}");}}- for id in ["view.fit", "view.home", "view.tool", "view.spin", "view.visual_style", "view.grid", "view.ground_shadow", "view.navigation_bar"] {+ for id in [+ "view.fit",+ "view.home",+ "view.tool",+ "view.tool.zoom",+ "view.spin",+ "view.visual_style",+ "view.grid",+ "view.ground_shadow",+ "view.navigation_bar",+ ] {for params in [json!(true), json!(1), json!("orbit"), json!([]), json!({"unexpected":true})] {assert!(s.execute(id, ¶ms).is_err(), "{id}: {params}");}diff --git a/crates/engine/src/schema/view_navigation.rs b/crates/engine/src/schema/view_navigation.rsindex 9ac9880204..7cbf8ad3ec 100644--- a/crates/engine/src/schema/view_navigation.rs+++ b/crates/engine/src/schema/view_navigation.rs@@ -41,6 +41,15 @@ pub struct RenderBrowser {pub open: bool,}+/// Latch or release the viewport's Zoom tool. With no flag, the UI toggles it.+#[derive(Debug, Deserialize, Serialize, JsonSchema)]+#[serde(deny_unknown_fields)]+pub struct ZoomTool {+ #[serde(default, deserialize_with = "present", skip_serializing_if = "Option::is_none")]+ #[schemars(with = "bool")]+ pub on: Option<bool>,+}+/// Empty input for the read-only viewport effect query.#[derive(Debug, Deserialize, Serialize, JsonSchema)]#[serde(deny_unknown_fields)]diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex fec5fad8a2..39f2799e77 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -309,6 +309,7 @@ fn execute(app: &mut SolveApp, id: &str, params: Value) -> Result<Value, String>"view.fit"| "view.home"| "view.tool"+ | "view.tool.zoom"| "view.spin"| "view.visual_style"| "view.grid"diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rsindex f64dd74b43..87572381e7 100644--- a/crates/ui-egui/src/keymap.rs+++ b/crates/ui-egui/src/keymap.rs@@ -12,6 +12,8 @@ use solidcraft_engine::{CommandSpec, command_specs};use crate::SolveApp;use crate::ui_kit;+pub(crate) const DRAG_ZOOM: &str = "view.tool.zoom";+/// Keys the application handles before any command shortcut.pub const RESERVED: &[&str] = &["Escape",@@ -32,6 +34,7 @@ pub const RESERVED: &[&str] = &["Ctrl+C","Ctrl+X","Ctrl+V",+ "Ctrl+Shift+V",// View keys (`navigation::view_key`)."Left","Right",@@ -342,6 +345,16 @@ pub fn keys(app: &SolveApp, id: &str) -> Vec<String> {}}+/// Drag to Zoom has no default binding. Compare the keys and current modifiers using the+/// same chord names as the shortcut recorder.+pub(crate) fn drag_zoom_key(app: &SolveApp, key: egui::Key, modifiers: egui::Modifiers) -> bool {+ app.keymap.custom.get(DRAG_ZOOM).is_some_and(|keys| !keys.is_empty() && keys.contains(&key_name(key, modifiers)))+}++pub(crate) fn drag_zoom_held(app: &SolveApp, input: &egui::InputState) -> bool {+ input.focused && input.keys_down.iter().any(|key| drag_zoom_key(app, *key, input.modifiers))+}+/// Use the spec already available when walking the command list.fn keys_for_spec<'a>(app: &'a SolveApp, command: &CommandSpec) -> Vec<&'a str> {match app.keymap.custom.get(command.id) {@@ -446,6 +459,10 @@ pub fn command_for(app: &SolveApp, key: &str) -> Option<&'static str> {/// starts in the new sketch.pub fn press(app: &mut SolveApp, key: &str, repeat: bool) {if let Some(id) = command_for(app, key) {+ if id == DRAG_ZOOM {+ // The viewport reads the held chord. A key press must not latch Zoom.+ return;+ }// Pressed again while a tool of the same family is out, with Preferences › Sketch asking// for it (#2459): before its first point, the family's next mode (wrapping round); once a// point is placed, the tool keeps it. A held key's repeats change nothing.diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 1a454bc709..363a7f4657 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1305,6 +1305,14 @@ impl SolveApp {_ => None,};}+ "view.tool.zoom" => {+ let active = self.viewport.nav == Some(viewport::NavMode::Zoom);+ if v.get("on").and_then(Value::as_bool).unwrap_or(!active) {+ self.viewport.nav = Some(viewport::NavMode::Zoom);+ } else if active {+ self.viewport.nav = None;+ }+ }"view.spin" => {self.cancel_view_animation();self.viewport.spin = v.get("on").and_then(Value::as_bool).unwrap_or(!self.viewport.spin);@@ -1782,6 +1790,7 @@ impl SolveApp {id,"view.fit"| "view.home"+ | "view.tool.zoom"| "view.spin"| "view.grid"| "view.ground_shadow"diff --git a/crates/ui-egui/src/navigation.rs b/crates/ui-egui/src/navigation.rsindex d2a16fc9ff..797bbba024 100644--- a/crates/ui-egui/src/navigation.rs+++ b/crates/ui-egui/src/navigation.rs@@ -461,11 +461,11 @@ pub(crate) struct KeyHold {}/// A menu, the command box or a focused widget has the keyboard, so the view keys are not ours.-fn view_keys_blocked(app: &SolveApp, ctx: &egui::Context) -> bool {+fn view_keys_blocked(app: &SolveApp, ctx: &egui::Context, canvas: Option<egui::Id>) -> bool {egui::Popup::is_any_open(ctx)|| app.viewport.context_menu.is_some()|| app.ui.palette_open- || ctx.memory(|m| m.focused().is_some())+ || ctx.memory(|m| m.focused().is_some_and(|focused| Some(focused) != canvas))|| ctx.data(|d| d.get_temp::<egui::Id>(egui::Id::unique("sc_panel_open")).is_some())}@@ -476,7 +476,7 @@ fn view_keys_blocked(app: &SolveApp, ctx: &egui::Context) -> bool {/// menu, the command box or a focused widget has the arrows. Returns whether the key was used.pub(crate) fn view_key(app: &mut SolveApp, ctx: &egui::Context, key: egui::Key, mods: egui::Modifiers, repeat: bool) -> bool {use egui::Key;- let menu_open = view_keys_blocked(app, ctx);+ let menu_open = view_keys_blocked(app, ctx, None);let ctrl = mods.command || mods.ctrl;if mods.alt || menu_open {return false;@@ -525,7 +525,7 @@ pub(crate) fn step_key_hold(app: &mut SolveApp, ctx: &egui::Context) {}let Some(hold) = app.viewport.key_hold else { return };let (down, dt) = ctx.input(|i| (i.key_down(hold.key), f64::from(i.unstable_dt)));- if !down || view_keys_blocked(app, ctx) {+ if !down || view_keys_blocked(app, ctx, None) {app.viewport.key_hold = None;return;}@@ -568,13 +568,13 @@ pub(crate) struct CameraInput {pub secondary_down: bool,pub primary_down: bool,pub primary_pressed: bool,- /// The pointer is over this view (not a window, menu or the axis view above it).+ /// The pointer is over this view and available for canvas input.pub inside: bool,/// The axis view or navigation cube's rectangle.pub axes: Rect,pub pinch: f32,pub pan: egui::Vec2,- /// The navigation bar's fixed mode, or the preset's left-button binding.+ /// The active left-button navigation mode, including a shortcut that owns the press.pub primary_nav: Option<NavMode>,/// The navigation this frame's pointer input drives.pub mode: Option<NavMode>,@@ -724,9 +724,21 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &elet sign = crate::prefs::orbit_sign(app);orbit(app, rect, sign * f64::from(raw.shift_pan.x), sign * f64::from(raw.shift_pan.y), hover);}+ let zoom_held = (inside || app.viewport.zoom_shortcut_drag)+ && ui.input(|input| crate::keymap::drag_zoom_held(app, input))+ && !view_keys_blocked(app, ui.ctx(), Some(resp.id))+ && !app.prefs_window.open+ && !crate::dim_view::editing();+ if primary_pressed {+ app.viewport.zoom_shortcut_drag = inside && zoom_held;+ } else if !primary_down && !primary_released {+ app.viewport.zoom_shortcut_drag = false;+ }+ let zoom_drag = app.viewport.zoom_shortcut_drag;+// A left press with the preset's keys (Alias: Shift+Alt) navigates until the button is let// go (kept through the release frame, so the end of the drag doesn't select either).- if primary_pressed && inside {+ if primary_pressed && inside && !zoom_drag {let empty_space = |app: &SolveApp| {app.viewport.context_menu.is_none()&& hover.is_some_and(|p| {@@ -750,7 +762,7 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e// still selects, and Ctrl on geometry still drags it without snapping.let ctrl_orbit = (mods.ctrl || mods.command) && !mods.shift && !mods.alt && empty_space(app);app.viewport.primary_nav = preset.or(ctrl_orbit.then_some(NavMode::Orbit));- } else if !primary_down && !primary_released {+ } else if zoom_drag || (!primary_down && !primary_released) {app.viewport.primary_nav = None;}// Hold Space for a momentary pan: the hand tool of design apps. It overrides whatever the@@ -761,11 +773,18 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e&& !ui.ctx().egui_wants_keyboard_input()&& !crate::dim_view::editing()&& ui.input(|i| i.key_down(egui::Key::Space));- if space_pan {+ if zoom_held {+ ui.ctx().set_cursor_icon(egui::CursorIcon::ZoomIn);+ } else if space_pan {ui.ctx().set_cursor_icon(if primary_down { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Grab });}- // The fixed navigation mode (navigation bar), a held Space, or the preset's left-button binding.- let primary_nav = if space_pan { Some(NavMode::Pan) } else { app.viewport.nav.or(app.viewport.primary_nav) };+ let primary_nav = if zoom_drag {+ zoom_held.then_some(NavMode::Zoom)+ } else if space_pan {+ Some(NavMode::Pan)+ } else {+ app.viewport.nav.or(app.viewport.primary_nav)+ };// The right button also clicks (the context menu), so it navigates only once the press can no// longer be a click: a Magic Mouse moves the pointer a fraction of a point as it is clicked (#5517).// On that frame the drag catches up with the whole way from the press, so none of it is lost.@@ -921,6 +940,9 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &eapp.cam = Camera::default();app.fit_view();}+ // Even if the shortcut was released first, the mouse release belongs to the zoom gesture.+ let inside = inside && !zoom_drag;+ let primary_nav = if zoom_drag { Some(NavMode::Zoom) } else { primary_nav };CameraInput { hover, scroll, mods, middle, secondary_down, primary_down, primary_pressed, inside, axes, pinch, pan, primary_nav, mode }}diff --git a/crates/ui-egui/src/navigation_bar.rs b/crates/ui-egui/src/navigation_bar.rsindex d833582038..6dbddd9ae2 100644--- a/crates/ui-egui/src/navigation_bar.rs+++ b/crates/ui-egui/src/navigation_bar.rs@@ -68,7 +68,7 @@ macro_rules! slot {pub(crate) const CATALOGUE: &[Slot] = &[slot!("orbit", Tool, "orbit", Some("view.tool")),slot!("pan", Tool, "pan", Some("view.tool")),- slot!("zoom", Tool, "zoom", Some("view.tool")),+ slot!("zoom", Tool, "zoom", Some(crate::keymap::DRAG_ZOOM)),slot!("spin", Toggle, "spin", Some("view.spin")),slot!("fit", Action, "fit", Some("view.fit")),slot!("look_at", Action, "lookat", Some("view.normal_to")),diff --git a/crates/ui-egui/src/navigation_bar_view.rs b/crates/ui-egui/src/navigation_bar_view.rsindex ac1e7e9eb6..2646a8b709 100644--- a/crates/ui-egui/src/navigation_bar_view.rs+++ b/crates/ui-egui/src/navigation_bar_view.rs@@ -249,7 +249,7 @@ fn activate(app: &mut SolveApp, slot: &Slot) {_ => {if let Some(command) = slot.command {let params = match slot.kind {- Kind::Tool => json!({"tool": if selected(app, slot.id) { "none" } else { slot.id }}),+ Kind::Tool if command == "view.tool" => json!({"tool": if selected(app, slot.id) { "none" } else { slot.id }}),_ if slot.id == "ambient_occlusion" => json!({"enabled": !app.preferences.ambient_occlusion}),_ => json!({}),};@@ -260,16 +260,18 @@ fn activate(app: &mut SolveApp, slot: &Slot) {}fn tooltip(app: &SolveApp, response: egui::Response, slot: &Slot, hidden: Option<&str>, along: Rect, edge: Edge) -> egui::Response {+ let key = slot.command.and_then(|id| crate::keymap::display_for(app, id));let label = if let Some(hidden) = hidden {app.tr(hidden).to_owned()} else if slot.id == "visual_style" {crate::i18n::format("navbar.value_tip", &[("name", app.tr(slot.label)), ("value", current_style(app))])} else if slot.id == "projection" && projection_locked(app) {app.tr("nav.perspective.sketch").to_owned()+ } else if slot.id == "zoom" && key.is_some() {+ app.tr("navbar.zoom_hold_tip").to_owned()} else {app.tr(slot.label).to_owned()};- let key = slot.command.and_then(|id| crate::keymap::display_for(app, id));ui_kit::navigation_tooltip(&response, along, edge, &label, key.as_deref());response}diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex 6ebc18be1a..39e7a2ded3 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -3639,7 +3639,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {if k != Key::Escape {app.last_escape = None;}- if shown && crate::navigation::view_key(app, ctx, k, mods, repeat) {+ if shown && (crate::keymap::drag_zoom_key(app, k, mods) || crate::navigation::view_key(app, ctx, k, mods, repeat)) {continue;}if mods.command {diff --git a/crates/ui-egui/src/view_home_tests.rs b/crates/ui-egui/src/view_home_tests.rsindex 88d1c5c9d0..2807ea6bc9 100644--- a/crates/ui-egui/src/view_home_tests.rs+++ b/crates/ui-egui/src/view_home_tests.rs@@ -163,9 +163,10 @@ fn view_bar_json_commands_apply_ui_state_without_dialogs_or_undo() {assert_eq!(r["ok"], true, "{r}");assert_eq!(usize::from(h.app.ui.visual_style), index);}- for id in ["view.spin", "view.grid", "view.ground_shadow", "view.navigation_bar"] {+ for id in ["view.tool.zoom", "view.spin", "view.grid", "view.ground_shadow", "view.navigation_bar"] {let key = if id == "view.navigation_bar" { "visible" } else { "on" };let state = |app: &crate::SolveApp| match id {+ "view.tool.zoom" => app.viewport.nav == Some(NavMode::Zoom),"view.spin" => app.viewport.spin,"view.grid" => app.ui.show_grid,"view.ground_shadow" => app.ui.ground_shadow,@@ -197,6 +198,66 @@ fn view_bar_json_commands_apply_ui_state_without_dialogs_or_undo() {assert_eq!(h.app.session.undo.len(), undo);}+#[test]+fn drag_to_zoom_shortcut_stops_on_key_release_without_editing_the_sketch() {+ use egui::{Event, Key, Modifiers, PointerButton, vec2};++ let mut h = Harness::new();+ h.app.home.open = false;+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();+ h.app.run("sketch.line", json!({"points":[[0,0],[20,0]]})).unwrap();+ h.app.start("sketch.line");+ h.settle();+ let cmd = crate::keymap::DRAG_ZOOM;+ assert!(crate::keymap::keys(&h.app, cmd).is_empty());+ let bind = h.call("ui.shortcut", json!({"command":cmd,"key":"Shift+F6"}));+ assert_eq!(bind["ok"], true, "{bind}");+ // Shift+F6 is assignable, but the built-in F6 Fit handler also sees it.+ h.app.cam.distance *= 1.5;+ let before = h.app.cam;+ let before_doc = h.app.session.doc.to_json();+ let before_undo = h.app.session.undo.len();+ let at = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap()).to_screen(Vec3::ZERO).unwrap();+ let shifted = Modifiers::SHIFT;+ let plain = Modifiers::NONE;+ let key = |pressed, modifiers| Event::Key { key: Key::F6, physical_key: None, pressed, repeat: false, modifiers };+ let mouse = |pos, pressed, modifiers| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers };+ let frame = |h: &mut Harness, modifiers, events: Vec<Event>| {+ h.frame_with(std::iter::once(Event::ModifiersChanged(modifiers)).chain(events).collect());+ };++ frame(&mut h, shifted, vec![Event::PointerMoved(at), key(true, shifted)]);+ assert_eq!(h.app.cam, before, "the assigned chord does not trigger Fit");+ assert!(h.app.viewport.nav.is_none(), "the key press does not latch Zoom");+ frame(&mut h, shifted, vec![mouse(at, true, shifted)]);+ let zoomed_at = at - vec2(0.0, 48.0);+ frame(&mut h, shifted, vec![Event::PointerMoved(zoomed_at)]);+ let zoomed = h.app.cam;+ assert!(zoomed.distance < before.distance, "an upward drag zooms in");+ assert_eq!(zoomed.back(), before.back());++ let after_release = zoomed_at - vec2(0.0, 48.0);+ frame(&mut h, plain, vec![Event::PointerMoved(after_release)]);+ assert_eq!(h.app.cam, zoomed, "releasing Shift breaks the chord and stops zoom");+ frame(&mut h, plain, vec![key(false, plain), mouse(after_release, false, plain)]);+ assert!(h.app.tool.as_ref().unwrap().pts.is_empty());+ assert_eq!(h.app.session.doc.to_json(), before_doc);+ assert_eq!(h.app.session.undo.len(), before_undo);++ // A stationary zoom press remains owned by navigation when the shortcut is released first.+ frame(&mut h, shifted, vec![Event::PointerMoved(at), key(true, shifted)]);+ frame(&mut h, shifted, vec![mouse(at, true, shifted)]);+ frame(&mut h, plain, vec![key(false, plain)]);+ frame(&mut h, plain, vec![mouse(at, false, plain)]);+ assert!(h.app.tool.as_ref().unwrap().pts.is_empty(), "the release does not place a line point");+ assert_eq!(h.app.cam, zoomed);++ h.frame();+ frame(&mut h, plain, vec![mouse(at, true, plain)]);+ frame(&mut h, plain, vec![mouse(at, false, plain)]);+ assert_eq!(h.app.tool.as_ref().unwrap().pts.len(), 1, "the next ordinary click starts the line");+}+#[test]fn navigation_bar_visibility_defaults_and_round_trips() {let mut h = Harness::new();@@ -225,12 +286,14 @@ fn navigation_bar_buttons_run_registered_commands() {moved_block(&mut h);let undo = h.app.session.undo.len();let mut orbit_on = false;+ let mut zoom_on = false;h.call("ui.prefs", json!({"navigation_bar":{"slots":["orbit","pan","zoom","fit","home","visual_style","spin"]}}));for (slot, id) in [("orbit", "view.tool"),("orbit", "view.tool"),("pan", "view.tool"),- ("zoom", "view.tool"),+ ("zoom", "view.tool.zoom"),+ ("zoom", "view.tool.zoom"),("fit", "view.fit"),("home", "view.home"),("spin", "view.spin"),@@ -244,6 +307,9 @@ fn navigation_bar_buttons_run_registered_commands() {if slot == "orbit" {orbit_on = !orbit_on;assert_eq!(h.app.viewport.nav, if orbit_on { Some(crate::viewport::NavMode::Orbit) } else { None });+ } else if slot == "zoom" {+ zoom_on = !zoom_on;+ assert_eq!(h.app.viewport.nav, if zoom_on { Some(crate::viewport::NavMode::Zoom) } else { None });}}let log = h.app.session.log.len();diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex fae816cf37..750c711b4f 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -188,6 +188,8 @@ pub struct ViewportState {/// The preset's navigation for the left-button drag under way (Alias: Shift+Alt), taken/// when the button went down, so the drag neither selects nor moves sketch geometry.pub primary_nav: Option<NavMode>,+ /// A primary press that started with the Zoom shortcut owns the pointer until release.+ pub(crate) zoom_shortcut_drag: bool,/// Button-free gesture and its last owned pointer position, kept through pauses.pub(crate) modifier_nav: Option<(NavMode, Pos2)>,/// The mode the middle or right drag under way started with, kept until its button isdiff --git a/docs/book/src/guide/shortcuts.md b/docs/book/src/guide/shortcuts.mdindex 3e390c9500..44d015da84 100644--- a/docs/book/src/guide/shortcuts.md+++ b/docs/book/src/guide/shortcuts.md@@ -95,6 +95,11 @@ Mouse and touch:| Double-click a sketch curve or edge | select its chain or tangent loop || Double-click the middle button | go Home: the home view, framing everything shown (Preferences › Navigation › Middle double-click: Home, Fit or Off) |+To zoom by dragging, assign a key to **Drag to Zoom** in File › Keyboard Shortcuts.+Hold the shortcut, then drag up or down with the left mouse button in the viewport.+Releasing the shortcut stops the zoom. The Zoom button in the navigation bar also+shows the assigned shortcut.+Help › Keyboard Shortcuts in the app lists the current bindings, including any you changed.With the **Touchpad** navigation preset, hold **Shift** while moving the pointer to pan, ordiff --git a/tests/kernel-cases/EXEMPT b/tests/kernel-cases/EXEMPTindex 52933595b8..93eb55c9db 100644--- a/tests/kernel-cases/EXEMPT+++ b/tests/kernel-cases/EXEMPT@@ -355,6 +355,7 @@ view.spin the view: camera, layout, displayview.status_details the view: camera, layout, displayview.status_items the view: camera, layout, displayview.tool the view: camera, layout, display+view.tool.zoom the view: camera, layout, displayview.top the view: camera, layout, displayview.visual_style the view: camera, layout, display