Batch 18 (CodeRabbit): parity floor back to 660; Nudge relabel only after a move; shape box drag ends on a tool switch

- menus/parity.rs: #11503 lowered FLOOR to 658 (two Warp rows went);
  with #11497's two entries the batch has 660 live again.
- #11443: a nudge that changed nothing (zero offset) no longer renames
  the state on top to "Nudge".
- #11295: a handle drag remembers its tool and ends on any tool switch,
  also to another tool that shows the box; the release of a drag that was
  just dropped is consumed instead of reaching the new tool; the box is
  drawn only over the active document's view.

Tests for each (both new UI tests fail without their fix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-06 03:07:11 +01:00
1 parent 8f7815adc5
commit ea15b297f5
6 files changed
+52 -6

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ use crate::menu_catalog::CATALOG;
use crate::menus::is_live;
/// Minimum number of live catalog items. Raise it when parity grows; never lower it.
pub const FLOOR: usize = 658;
pub const FLOOR: usize = 660;
/// One top-level menu's coverage.
#[derive(Clone, Debug, serde::Serialize)]
@@ -157,3 +157,21 @@ fn an_alt_arrow_nudge_keeps_duplicate_plus_move() {
assert_eq!(history(&app), h0 + 1);
assert_eq!(newest(&app).as_deref(), Some("Duplicate + Move"));
}
/// A zero offset moves nothing: the step on top (here the paint) keeps its name.
#[test]
fn a_zero_nudge_renames_no_earlier_step() {
let mut app = app();
for bundle in [false, true] {
app.session.edit_prefs(|p| p.tools.bundle_nudges = bundle);
let before: Vec<String> = app.session.active().unwrap().history.entries().to_vec();
crate::move_mods::nudge(&mut app, 0.0, 0.0, false);
let after: Vec<String> = app.session.active().unwrap().history.entries().to_vec();
if after.len() == before.len() {
assert_eq!(after, before, "bundle {bundle}");
} else {
assert_eq!(after.last().map(String::as_str), Some("Nudge"), "bundle {bundle}");
assert_eq!(after[..before.len()], before[..], "bundle {bundle}");
}
}
}
@@ -298,3 +298,20 @@ fn with_background_jobs_the_scale_step_is_named_and_the_one_before_is_kept() {
assert_eq!(after[..before.len()], before[..], "the earlier steps keep their names");
assert_eq!(after.last().map(String::as_str), Some("Transform Path"));
}
/// A switch to another tool during a handle drag ends the drag, also when the new tool shows the
/// box too; the release scales nothing and is still the box's (it doesn't reach the new tool).
#[test]
fn a_tool_switch_during_a_drag_ends_it_and_takes_its_release() {
let (mut app, a, b) = app_with_two_shapes(Tool::Rectangle);
let steps = app.session.active().unwrap().history.past_len();
let (ba, bb) = (bounds(&app, a), bounds(&app, b));
tool_event(&mut app, ToolEvent::Down { x: 723.0, y: 451.0, pressure: 1.0 }, NONE);
tool_event(&mut app, ToolEvent::Move { x: 623.0, y: 391.0, pressure: 1.0 }, NONE);
assert!(app.ui.shape_box.is_some());
app.ui.tool = Tool::PathSelection;
assert!(crate::shape_bounds_box::pointer(&mut app, ToolEvent::Up { x: 623.0, y: 391.0 }, NONE), "the release is the box's");
assert!(app.ui.shape_box.is_none());
assert_eq!(app.session.active().unwrap().history.past_len(), steps);
assert_eq!((bounds(&app, a), bounds(&app, b)), (ba, bb));
}
+4 -1
View File
@@ -273,6 +273,7 @@ pub fn nudge(app: &mut PhotocraftApp, dx: f64, dy: f64, duplicate_first: bool) {
return;
}
let from = if duplicate_first { duplicate(app) } else { None };
let revision = app.session.active().map(|st| st.revision);
let moved = if duplicate_first {
// A copy is a state of its own, folded with its move below.
app.nudge_bundle.reset();
@@ -282,8 +283,10 @@ pub fn nudge(app: &mut PhotocraftApp, dx: f64, dy: f64, duplicate_first: bool) {
};
match moved {
// The reference names an arrow-key move "Nudge"; a bundled run is one step with that name.
// Only a move that changed the document: a zero offset records nothing, and the state
// on top is then another edit's.
Ok(_) if from.is_none() => {
if let Some(st) = app.session.active_mut() {
if let Some(st) = app.session.active_mut().filter(|st| Some(st.revision) != revision) {
st.history.set_current_label(tl!("Nudge"));
}
}
+8 -3
View File
@@ -31,6 +31,8 @@ pub struct Drag {
/// document nor an edit under it (Undo, say).
doc: photocraft_doc::DocId,
revision: u64,
/// The tool it started with: a switch to another tool ends it, even one that shows the box.
tool: Tool,
/// The selected shape layers, as at the press.
layers: Vec<u64>,
/// Their union box `[x0, y0, x1, y1]` at the press.
@@ -170,7 +172,7 @@ pub fn cancel(app: &mut PhotocraftApp) {
pub fn cancel_stale(app: &mut PhotocraftApp) {
let Some(d) = app.ui.shape_box.as_ref() else { return };
let current = app.session.active().is_some_and(|st| st.doc.id == d.doc && st.revision == d.revision);
if !current || !shows(app) {
if !current || app.ui.tool != d.tool || !shows(app) {
cancel(app);
}
}
@@ -185,7 +187,7 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
let Some(handle) = hit(app, [x, y]) else { return false };
let Some((layers, rect)) = selection(app) else { return false };
let Some((doc, revision)) = app.session.active().map(|st| (st.doc.id, st.revision)) else { return false };
app.ui.shape_box = Some(Drag { doc, revision, layers, rect, handle, start: [x, y], scale: [1.0, 1.0] });
app.ui.shape_box = Some(Drag { doc, revision, tool: app.ui.tool, layers, rect, handle, start: [x, y], scale: [1.0, 1.0] });
// The press may have started the Move tool's snapping, which a box drag has none of.
app.prefs_rt.snap = None;
app.prefs_rt.snap_lines.clear();
@@ -198,9 +200,12 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
true
}
ToolEvent::Up { x, y } => {
let had = app.ui.shape_box.is_some();
cancel_stale(app);
if app.ui.shape_box.is_none() {
return false;
// The release of a drag that was just dropped is still the box's: it must not
// reach the tool that is active now.
return had;
}
pointer(app, ToolEvent::Move { x, y, pressure: 1.0 }, mods);
let Some(d) = app.ui.shape_box.take() else { return true };
@@ -194,7 +194,10 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform
draw_anchor(painter, to_scr([k.anchor.x, k.anchor.y]), true, accent);
}
}
crate::shape_bounds_box::draw(app, painter, &to_scr, accent);
// Only over the active document, whose selected layers the box frames.
if st.is_some_and(|s| s.doc.id == doc.id) {
crate::shape_bounds_box::draw(app, painter, &to_scr, accent);
}
crate::corner_radius::draw(app, painter, &to_scr, accent);
}
// Pen path in progress, with handles of the last knot and a rubber band to the pointer. While