From 844c1658ca3178b7d43dc699dfef8e8ef9b158ae Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 02:54:00 -0800 Subject: [PATCH 1/3] Canvas, Gradient, Home: drop the stop-popover and Space Hand workarounds, test Home's scrolling The craft-libs pin now carries storytold/craft-libs#5131, #5056 and #5193, which fix these in the framework: - Gradient panel: the slider no longer drags a stop on the press of the double click that opens the stop's popover (#5131). The panel's color_press and color_drag fields and the early return that dropped that press's edits are removed. The test gradient_stop_popover_stays_open_when_the_double_click_drifts still passes without them. - Canvas: the tool host ends a momentary Hand whose key went up while the canvas was away (#5056). end_missed_momentary, note_momentary_keys, their calls and CanvasCache::momentary_keys are removed. Both Space Hand tests still pass without them. - Home: a Column start page whose column fits the view no longer scrolls for the margin under it (#5193). A new test shows the whole window with no recent files: at 1440 by 900 a wheel over the title leaves it in place, and at 1280 by 800, where the column is taller than the view, the page scrolls. --- crates/ui-egui/src/app.rs | 1 - crates/ui-egui/src/caches.rs | 3 -- crates/ui-egui/src/canvas/tool_adapter.rs | 44 ++--------------------- crates/ui-egui/src/panels/gradient.rs | 22 ------------ crates/ui-egui/src/tests/home.rs | 44 +++++++++++++++++++++++ 5 files changed, 47 insertions(+), 67 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 25170c9f12..13b36e3d3d 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -149,7 +149,6 @@ impl VectorcraftApp { spelling: Default::default(), text_nodes: Default::default(), momentary: None, - momentary_keys: vec![], hand: None, zoom_tool: None, selection_box: None, diff --git a/crates/ui-egui/src/caches.rs b/crates/ui-egui/src/caches.rs index d2809d5846..6dcec22bff 100644 --- a/crates/ui-egui/src/caches.rs +++ b/crates/ui-egui/src/caches.rs @@ -81,9 +81,6 @@ pub struct CanvasCache { /// The Hand, Zoom and Rotate View tools the Space key and its chords lend the canvas, between /// passes; the tool adapter takes it out for its call and puts it back. pub momentary: Option, - /// The keys down when the held momentary command started; empty while none is held or when none started it. - /// Temporary, with `tool_adapter::end_missed_momentary` (craft-libs#5056). - pub momentary_keys: Vec, pub hand: Option, /// The selected Zoom tool keeps its press and drag rectangle between canvas passes. pub zoom_tool: Option, diff --git a/crates/ui-egui/src/canvas/tool_adapter.rs b/crates/ui-egui/src/canvas/tool_adapter.rs index 58e735257e..1136fda54d 100644 --- a/crates/ui-egui/src/canvas/tool_adapter.rs +++ b/crates/ui-egui/src/canvas/tool_adapter.rs @@ -7,8 +7,8 @@ use craft::behavior::{CancelReason, CanvasView, Cursor, PointerKind as Device, P use craft::keymap::{Chord, Key}; use craft::ui::canvas::ToolPath; use craft::ui::canvas::{ - Autoscroll, CanvasTool, Momentary, MomentaryCommands, MomentaryShift, ToolAction, ToolClaims, ToolContext, ToolHost, ToolHostResponse, ToolKey, - ToolPass, ToolPointer, + Autoscroll, CanvasTool, Momentary, MomentaryShift, ToolAction, ToolClaims, ToolContext, ToolHost, ToolHostResponse, ToolKey, ToolPass, + ToolPointer, }; use serde_json::json; use vectorcraft_engine::ViewInfo; @@ -610,37 +610,6 @@ impl CanvasTool for SessionTool<'_> { } } -/// Ends the held momentary command (Space's Hand, Cmd+Space's Zoom...) once none of the keys that were down when it -/// started is down, and returns the command still held. The shortcut board drops a queued release when the canvas -/// does not run on the frame the key goes up (a dialog or another tab in front). A hold that started with no key down -/// (automation) lasts until its release. -/// -/// Temporary: craft-libs#5056 ends the hold inside the tool host. Remove this function, [`note_momentary_keys`], -/// their calls and `CanvasCache::momentary_keys` once the craft-libs pin includes that change. -fn end_missed_momentary(ctx: &egui::Context, momentary: &mut Momentary, keys: &mut Vec) -> Option { - let held = momentary.held()?; - if keys.is_empty() { - return Some(held); - } - let down = craft::ui::runtime::keys::held(ctx); - if keys.iter().any(|key| down.contains(key)) { - return Some(held); - } - momentary.fired(held, craft::ui::runtime::commands::FirePhase::Release); - keys.clear(); - None -} - -/// Notes the keys down when a momentary command starts (or changes), for [`end_missed_momentary`]; `before` is the -/// command held before the tool host's pass. -fn note_momentary_keys(ctx: &egui::Context, before: Option, momentary: &Momentary, keys: &mut Vec) { - match momentary.held() { - None => keys.clear(), - Some(held) if before != Some(held) => *keys = craft::ui::runtime::keys::held(ctx), - Some(_) => {} - } -} - /// Runs the tool host on `tool` with the app's momentary set, which the app keeps across passes. A finger, once a pen /// has been seen, only navigates (palm rejection). fn host_run(app: &mut VectorcraftApp, ui: &Ui, pass: &ToolPass, tool: &mut dyn CanvasTool) -> ToolHostResponse { @@ -648,9 +617,7 @@ fn host_run(app: &mut VectorcraftApp, ui: &Ui, pass: &ToolPass, tool: &mut dyn C let mut momentary = app.canvas.momentary.take().unwrap_or_else(|| Momentary::new(options).shift(MomentaryShift::RotateView)); momentary.set_options(options); momentary.hand_selected(app.session.tool_id() == "hand"); - let before = end_missed_momentary(ui.ctx(), &mut momentary, &mut app.canvas.momentary_keys); let response = ToolHost::new().momentary(&mut momentary).navigates(crate::touch::finger_navigates_only()).run(ui, pass, tool); - note_momentary_keys(ui.ctx(), before, &momentary, &mut app.canvas.momentary_keys); app.canvas.momentary = Some(momentary); response } @@ -783,14 +750,9 @@ fn host_run_session(tool: &mut SessionTool<'_>, ui: &Ui, pass: &ToolPass) -> Too let mut momentary = app.canvas.momentary.take().unwrap_or_else(|| Momentary::new(options).shift(MomentaryShift::RotateView)); momentary.set_options(options); momentary.hand_selected(app.session.tool_id() == "hand"); - let mut keys = std::mem::take(&mut app.canvas.momentary_keys); drop(app); - let before = end_missed_momentary(ui.ctx(), &mut momentary, &mut keys); let response = ToolHost::new().momentary(&mut momentary).navigates(crate::touch::finger_navigates_only()).run(ui, pass, tool); - note_momentary_keys(ui.ctx(), before, &momentary, &mut keys); - let mut app = tool.app(); - app.canvas.momentary = Some(momentary); - app.canvas.momentary_keys = keys; + tool.app().canvas.momentary = Some(momentary); response } diff --git a/crates/ui-egui/src/panels/gradient.rs b/crates/ui-egui/src/panels/gradient.rs index 9d6088cbd3..4c8122fa77 100644 --- a/crates/ui-egui/src/panels/gradient.rs +++ b/crates/ui-egui/src/panels/gradient.rs @@ -102,13 +102,6 @@ pub struct GradientUi { /// `paint.editGradient` sorts the stops, so the gradient shown mid-gesture is the last preview /// re-sorted: the editor's tags name stops of this one. pub(crate) begun: Option>, - /// The press of a double click that asked for a stop's color is still held. Until craft-libs#5131 reaches the - /// pin, the slider also drags the stop when the pointer drifts during that press, and the moved stop closes the - /// popover the double click opened: the panel drops that press's slider edits. - pub(crate) color_press: bool, - /// The slider's gesture that the press above began, dropped until its `Commit` or `Cancel`, which can arrive in a - /// pass after the button is up. - pub(crate) color_drag: bool, } /// Select stop `i` (the session's selected stop, shared with the Gradient tool's annotator, the @@ -836,21 +829,6 @@ fn stops_editor(app: &mut VectorcraftApp, ui: &mut Ui, g: &GradientPaint, is_gra .shared_selection(Bind::bound(&mut shared)) .drop_target::() .show(ui); - let panel = &mut app.ui.gradient_panel; - let color_press = panel.color_press || out.color_requested.is_some(); - let held = craft::ui::runtime::pointer::press_state(ui.ctx()).buttons.contains(craft::behavior::Buttons::PRIMARY); - let dropping = panel.color_drag || (color_press && out.edit.events.began()); - let ended = matches!(out.edit.events.last(), Some(EditEvent::Commit { .. } | EditEvent::Cancel { .. } | EditEvent::Set { .. })); - panel.color_press = color_press && held; - panel.color_drag = dropping && !ended; - if color_press || dropping { - // The drift of the press that asked for the color moves no stop (craft-libs#5131). - if is_grad && let Some(request) = &out.color_requested { - let at = request.rect.map_or(out.edit.response.rect.left_bottom(), |r| r.left_bottom()); - open_popover(app, request.index, at); - } - return; - } let events = &out.edit.events; if !is_grad { // The slider shows the default gradient: an edit of it applies a gradient first. diff --git a/crates/ui-egui/src/tests/home.rs b/crates/ui-egui/src/tests/home.rs index 50991b8d8c..77748f68f5 100644 --- a/crates/ui-egui/src/tests/home.rs +++ b/crates/ui-egui/src/tests/home.rs @@ -125,6 +125,50 @@ fn home_screen(app: VectorcraftApp) -> Panel { home } +/// Where one frame of the whole window `size` big painted Home's title, after `events`. +fn home_title_after(app: &mut VectorcraftApp, ctx: &egui::Context, size: egui::Vec2, events: Vec) -> egui::Rect { + let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)), events, ..Default::default() }; + let out = crate::testing::app_frame(app, ctx, raw); + let titles: Vec = crate::tests_labels::painted_shapes(&out.shapes) + .into_iter() + .filter_map(|(shape, transform, _)| match shape { + egui::Shape::Text(t) if t.galley.text() == "Welcome to VectorCraft" => Some(transform * t.visual_bounding_rect()), + _ => None, + }) + .collect(); + assert_eq!(titles.len(), 1, "Home paints its title once: {titles:?}"); + titles[0] +} + +/// How far a wheel turned to the end over Home's title moves the title, with no recent files in a window `size` big. +fn home_title_moved_by_a_wheel(size: egui::Vec2) -> f32 { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let ctx = crate::testing::ui_context(); + for _ in 0..3 { + home_title_after(&mut app, &ctx, size, vec![]); + } + assert!(crate::menus::home_showing(&app), "Home with no document open"); + let before = home_title_after(&mut app, &ctx, size, vec![]); + home_title_after(&mut app, &ctx, size, vec![egui::Event::PointerMoved(before.center())]); + home_title_after(&mut app, &ctx, size, vec![craft::ui::testing::pointer::wheel(-2000.0)]); + let mut after = before; + for _ in 0..3 { + after = home_title_after(&mut app, &ctx, size, vec![]); + } + after.top() - before.top() +} + +/// At the app's default window size, Home's column fits the canvas view, so the page has no room to scroll and shows no +/// scroll bar beside the docks: a wheel leaves the title where it is. In a smaller window, where the Learn cards stand +/// two by two and the column is taller than the view, the page scrolls. +#[test] +fn home_scrolls_only_when_its_column_is_taller_than_the_window() { + let moved = home_title_moved_by_a_wheel(egui::vec2(1440.0, 900.0)); + assert!(moved.abs() < 0.5, "at 1440 by 900 the column fits, so the page does not scroll: moved {moved}"); + let moved = home_title_moved_by_a_wheel(egui::vec2(1280.0, 800.0)); + assert!(moved < -1.0, "at 1280 by 800 the column is taller than the view, so the page scrolls: moved {moved}"); +} + /// Home's Open while a file dialog is still open (a window the system may have placed out of sight) /// says so in the status bar and asks for no second picker; once the first answers, Open asks again /// (#6160). From d70ab835f34e49eb7b304a316df6e6a9b4e712f5 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 15:30:10 -0800 Subject: [PATCH 2/3] Automation: a dropped file stays confined until its drop is delivered A drop of files the OS made in a pass that carried injected input was confined to the automation roots only through the next root frame. The drag session holds a drop that comes without a pointer position until a later pass resolves its target, so a drop delivered after that frame could open a file outside the roots. The app now keeps the dropped files the drag session holds and confines every pass until the session lets them go, the pass that delivers them included. A new test drops a file after a hover with a pointer position, in a pass without one, and checks that the drop is refused when it is delivered two passes later. --- crates/ui-egui/src/app.rs | 23 ++++++++++++++------- crates/ui-egui/src/lib.rs | 7 ++++--- crates/ui-egui/src/tests/automation.rs | 28 ++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 7adfcccd1f..cf6e35b4ae 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -11,6 +11,7 @@ use craft::ui::docking::IconGroupSeparator; use craft::ui::list::{CommandHighlight, ThumbRows}; use craft::ui::menu::{MenuTitleLook, MenuTitlePad}; use craft::ui::patterns::form_dialogs::PresetCardLook; +use craft::ui::runtime::drag::{self, OsFiles}; use craft::ui::runtime::env::{AltCodeKeys, RootEnv, Scale, ScrubDrags, WindowKey, WordsOverride, with_env}; use craft::ui::runtime::frame::{FrameInput, FrameOutput}; use craft::ui::runtime::toast::{self, Toast}; @@ -361,18 +362,26 @@ impl VectorcraftApp { } /// The folders this pass may read and write: the automation roots while the pass carries - /// input the control channel injected, or delivers files the OS dropped in such a pass; - /// anywhere otherwise. + /// input the control channel injected, or while the drag session still holds files the OS + /// dropped in such a pass; anywhere otherwise. fn automation_scope(&self, ctx: &egui::Context) -> Option> { - let delivers = self.confined_drop.is_some_and(|last| ctx.cumulative_frame_nr_for(egui::ViewportId::ROOT) <= last); - (WindowHost::of(ctx).injected_pass() || delivers).then(|| self.automation_roots.clone()).flatten() + (WindowHost::of(ctx).injected_pass() || self.confined_drop.is_some()).then(|| self.automation_roots.clone()).flatten() } - /// Notes files the OS dropped in a pass that carries injected input: the drag session delivers - /// them in the next root frame, which [`Self::automation_scope`] confines too. + /// Keeps the files the OS dropped in a pass that carries injected input until the drag session + /// lets them go: it delivers them in a later pass, after their target is resolved, and + /// [`Self::automation_scope`] confines every pass until then. fn note_confined_drop(&mut self, ctx: &egui::Context) { + if self.automation_roots.is_none() { + return; + } + let held = || drag::active::(ctx); if WindowHost::of(ctx).injected_pass() && ctx.input(|i| !i.raw.dropped_files.is_empty()) { - self.confined_drop = Some(ctx.cumulative_frame_nr_for(egui::ViewportId::ROOT) + 1); + self.confined_drop = held(); + } else if let Some(dropped) = &self.confined_drop + && !held().is_some_and(|now| Arc::ptr_eq(&now, dropped)) + { + self.confined_drop = None; } } } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 115af4ac32..c3412f24db 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -346,9 +346,10 @@ pub struct VectorcraftApp { /// (`--automation-read-root`, `--automation-write-root`); `None`: anywhere. See /// [`Self::with_automation_roots`]. automation_roots: Option>, - /// The last root frame of a drop of files the OS made in a pass that carried injected input: the drag session - /// delivers that drop in the next frame, which [`Self::ui`] confines to the automation roots as well. - confined_drop: Option, + /// The files the OS dropped in a pass that carried injected input, while the drag session holds them: every pass + /// until the session lets them go, the one that delivers them included, is confined to the automation roots as well + /// ([`Self::ui`]). + confined_drop: Option>, /// The agents link while the ArtCraft Launcher's switch may let agents in ([`Self::with_agents`]). #[cfg(not(target_arch = "wasm32"))] pub(crate) agents: Option>, diff --git a/crates/ui-egui/src/tests/automation.rs b/crates/ui-egui/src/tests/automation.rs index b8798e6cfa..7bdc89069f 100644 --- a/crates/ui-egui/src/tests/automation.rs +++ b/crates/ui-egui/src/tests/automation.rs @@ -580,10 +580,24 @@ fn a_drop_in_a_pass_with_one_step_of_injected_input_is_confined_when_delivered() drop_in_an_injected_pass_is_confined("ui.text", json!({"text": "a"})); } +/// The OS held the file under the pointer and drops it in a pass with no pointer position: the drag +/// session holds the drop until a later pass resolves its target, and the drop is still refused when +/// it is delivered there. +#[test] +fn a_drop_that_waits_for_its_target_is_confined_when_delivered() { + drop_is_confined("ui.text", json!({"text": "a"}), true); +} + /// Injects `method` with `params`, has the person drop a file outside the automation roots in the /// same pass, and checks that the drop opens nothing, then that a later drop of the person's opens /// the file. fn drop_in_an_injected_pass_is_confined(method: &str, params: Value) { + drop_is_confined(method, params, false); +} + +/// [`drop_in_an_injected_pass_is_confined`]; `pointer`: the pass that hovers the file carries a +/// pointer position and the drop's pass none, so the drag session delivers the drop a pass later. +fn drop_is_confined(method: &str, params: Value, pointer: bool) { #[derive(Debug)] struct Dropped(PathBuf); impl egui::DroppedFile for Dropped { @@ -602,6 +616,12 @@ fn drop_in_an_injected_pass_is_confined(method: &str, params: Value) { let mut raw = egui::RawInput::default(); if hovered { raw.hovered_files.push(egui::HoveredFile { path: Some(outside.clone()), mime: String::new() }); + if pointer { + raw.events.push(egui::Event::PointerMoved(egui::pos2(300.0, 300.0))); + } + } + if dropped && pointer { + raw.events.push(egui::Event::PointerGone); } if dropped { raw.dropped_files.push(std::sync::Arc::new(Dropped(outside.clone()))); @@ -614,13 +634,13 @@ fn drop_in_an_injected_pass_is_confined(method: &str, params: Value) { tx.send(req).unwrap(); app.run_control(&ctx); pass(&mut app, false, true); - // The drag session delivers a drop of files in the pass after the one the OS dropped them in. - assert_eq!(pass(&mut app, false, false), 0, "{method}: the drop of the pass carrying the input is confined"); - for _ in 0..4 { - pass(&mut app, false, false); + // The drag session delivers a drop of files in a pass after the one the OS dropped them in. + for _ in 0..5 { + assert_eq!(pass(&mut app, false, false), 0, "{method}: the drop of the pass carrying the input is confined"); } pass(&mut app, true, false); pass(&mut app, false, true); + pass(&mut app, false, false); assert_eq!(pass(&mut app, false, false), 1, "{method}: the person's pass is not"); let _ = std::fs::remove_dir_all(base); } From 7c2994d78e8db75405eedae30037372479b11f81 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 16:42:16 -0800 Subject: [PATCH 3/3] Tests: give each confined drop scenario its own fixture directory The two drop tests that inject `ui.text` both used the directory vc-ui-roots-synthetic-ui.text-. Tests run in parallel, and each one removes that directory during setup and cleanup, so one test could delete outside/b.svg before the other's final drop. The tag now also names whether the scenario moves the pointer. --- crates/ui-egui/src/tests/automation.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tests/automation.rs b/crates/ui-egui/src/tests/automation.rs index 7bdc89069f..9bc6810b71 100644 --- a/crates/ui-egui/src/tests/automation.rs +++ b/crates/ui-egui/src/tests/automation.rs @@ -608,7 +608,8 @@ fn drop_is_confined(method: &str, params: Value, pointer: bool) { std::fs::read(&self.0).map_err(|e| e.to_string()) } } - let (mut app, tx, base) = confined(&format!("synthetic-{method}")); + // Each scenario has its own directory, so tests running in parallel do not remove each other's files. + let (mut app, tx, base) = confined(&format!("synthetic-{method}-{}", if pointer { "pointer" } else { "nopointer" })); let ctx = crate::testing::ui_context(); let outside = base.join("outside/b.svg"); // The OS holds the file over the window in the pass before it drops it (`hovered`), as a desktop drag does.