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 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-12-01 15:41:44 +01:00
1 parent d8aaec1a59
commit d7349ffee9
7 files changed
+111 -8

No files matched your search

+3 -2
View File
@@ -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,
}
}
}
+4 -3
View File
@@ -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));
+3
View File
@@ -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[..])
+14 -3
View File
@@ -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::*;
@@ -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<PhotocraftApp>> {
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<PhotocraftApp>>) -> 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<PhotocraftApp>>) -> usize {
h.state().session.active().unwrap().history.entries().iter().filter(|e| *e == "Nudge").count()
}
fn nudge(h: &mut Harness<'_, Box<PhotocraftApp>>) {
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<PhotocraftApp>>, 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");
}
+1
View File
@@ -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);
@@ -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);