From 822987115cd056db3d620686803960c371c90b99 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 21:58:46 -0800 Subject: [PATCH] Transform: a Sides slider drag that ends early takes no more input until release - A drag whose rows stop being drawn still keeps its preview as one undo step, and the rest of it is ignored while the button stays down, also when the rows are drawn again before the release. An Escape in the pass whose rows are not drawn (one that closes the task bar's popover) puts the count back instead. - A drag during which another document comes to the front ends there; the rest of it changes neither document. - The Escape that cancels a drag is the slider's: the tool, isolation mode and a command bound to Escape do not take it (shortcuts::handle, through transform::sides_drag_held). --- crates/ui-egui/src/panels/transform.rs | 44 ++++++-- crates/ui-egui/src/panels/transform/tests.rs | 109 +++++++++++++++++++ crates/ui-egui/src/shortcuts.rs | 13 ++- docs/target-app-parity.md | 2 +- 4 files changed, 152 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/panels/transform.rs b/crates/ui-egui/src/panels/transform.rs index 70b9dd030d..8f95f7659b 100644 --- a/crates/ui-egui/src/panels/transform.rs +++ b/crates/ui-egui/src/panels/transform.rs @@ -648,11 +648,14 @@ pub(crate) fn polygon_rows(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node, live /// 1,000. pub(crate) const SIDES_SLIDER: std::ops::RangeInclusive = 3.0..=20.0; -/// A drag on a Sides slider in progress: the rows it is in, whether Escape canceled it (the rest -/// of it is ignored until the button is up), and the main window's pass the rail was last drawn in. +/// A drag on a Sides slider in progress: the rows it is in, the document it edits (its `uid`), +/// whether it ended early (Escape canceled it, its rows went undrawn or another document came to +/// the front; the rest of it is ignored until the button is up), and the main window's pass the +/// rail was last drawn in. #[derive(Clone, Debug, PartialEq)] struct SidesDrag { rows: String, + doc: Option, canceled: bool, pass: u64, } @@ -665,22 +668,38 @@ fn root_pass(ctx: &egui::Context) -> u64 { ctx.cumulative_pass_nr_for(egui::ViewportId::ROOT) } +/// Is a Sides slider drag in progress, or one that ended early with its button still down? The +/// shortcuts then leave Escape to the slider. +pub(crate) fn sides_drag_held(ctx: &egui::Context) -> bool { + pstate::>(ctx, SIDES_DRAG).is_some() +} + /// Keeps the count a Sides slider drag previewed as one undo step when its rail was not drawn in /// this pass (the task bar's popover or the panel closed during the drag), so no preview stays open -/// into a later pass; a drag Escape canceled only ends. The app runs this at the end of every -/// pass, after the panels. +/// into a later pass; with an Escape in this pass it puts the count back instead, and a drag that +/// already ended early only ends. While the button stays down, the +/// rest of the drag is ignored, also when its rows are drawn again. The app runs this at the end +/// of every pass, after the panels. pub(crate) fn end_stale_sides_drag(app: &mut VectorcraftApp, ctx: &egui::Context) { let Some(drag) = pstate::>(ctx, SIDES_DRAG) else { return }; if drag.pass == root_pass(ctx) { return; } - if !drag.canceled && app.session.in_interaction() { - if let Err(e) = app.session.commit_interaction() { + let front = app.session.active().map(|d| d.uid); + if !drag.canceled && drag.doc == front && app.session.in_interaction() { + // An Escape in this pass (one that closed the task bar's popover) cancels the drag, as it + // does on a drawn rail; the shortcuts leave it to the slider. + let escaped = ctx.input(|i| { + i.events.iter().any(|e| matches!(e, egui::Event::Key { key: egui::Key::Escape, pressed: true, modifiers, .. } if modifiers.is_none())) + }); + let ended = if escaped { app.session.cancel_interaction() } else { app.session.commit_interaction() }; + if let Err(e) = ended { app.ui.status = e.to_string(); } app.sync_views(); } - set_pstate(ctx, SIDES_DRAG, None::); + let down = ctx.input(|i| i.pointer.any_down()); + set_pstate(ctx, SIDES_DRAG, down.then_some(SidesDrag { canceled: true, ..drag })); } /// The Sides slider of Polygon Properties (rows `id`), `width` wide, for a polygon of `sides` @@ -699,20 +718,23 @@ fn sides_slider(app: &mut VectorcraftApp, ui: &mut Ui, id: &str, sides: u32, wid let held = pstate::>(&ctx, SIDES_DRAG).filter(|d| d.rows == id); let down = ui.input(|i| i.pointer.any_down()); let pass = root_pass(&ctx); + let doc = app.session.active().map(|d| d.uid); // `None` leaves another rows' drag as it is. let mut next = None; - if let Some(d) = held.as_ref().filter(|d| d.canceled) { - next = Some(down.then(|| SidesDrag { pass, ..d.clone() })); + // A switch to another document canceled the drag's preview there; the rest of the drag is + // ignored, as after Escape. + if let Some(d) = held.as_ref().filter(|d| d.canceled || d.doc != doc) { + next = Some(down.then(|| SidesDrag { canceled: true, pass, ..d.clone() })); } else if held.is_some() && ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) { if let Err(e) = app.session.cancel_interaction() { app.ui.status = e.to_string(); } app.sync_views(); - next = Some(down.then(|| SidesDrag { rows: id.to_string(), canceled: true, pass })); + next = Some(down.then(|| SidesDrag { rows: id.to_string(), doc, canceled: true, pass })); } else if let Some(x) = dragged { let count = (lo + f64::from(x) * (hi - lo)).round(); super::live_run(app, "Live Shape Properties", "object.setLiveShape", json!({ "sides": count as u64 }), phase); - next = Some((phase == widgets::Live::Dragging).then(|| SidesDrag { rows: id.to_string(), canceled: false, pass })); + next = Some((phase == widgets::Live::Dragging).then(|| SidesDrag { rows: id.to_string(), doc, canceled: false, pass })); } else if let Some(k) = keyed.map(f64::round).filter(|k| *k != n) { app.run("object.setLiveShape", json!({ "sides": k as u64 })).ok(); } else if let Some(d) = held { diff --git a/crates/ui-egui/src/panels/transform/tests.rs b/crates/ui-egui/src/panels/transform/tests.rs index 5ee1311e80..cd9cdd8eb1 100644 --- a/crates/ui-egui/src/panels/transform/tests.rs +++ b/crates/ui-egui/src/panels/transform/tests.rs @@ -1513,6 +1513,115 @@ fn polygon_sides_slider_drag_released_unseen_is_kept() { h.run_steps(2); assert_eq!(polygon_sides(h.state()), 15); assert_eq!(undo(h.state()), depth + 1); + // Rows drawn again while the button is still down: the rest of that drag changes nothing. + let (fifteen, ten) = (sides_rail_at(&h, 15.0), sides_rail_at(&h, 10.0)); + sides_press_and_move(&mut h, fifteen, ten); + assert_eq!(polygon_sides(h.state()), 10); + shown.set(false); + h.run_steps(1); + assert_eq!(undo(h.state()), depth + 2, "the drag ends with the pass that did not draw it"); + shown.set(true); + h.run_steps(1); + sides_press_and_move_back(&mut h, ten, fifteen); + sides_release(&mut h, fifteen); + assert!(!h.state().session.in_interaction()); + assert_eq!(polygon_sides(h.state()), 10, "the rows drawn again before the release take no more of the drag"); + assert_eq!(undo(h.state()), depth + 2); +} + +/// An Escape in the pass whose rows are not drawn (an Escape that closes the task bar's popover) +/// puts the count a Sides drag previewed back instead of keeping it, and adds no undo step. +#[test] +fn polygon_sides_slider_drag_escaped_unseen_is_canceled() { + let undo = |app: &VectorcraftApp| app.session.doc().unwrap().history.undo.len(); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 300, "height": 300})).unwrap(); + app.run("shape.polygon", json!({"cx": 150, "cy": 150, "radius": 50, "sides": 6})).unwrap(); + let depth = undo(&app); + let shown = std::rc::Rc::new(std::cell::Cell::new(true)); + let drawn = shown.clone(); + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(320.0, 900.0)).with_accessibility_check(false).build_ui_state( + move |ui, app: &mut VectorcraftApp| { + if !std::mem::replace(&mut fonts, true) { + crate::theme::install_fonts(ui.ctx()); + return; + } + if drawn.get() { + show(app, ui); + } + end_stale_sides_drag(app, ui.ctx()); + }, + app, + ); + h.run_steps(3); + let (six, fifteen) = (sides_rail_at(&h, 6.0), sides_rail_at(&h, 15.0)); + sides_press_and_move(&mut h, six, fifteen); + assert_eq!(polygon_sides(h.state()), 15); + shown.set(false); + h.key_press(egui::Key::Escape); + h.run_steps(1); + assert!(!h.state().session.in_interaction()); + assert_eq!(polygon_sides(h.state()), 6, "Escape puts the count back"); + assert_eq!(undo(h.state()), depth, "and records no undo step"); + shown.set(true); + h.run_steps(1); + sides_release(&mut h, fifteen); + assert_eq!(polygon_sides(h.state()), 6); + assert_eq!(undo(h.state()), depth); +} + +/// A Sides drag in progress when another document comes to the front (which cancels the drag's +/// preview) changes neither document with the rest of the drag. +#[test] +fn polygon_sides_slider_drag_ends_with_a_document_switch() { + let undo = |app: &VectorcraftApp| app.session.doc().unwrap().history.undo.len(); + let mut h = polygon_harness(6, show); + h.state_mut().run("file.new", json!({"width": 300, "height": 300})).unwrap(); + h.state_mut().run("shape.polygon", json!({"cx": 150, "cy": 150, "radius": 50, "sides": 6})).unwrap(); + h.run_steps(2); + let depths = (undo(h.state()), { + crate::chrome::show_document(h.state_mut(), 0); + let d = undo(h.state()); + crate::chrome::show_document(h.state_mut(), 1); + d + }); + h.run_steps(2); + let (six, fifteen, ten) = (sides_rail_at(&h, 6.0), sides_rail_at(&h, 15.0), sides_rail_at(&h, 10.0)); + sides_press_and_move(&mut h, six, fifteen); + assert_eq!(polygon_sides(h.state()), 15); + crate::chrome::show_document(h.state_mut(), 0); + h.run_steps(1); + sides_press_and_move_back(&mut h, fifteen, ten); + sides_release(&mut h, ten); + assert!(!h.state().session.in_interaction()); + assert_eq!((polygon_sides(h.state()), undo(h.state())), (6, depths.1), "the document now in front stays as it was"); + crate::chrome::show_document(h.state_mut(), 1); + assert_eq!((polygon_sides(h.state()), undo(h.state())), (6, depths.0), "the switch put the other document back"); +} + +/// An Escape that cancels a Sides drag in isolation mode ends only the drag: isolation mode stays. +#[test] +fn polygon_sides_slider_escape_keeps_isolation_mode() { + let mut h = polygon_harness(6, |app, ui| { + crate::shortcuts::handle(app, ui.ctx()); + show(app, ui); + }); + for (cmd, p) in [("object.group", json!({})), ("object.isolate", json!({})), ("select.all", json!({}))] { + h.state_mut().run(cmd, p).unwrap(); + } + h.run_steps(2); + let isolated = |app: &VectorcraftApp| app.session.active().unwrap().isolation.is_some(); + assert!(isolated(h.state())); + let (six, fifteen) = (sides_rail_at(&h, 6.0), sides_rail_at(&h, 15.0)); + sides_press_and_move(&mut h, six, fifteen); + assert_eq!(polygon_sides(h.state()), 15); + h.key_press(egui::Key::Escape); + h.run_steps(1); + assert_eq!(polygon_sides(h.state()), 6, "Escape cancels the drag"); + assert!(isolated(h.state()), "and isolation mode stays"); + sides_release(&mut h, fifteen); + assert!(isolated(h.state())); } /// Move from `from` to `to` in four frames with the primary button still down. diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 462adb62d2..f37a6e13de 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -279,7 +279,10 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) { // Escape that cancels a ruler-origin drag or floating Tools move skips the tool and later Escape actions, // and so do its repeats while it is held. let escape_ended_gesture = escape_ended_gesture(ctx); - let escape_held_by_drag = crate::canvas::dragging(ctx) || escape_ended_gesture; + // Escape during a drag on Polygon Properties' Sides slider is the slider's (it cancels the + // drag), so neither the tool nor the later Escape actions take it. + let sides_drag = crate::panels::transform::sides_drag_held(ctx); + let escape_held_by_drag = crate::canvas::dragging(ctx) || escape_ended_gesture || sides_drag; let typing = ctx.egui_wants_keyboard_input(); // Escape closes Edit Toolbar's drawer first (egui drops a drag from it on Escape already). if app.ui.tools_drawer && !typing && !escape_held_by_drag && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)) { @@ -302,7 +305,7 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) { if (text || !busy) && ctx.input(|i| runs_a_command(i, k, text)) { continue; } - if k == Key::Escape && escape_ended_gesture { + if k == Key::Escape && (escape_ended_gesture || sides_drag) { continue; } // A key the tool claims (Esc with a loaded place cursor) is only the tool's. @@ -400,8 +403,10 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) { let row_key = |chord: &craft_keymap::Chord| { rows_keys && chord.is_plain() && !chord.mods.shift && matches!(chord.key, craft_keymap::Key::Delete | craft_keymap::Key::Backspace) }; - // An Escape that ended a ruler-origin drag or floating Tools move runs no command bound to it. - let gesture_escape = |chord: &craft_keymap::Chord| escape_ended_gesture && chord.is_plain() && chord.key == craft_keymap::Key::Escape; + // An Escape that ended a ruler-origin drag or floating Tools move, or that a Sides slider drag + // takes, runs no command bound to it. + let gesture_escape = + |chord: &craft_keymap::Chord| (escape_ended_gesture || sides_drag) && chord.is_plain() && chord.key == craft_keymap::Key::Escape; // A Copy or Cut left to the labels runs neither command from the keymap. let labels_clip = |hit: &Hit| to_labels && matches!(hit.command.id.as_str(), "edit.copy" | "edit.cut"); let hits = dispatch(app, ctx, |hit| { diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 40d395e75a..efa910cebc 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1494,7 +1494,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur View › Hide Edges hides the Live Corners widgets, the bounding box and the type widget, and the selection tools then do not answer a press on them or change the cursor over them. - **Rectangle Properties corner type:** a live rectangle's Rectangle Properties (Transform panel, the Properties panel's Transform section and the Contextual Task Bar's Shape Properties) have a Corner menu with Round, Inverted Round and Chamfer. With Corner Radius linked, one menu sets the kind of every corner of each selected rectangle, also corners with no radius, and shows blank when the shown rectangle's kinds differ; unlinked, each corner's row has its own menu beside its radius field, or under it in a panel too narrow for both; the unlinked radius fields and menus leave other selected paths and polygons as they are. A pick is one undo step, and picking the kind the corners already have adds none (`object.setLiveShape {kind, rectanglesOnly, corners}`); an action that records them acts on the rectangles selected when it plays. The help page says a rectangle's corner type can be set for each corner or for all of them at once ([the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/live-shape-properties.html)); tying the number of menus to the Corner Radius link, the blank value and the undo steps are VectorCraft's own rules (`a_rectangle_shows_linked_and_unlinked_corner_types`, `the_shape_properties_popup_changes_a_rectangle_corner_type`, `the_linked_corner_menu_sets_every_selected_rectangle`, `the_unlinked_corner_menus_fit_a_narrow_panel`, `an_unlinked_corner_radius_leaves_other_selected_shapes`, `a_rectangle_corner_kind_without_a_selected_rectangle_changes_nothing`, `rectangle_kind_menu_targets_all_or_one_corner_and_skips_noop_undo`, `rectangles_only_sets_the_selected_rectangles_when_an_action_plays`, `a_radius_reaches_a_rectangle_that_already_draws_it`). - **Polygon side widget:** a selected live polygon shows a small diamond beside the middle of the right side of its bounding box, with the Selection tool and with the Rectangle, Rounded Rectangle, Ellipse, Polygon and Star tools, while the bounding box and the edges are shown. Dragging the widget sets the polygon's side count, from 3 to 11, as [the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/add-or-remove-sides-from-polygons.html) describes; typed counts in the Transform panel and `object.setLiveShape` still go from 3 to 1000. A drag down adds one side and a drag up removes one for every 12 screen pixels along the box's own vertical axis, and the pointer shows the count while measurement labels are on. A polygon of more than 11 sides keeps its count until the drag goes up, which gives it 11. The drag sends `object.setLiveShape {sides}`, so the polygon keeps its center, radius and rotation; the release adds one undo step when the count changed and none when it ends where it began, and Escape puts the count back. The widget's look and place, the drag direction, the step and the rule for more than 11 sides are VectorCraft's own (`crates/tools/src/sidewidget.rs`). - - **Polygon side slider:** Polygon Properties (Transform panel, the Properties panel's Transform section and the Contextual Task Bar's Shape Properties) have a Sides slider after the Sides field, over 3 to 20 sides. [The help page](https://helpx.adobe.com/illustrator/using/live-shapes.html) gives the slider that range and leaves larger counts, up to 1000, to the typed field, which still takes 3 to 1000. A drag previews the count through `object.setLiveShape {sides}`; its release adds one undo step when the count changed and none when it ends where it began, and Escape during the drag puts the count back and ignores the rest of it. A click on the rail or an arrow key on it sets the count in one undo step. A count above 20 shows the handle at the rail's right end, and screen readers and the field show the real count, until the rail moves. The slider's place, the rule for counts above 20 and the undo steps are VectorCraft's own (`polygon_sides_slider_is_shared_by_transform_and_properties`, `polygon_sides_above_slider_range_remain_editable`, `polygon_sides_slider_drag_is_one_undo_step`, `polygon_sides_slider_drag_released_unseen_is_kept`). + - **Polygon side slider:** Polygon Properties (Transform panel, the Properties panel's Transform section and the Contextual Task Bar's Shape Properties) have a Sides slider after the Sides field, over 3 to 20 sides. [The help page](https://helpx.adobe.com/illustrator/using/live-shapes.html) gives the slider that range and leaves larger counts, up to 1000, to the typed field, which still takes 3 to 1000. A drag previews the count through `object.setLiveShape {sides}`; its release adds one undo step when the count changed and none when it ends where it began, and Escape during the drag puts the count back and ignores the rest of it without leaving isolation mode or running a command bound to Escape. A drag whose rows stop being drawn keeps its preview as one undo step (an Escape in that pass puts the count back instead), and a drag during which another document comes to the front leaves both documents as they were; in both cases the rest of the drag is ignored until the button is released. A click on the rail or an arrow key on it sets the count in one undo step. A count above 20 shows the handle at the rail's right end, and screen readers and the field show the real count, until the rail moves. The slider's place, the rule for counts above 20 and the undo steps are VectorCraft's own (`polygon_sides_slider_is_shared_by_transform_and_properties`, `polygon_sides_above_slider_range_remain_editable`, `polygon_sides_slider_drag_is_one_undo_step`, `polygon_sides_slider_drag_released_unseen_is_kept`, `polygon_sides_slider_drag_escaped_unseen_is_canceled`, `polygon_sides_slider_drag_ends_with_a_document_switch`, `polygon_sides_slider_escape_keeps_isolation_mode`). - **Hide/Show Shape Widgets:** with the Rectangle, Rounded Rectangle, Ellipse, Polygon or Star tool, the Control bar shows a Hide Shape Widgets button, which reads Show Shape Widgets while the widgets are hidden (`view.shapeWidgets {on?}`). [The help page](https://helpx.adobe.com/illustrator/using/live-shapes.html) describes this Control panel button, offered with any live shape drawing tool, as switching the on-canvas widgets of selected shapes off and on. While they are hidden, a selected live rectangle's or polygon's corner widgets, a live ellipse's pie widgets and a live polygon's side widget are not drawn, and the Selection tool and those shape tools do not answer a press, a double-click or the cursor on their place (a shape tool draws from there). The bounding box and its handles, the center point and Direct Selection's corner widgets (View › Hide Corner Widget) stay as they are. The setting is on by default, kept with the interface state across sessions and tool switches, and adds no undo step. Its scope beyond the shape tools, its default and what it leaves shown are VectorCraft's own rules (tests `hidden_shape_widgets_leave_the_bounding_box`, `the_shape_tools_control_bar_hides_and_shows_the_shape_widgets`, `shape_widgets_command_toggles_and_takes_on`, `hidden_shape_widgets_do_not_answer_a_shape_tool` and `hidden_shape_widgets_leave_direct_selections_corners`). - **Blend spine Anchor Point tool (#2544):** on a selected blend, dragging a spine corner makes symmetric Smooth handles; the tool displays and picks existing spine handles when switched to, drags one independently or retracts it on click, and clicking a point with handles retracts both. The spine is edited live without moving its key objects. Windows native canvas checks and screenshots reviewed: symmetric and independent handles, corner/retraction, Shift constraints and perpendicular reshaping, tool switching, key preservation, Undo/Redo, save/reopen, hidden handles and overlapping Path/Blend priority (PR #2643). Behaviour reference: [public path-editing documentation](https://helpx.adobe.com/illustrator/using/adjust-path-segments.html). - **Anchor Point tool, Alt-drag on a handle:** with the Anchor Point tool chosen, dragging a direction handle with Alt (Option) held links it with the opposite handle and makes the anchor smooth, on a path and on a selected blend's spine, as [the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-paths/create-smooth-paths-with-the-smooth-tool.html) describes; a drag without Alt still moves one handle on its own (`path.setHandle` and `object.blend.spine.moveAnchor` with `link`). VectorCraft's own rules: the opposite handle keeps its length; a retracted one is pulled out to the dragged handle's length where a segment leaves the anchor on its side and stays retracted at an open end; Shift with Alt keeps the 45° steps; an Alt-click still retracts the handle; the Pen with Alt keeps moving a handle on its own. Tests: `anchor_point_alt_drag_links_*` in `crates/tools/src/draw2/anchor/tests.rs`, `a_linked_handle_makes_the_anchor_smooth` in `crates/engine/src/tests/anchor_edit_work.rs`, `a_linked_spine_handle_makes_the_point_smooth` in `crates/engine/src/tests/blendspine.rs`.