From d8aaec1a594dd8c9935481ba19a59ed88fe5ab30 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 15:29:37 +0100 Subject: [PATCH 1/3] WIP: Move tool: arrow nudges seconds apart stay one Nudge state (#18141) From d7349ffee9947e182410d7b3134816464fbb4c56 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 15:41:44 +0100 Subject: [PATCH 2/3] Move tool: arrow nudges seconds apart stay one Nudge state (#18141) The Tools Nudge Bundle Pause default goes from 1 s to 5 s, so taps a few seconds apart are still one History state, as in the reference application. A press on the canvas now ends the run even when it changes nothing in the document, so the next nudge is a state of its own. Co-Authored-By: Claude Opus 5.5 --- crates/engine-core/src/prefs.rs | 5 +- crates/engine-core/src/prefs/tests.rs | 7 +- crates/ui-egui/src/canvas.rs | 3 + crates/ui-egui/src/input/nudge_bundle.rs | 17 +++- .../src/input/nudge_bundle_pause_tests.rs | 85 +++++++++++++++++++ crates/ui-egui/src/nudge_bundle_tests.rs | 1 + crates/ui-egui/src/tools/move_mods/tests.rs | 1 + 7 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 crates/ui-egui/src/input/nudge_bundle_pause_tests.rs diff --git a/crates/engine-core/src/prefs.rs b/crates/engine-core/src/prefs.rs index 76d893ed93..1ee81aab1a 100644 --- a/crates/engine-core/src/prefs.rs +++ b/crates/engine-core/src/prefs.rs @@ -531,7 +531,8 @@ pub struct Tools { /// History state (#2259). Off: every press is a state. pub bundle_nudges: bool, /// The longest pause, in milliseconds, between two nudges that still bundle into one state. - /// Longer than a key's auto-repeat delay (about half a second), so a held key is one state. + /// Longer than a key's auto-repeat delay (about half a second), so a held key is one state, + /// and than a few seconds of looking between taps, which still nudge as one state (#18141). pub nudge_bundle_pause_ms: u32, } @@ -553,7 +554,7 @@ impl Default for Tools { tablet_input: TabletInput::WindowsInk, pressure_curve: vec![[0.0, 0.0], [1.0, 1.0]], bundle_nudges: true, - nudge_bundle_pause_ms: 1000, + nudge_bundle_pause_ms: 5000, } } } diff --git a/crates/engine-core/src/prefs/tests.rs b/crates/engine-core/src/prefs/tests.rs index e072da4dc5..5a6099e40f 100644 --- a/crates/engine-core/src/prefs/tests.rs +++ b/crates/engine-core/src/prefs/tests.rs @@ -767,16 +767,17 @@ fn ruler_units_round_to_their_own_decimal_places() { } /// #2259: arrow-key nudges bundle into one History state by default, within a pause long enough -/// for a held key's auto-repeat delay; both are Tools preferences with a validated range. +/// for a held key's auto-repeat delay and a few seconds between taps (#18141); both are Tools +/// preferences with a validated range. #[test] fn nudge_bundling_preferences() { let p = Preferences::default(); assert!(p.tools.bundle_nudges); - assert_eq!(p.tools.nudge_bundle_pause_ms, 1000); + assert_eq!(p.tools.nudge_bundle_pause_ms, 5000); // Preferences saved before these existed load with the defaults. let old: Preferences = serde_json::from_value(json!({"tools": {"showTooltips": false}})).unwrap(); assert!(old.tools.bundle_nudges && !old.tools.show_tooltips); - assert_eq!(old.tools.nudge_bundle_pause_ms, 1000); + assert_eq!(old.tools.nudge_bundle_pause_ms, 5000); let mut s = session(); assert_eq!(s.execute("prefs.get", json!({"path": "tools.bundleNudges"})).unwrap(), json!(true)); diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 6703f383f0..9d90f445ec 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -218,6 +218,9 @@ pub fn canvas_view( if active && !app.dialog_open() && matches!(shown.output.press.phase, PressPhase::Down { .. }) { crate::spring_tools::note_canvas_press(app); } + if matches!(shown.output.press.phase, PressPhase::Down { .. }) { + crate::nudge_bundle::note_canvas_press(app); + } if let Some(stored) = stored && let Some(current) = app.ui.views.get(idx) && let Some(asked) = current.pending.strip_prefix(&stored.pending[..]) diff --git a/crates/ui-egui/src/input/nudge_bundle.rs b/crates/ui-egui/src/input/nudge_bundle.rs index 87746c7165..f1769d61bb 100644 --- a/crates/ui-egui/src/input/nudge_bundle.rs +++ b/crates/ui-egui/src/input/nudge_bundle.rs @@ -6,9 +6,10 @@ //! edits with the same key into one step, see `Session::execute`) and Undo takes back the run. //! //! A run lasts while each nudge comes within the Tools › Nudge Bundle Pause of the one before it -//! (longer than a key's auto-repeat delay, so a held key is one run) and nothing else happened -//! to the document in between: another edit, an Undo or Redo, a different layer selected or a -//! save each end it. Tools › Bundle Arrow-Key Nudges off gives every press its own state. +//! (by default five seconds: longer than a key's auto-repeat delay, so a held key is one run, and +//! than a look at the picture between taps, #18141) and nothing else happened in between: another +//! edit, an Undo or Redo, a different layer selected, a save or a click on the canvas each end it. +//! Tools › Bundle Arrow-Key Nudges off gives every press its own state. //! //! [`NudgeBundle`] only decides which run a nudge belongs to; it reads the clock from the key //! handlers ([`NudgeBundle::now`]) and the document from the caller, so it is tested without egui. @@ -110,6 +111,16 @@ pub(crate) fn run(app: &mut PhotocraftApp, what: &str, id: &str, mut params: Val result } +/// A press on the canvas ends the run of nudges, even one that changes nothing in the document +/// (#18141): the next nudge is a History state of its own. +pub(crate) fn note_canvas_press(app: &mut PhotocraftApp) { + app.nudge_bundle.reset(); +} + +#[cfg(test)] +#[path = "nudge_bundle_pause_tests.rs"] +mod pause_tests; + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ui-egui/src/input/nudge_bundle_pause_tests.rs b/crates/ui-egui/src/input/nudge_bundle_pause_tests.rs new file mode 100644 index 0000000000..4c3c180b61 --- /dev/null +++ b/crates/ui-egui/src/input/nudge_bundle_pause_tests.rs @@ -0,0 +1,85 @@ +//! #18141: arrow-key nudges a few seconds apart are still one "Nudge" state with the default +//! preferences, and a click on the canvas between two nudges starts a new one. + +use egui_kittest::Harness; +use photocraft_geom::Rect; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::state::Tool; + +fn harness() -> Harness<'static, Box> { + let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_max_steps(64).build_eframe(|cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app.run("select.rect", json!({"x": 40, "y": 40, "width": 20, "height": 20})).unwrap(); + app.run("edit.fill", json!({"color": "#ff0000"})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + app.ui.tool = Tool::Move; + app + }); + h.run_steps(6); + h +} + +fn bounds(h: &Harness<'_, Box>) -> Rect { + let st = h.state().session.active().unwrap(); + st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().content_bounds() +} + +fn nudges(h: &Harness<'_, Box>) -> usize { + h.state().session.active().unwrap().history.entries().iter().filter(|e| *e == "Nudge").count() +} + +fn nudge(h: &mut Harness<'_, Box>) { + h.key_press(egui::Key::ArrowRight); + h.run_steps(1); +} + +/// The test clock runs a quarter of a second per frame. +fn wait_seconds(h: &mut Harness<'_, Box>, seconds: usize) { + h.run_steps(seconds * 4); +} + +#[test] +fn nudges_four_seconds_apart_are_one_state_by_default() { + let mut h = harness(); + let start = bounds(&h); + for _ in 0..3 { + nudge(&mut h); + wait_seconds(&mut h, 4); + } + nudge(&mut h); + assert_eq!(bounds(&h).x0, start.x0 + 4); + assert_eq!(nudges(&h), 1, "four nudges with four seconds between them are one state"); + h.state_mut().session.undo(); + assert_eq!(bounds(&h), start, "one Undo takes the whole run back"); +} + +#[test] +fn a_canvas_click_between_nudges_starts_a_new_state() { + let mut h = harness(); + // Auto-Select off: the click picks no layer, so it changes nothing in the document. + h.state_mut().ui.tool_options.move_auto_select = false; + let start = bounds(&h); + nudge(&mut h); + nudge(&mut h); + let seen = crate::nudge_bundle::Seen::of(h.state().session.active().unwrap()); + let steps = h.state().session.active().unwrap().history.past_len(); + let p = crate::canvas::testing::to_screen(h.state(), [52.0, 50.0]); + h.event(egui::Event::PointerMoved(p)); + h.run_steps(1); + for pressed in [true, false] { + h.event(egui::Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }); + h.run_steps(1); + } + assert_eq!(h.state().session.active().unwrap().history.past_len(), steps, "the click itself is no History state"); + assert_eq!(crate::nudge_bundle::Seen::of(h.state().session.active().unwrap()), seen, "nor any other change"); + nudge(&mut h); + assert_eq!(bounds(&h).x0, start.x0 + 3); + assert_eq!(nudges(&h), 2, "the nudge after the click is a state of its own"); + h.state_mut().session.undo(); + assert_eq!(bounds(&h).x0, start.x0 + 2, "Undo takes back only the nudge after the click"); +} diff --git a/crates/ui-egui/src/nudge_bundle_tests.rs b/crates/ui-egui/src/nudge_bundle_tests.rs index 576287ee75..c38427f511 100644 --- a/crates/ui-egui/src/nudge_bundle_tests.rs +++ b/crates/ui-egui/src/nudge_bundle_tests.rs @@ -76,6 +76,7 @@ fn a_held_key_is_one_history_step() { #[test] fn a_pause_starts_a_new_step_and_the_preference_sets_how_long() { let mut h = harness(); + h.state_mut().run("prefs.set", json!({"path": "tools.nudgeBundlePauseMs", "value": 1000})).unwrap(); let n0 = steps(&h); nudge(&mut h, egui::Key::ArrowRight, 1); nudge(&mut h, egui::Key::ArrowRight, 1); diff --git a/crates/ui-egui/src/tools/move_mods/tests.rs b/crates/ui-egui/src/tools/move_mods/tests.rs index 8878851574..860d33cffa 100644 --- a/crates/ui-egui/src/tools/move_mods/tests.rs +++ b/crates/ui-egui/src/tools/move_mods/tests.rs @@ -332,6 +332,7 @@ fn a_run_of_arrow_nudges_is_one_history_step_zoomed_out() { #[test] fn a_pause_ends_the_run() { let mut app = app_with_layer(); + app.session.edit_prefs(|p| p.tools.nudge_bundle_pause_ms = 1000); let id = app.session.active().unwrap().active_layer.unwrap(); let h0 = history(&app); press_at(&mut app, egui::Key::ArrowRight, egui::Modifiers::NONE, 1.0); From 5abd1c172dcc02c0fe52f888d55f3491f67ec6f4 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 15:52:42 +0100 Subject: [PATCH 3/3] Prefs test: Reset restores the 5 s nudge pause default (#18141) Co-Authored-By: Claude Opus 5.5 --- crates/engine-core/src/prefs/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine-core/src/prefs/tests.rs b/crates/engine-core/src/prefs/tests.rs index 5a6099e40f..59b69468ef 100644 --- a/crates/engine-core/src/prefs/tests.rs +++ b/crates/engine-core/src/prefs/tests.rs @@ -795,7 +795,7 @@ fn nudge_bundling_preferences() { assert_eq!(s.prefs().tools.nudge_bundle_pause_ms, 10_000, "a rejected value changes nothing"); s.execute("prefs.reset", json!({"path": "tools"})).unwrap(); assert!(s.prefs().tools.bundle_nudges); - assert_eq!(s.prefs().tools.nudge_bundle_pause_ms, 1000); + assert_eq!(s.prefs().tools.nudge_bundle_pause_ms, 5000); } /// #3665: Photoshop's second default keys (F2/F3/F4, Shift+F7, Cmd++) are a command's