From 4bbb277a86bf9c086167590f598f3e1b554ddaec Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 16:14:39 -0800 Subject: [PATCH 1/2] Properties: a drag does not measure the panel's sections on each move The Properties panel measured all of its sections before showing them whenever the document's revision changed. A Selection tool drag changes the revision on every pointer move, so each frame of the drag ran the whole panel twice. On a blank document with one rectangle, a drag frame ran 396 components where a hover frame ran 170. The revision is now kept apart from the selection, tool and isolation key. While a canvas drag or a scrubbed field is in progress, a new revision alone does not measure the sections; the edit is measured once when the drag ends. A drag frame now runs 168 components and each frame still takes one pass. --- crates/ui-egui/src/panels/properties.rs | 18 +++++-- crates/ui-egui/src/panels/properties/tests.rs | 51 +++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 3ee8c24ce5..6194f28085 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -29,6 +29,8 @@ pub struct PropertiesUi { quick_actions: Option<(u64, Vec)>, /// The [`content_key`] the sections were last shown for. content: Option, + /// The document (uid, revision) the sections were last shown for. + revision: Option<(u64, u64)>, } /// The key of [`PropertiesUi::edited_profiled`]: (document uid, revision, active Appearance row). @@ -66,7 +68,13 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let guides = super::transform::selected_guides(app); let header = heading(first.as_deref(), n_sel, editing_artboards, guides.is_some()); let content = content_key(app); - let changed = app.ui.properties_panel.content.replace(content) != Some(content); + let revision = app.session.active().map(|st| (st.uid, st.revision)); + let content_changed = app.ui.properties_panel.content.replace(content) != Some(content); + let edited = std::mem::replace(&mut app.ui.properties_panel.revision, revision) != revision; + // A drag on the canvas, or a scrubbed field, moves the revision on every pointer move without changing which + // sections show: the sections are measured again for an edit once the drag ends, not on each move. + let dragging = app.session.active().is_some_and(|st| st.interaction.is_some() || st.undo_group.is_some()); + let changed = content_changed || (edited && !dragging); let mut sections = |ui: &mut Ui, _: &mut BodyCx<'_>| { // The reference panel's labels end in a colon beside fields that keep their own width. Stack::new().fill_width().labels(LabelScheme::Form).show(ui, |ui, _| { @@ -87,19 +95,21 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let mut panel = Panel::new(header).titled().strength(HeaderStrength::Quiet).labels(LabelScheme::Inspector).pad(Pad::None); panel = panel.id_salt(egui::IdSalt::new(key)); if changed { + #[cfg(test)] + SECTION_MEASURES.with(|n| n.set(n.get() + 1)); let _ = panel.measure_in(ui, Proposal::Size(ui.available_size()), &mut sections); } panel.show(ui, sections); } -/// What the sections show: the document and its revision, the selection, the tool and isolation mode. +/// What the sections show besides the document's revision: the document, the selection, the tool and isolation mode. fn content_key(app: &VectorcraftApp) -> u64 { use std::hash::{Hash, Hasher}; let mut h = std::collections::hash_map::DefaultHasher::new(); app.session.tool_id().hash(&mut h); if let Some(st) = app.session.active() { let selection = &st.selection; - (st.uid, st.revision, st.isolation, &selection.objects, selection.key, selection.target, &selection.slices).hash(&mut h); + (st.uid, st.isolation, &selection.objects, selection.key, selection.target, &selection.slices).hash(&mut h); for (id, anchors) in &selection.anchors { (id, anchors.len()).hash(&mut h); } @@ -223,6 +233,8 @@ fn quick_actions_key(app: &VectorcraftApp) -> u64 { thread_local! { /// How many times this thread has listed the Quick Actions. pub(crate) static QUICK_ACTION_LISTS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// How many times this thread has measured the panel's sections before showing them. + pub(crate) static SECTION_MEASURES: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// [`quick_actions`], listed again only when [`quick_actions_key`] changed. diff --git a/crates/ui-egui/src/panels/properties/tests.rs b/crates/ui-egui/src/panels/properties/tests.rs index 97c9f1e9bb..c46bcbf6e4 100644 --- a/crates/ui-egui/src/panels/properties/tests.rs +++ b/crates/ui-egui/src/panels/properties/tests.rs @@ -190,6 +190,57 @@ fn a_selection_change_draws_the_window_in_one_pass() { } } +/// Dragging the selected object with the Selection tool, with the Properties panel docked, does not measure the +/// panel's sections on each pointer move, and each frame of the drag takes one pass. The release measures them once +/// for the moved object, and so does an edit made without a drag. +#[test] +fn a_drag_does_not_measure_the_sections_on_each_move() { + let measures = || SECTION_MEASURES.with(std::cell::Cell::get); + let mut app = new_app(); + let a = rect(&mut app, 100.0, 100.0, 80.0, 80.0); + app.run("select.set", json!({"ids": [a]})).unwrap(); + app.run("window.panel", json!({"panel": "properties"})).unwrap(); + app.select_tool("selection"); + let ctx = crate::testing::ui_context(); + let mut time = 0.0; + // One frame with `events` → (the passes it took, the section measures it made). + let mut frame = |app: &mut VectorcraftApp, events: Vec| { + time += 1.0 / 60.0; + let raw = egui::RawInput { + time: Some(time), + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 1000.0))), + focused: true, + events, + ..Default::default() + }; + let (pass, measured) = (ctx.cumulative_pass_nr(), measures()); + let _ = crate::testing::app_frame(app, &ctx, raw); + (ctx.cumulative_pass_nr() - pass, measures() - measured) + }; + for _ in 0..4 { + frame(&mut app, vec![]); + } + let x = |app: &VectorcraftApp| { + let st = app.session.active().unwrap(); + st.selection.objects.first().and_then(|id| st.doc.node(*id)).and_then(|n| n.geometric_bounds()).unwrap().x0 + }; + let start_x = x(&app); + let start = app.canvas_view().unwrap().to_screen(craft::behavior::kurbo::Point::new(140.0, 140.0)); + let button = |pos, pressed| Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Modifiers::NONE }; + frame(&mut app, vec![Event::PointerMoved(start)]); + assert_eq!(frame(&mut app, vec![button(start, true)]), (1, 0), "the press"); + let mut at = start; + for step in 1..=6 { + at = start + egui::vec2(8.0 * step as f32, 5.0 * step as f32); + assert_eq!(frame(&mut app, vec![Event::PointerMoved(at)]), (1, 0), "move {step} of the drag"); + } + assert_eq!(frame(&mut app, vec![button(at, false)]), (1, 1), "the release measures the moved object's sections once"); + assert!(x(&app) > start_x, "the drag moved the object"); + assert_eq!(frame(&mut app, vec![]).1, 0, "a settled frame"); + app.run("object.move", json!({"dx": 5, "dy": 0})).unwrap(); + assert_eq!(frame(&mut app, vec![]).1, 1, "an edit without a drag measures the sections"); +} + /// Start Global Edit in Quick Actions starts it on the one selected path, the button then reads /// Stop Global Edit, and Escape stops it. Selected type has no Start Global Edit button. #[test] From 5b2b29c73f74b195dc36bd9af044723e5e5f4c71 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 17:28:06 -0800 Subject: [PATCH 2/2] Properties: an edit made during a drag is measured when the drag ends A scrubbed field or a canvas drag moves the revision while the sections are not measured. When the release itself left the revision unchanged, the panel skipped the measurement and kept the sizes from before the drag. The edit now stays pending until a frame runs without a drag or an open undo group. --- crates/ui-egui/src/panels/properties.rs | 9 ++++- crates/ui-egui/src/panels/properties/tests.rs | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 6194f28085..06d19cd822 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -31,6 +31,8 @@ pub struct PropertiesUi { content: Option, /// The document (uid, revision) the sections were last shown for. revision: Option<(u64, u64)>, + /// An edit made during a drag whose sections are not measured yet. + measure_pending: bool, } /// The key of [`PropertiesUi::edited_profiled`]: (document uid, revision, active Appearance row). @@ -72,9 +74,12 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let content_changed = app.ui.properties_panel.content.replace(content) != Some(content); let edited = std::mem::replace(&mut app.ui.properties_panel.revision, revision) != revision; // A drag on the canvas, or a scrubbed field, moves the revision on every pointer move without changing which - // sections show: the sections are measured again for an edit once the drag ends, not on each move. + // sections show: the sections are measured again for an edit once the drag ends, not on each move. The edit stays + // pending until then, also when the release itself does not move the revision. let dragging = app.session.active().is_some_and(|st| st.interaction.is_some() || st.undo_group.is_some()); - let changed = content_changed || (edited && !dragging); + let pending = app.ui.properties_panel.measure_pending || edited; + let changed = content_changed || (pending && !dragging); + app.ui.properties_panel.measure_pending = pending && !changed; let mut sections = |ui: &mut Ui, _: &mut BodyCx<'_>| { // The reference panel's labels end in a colon beside fields that keep their own width. Stack::new().fill_width().labels(LabelScheme::Form).show(ui, |ui, _| { diff --git a/crates/ui-egui/src/panels/properties/tests.rs b/crates/ui-egui/src/panels/properties/tests.rs index c46bcbf6e4..dea62a6dfa 100644 --- a/crates/ui-egui/src/panels/properties/tests.rs +++ b/crates/ui-egui/src/panels/properties/tests.rs @@ -241,6 +241,43 @@ fn a_drag_does_not_measure_the_sections_on_each_move() { assert_eq!(frame(&mut app, vec![]).1, 1, "an edit without a drag measures the sections"); } +/// An edit made while an undo group is open, as a scrubbed field's drag makes, is measured once the group ends, also +/// when ending it does not move the document's revision. +#[test] +fn an_edit_during_a_drag_is_measured_when_the_drag_ends_without_a_new_revision() { + let measures = || SECTION_MEASURES.with(std::cell::Cell::get); + let mut app = new_app(); + let a = rect(&mut app, 100.0, 100.0, 80.0, 80.0); + app.run("select.set", json!({"ids": [a]})).unwrap(); + app.run("window.panel", json!({"panel": "properties"})).unwrap(); + let ctx = crate::testing::ui_context(); + let mut time = 0.0; + let mut frame = |app: &mut VectorcraftApp| { + time += 1.0 / 60.0; + let raw = egui::RawInput { + time: Some(time), + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 1000.0))), + focused: true, + ..Default::default() + }; + let measured = measures(); + let _ = crate::testing::app_frame(app, &ctx, raw); + measures() - measured + }; + for _ in 0..4 { + frame(&mut app); + } + app.run("edit.undoGroup.begin", json!({})).unwrap(); + assert_eq!(frame(&mut app), 0, "opening the group"); + app.run("object.move", json!({"dx": 5, "dy": 0})).unwrap(); + assert_eq!(frame(&mut app), 0, "an edit inside the group"); + let revision = app.session.active().unwrap().revision; + app.run("edit.undoGroup.end", json!({})).unwrap(); + assert_eq!(app.session.active().unwrap().revision, revision, "ending the group keeps the revision"); + assert_eq!(frame(&mut app), 1, "the end of the group measures the edit"); + assert_eq!(frame(&mut app), 0, "a settled frame"); +} + /// Start Global Edit in Quick Actions starts it on the one selected path, the button then reads /// Stop Global Edit, and Escape stops it. Selected type has no Start Global Edit button. #[test]