Move gear: the pick marker lasts until the next active-layer change, not a frame (#11381)

The counter lives in the engine: Session::active_layer_changes(), bumped by Session::execute whenever a command leaves a different active document or layer (selection commands, Action playback, undo, canvas picks). note_move_pick stores it with the picked id; layer_reveal::track accepts the marker only if the active layer is that id and the count is unchanged, so it survives a hidden panel for any number of frames and any later non-pick change (even back to the same id) invalidates it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
Trevor BrownandClaude Fable 5.1 committed 2026-11-06 11:55:37 -05:00
1 parent f4e665c1a2
commit 7fc8ec621c
8 files changed
+72 -10

No files matched your search

+4
View File
@@ -216,6 +216,10 @@ pub struct Session {
active_generation: u64,
/// The document id [`Self::active_generation`] was last bumped for.
active_doc_for_generation: Option<photocraft_doc::DocId>,
/// Counts the [`Session::execute`] calls that changed the active document or layer (selection
/// commands, Action playback, undo, a canvas pick). A caller that remembers how a change came
/// about compares it to see that nothing changed the active layer since.
active_layer_changes: u64,
pub tools: ToolState,
/// Log of executed commands (for action recording and debugging).
pub journal: Vec<(String, Value)>,
+5
View File
@@ -43,6 +43,11 @@ impl Session {
self.active_generation
}
/// Count of [`Self::execute`] calls that changed the active document or layer; see the field.
pub fn active_layer_changes(&self) -> u64 {
self.active_layer_changes
}
/// Bump [`Self::active_generation`] when the active document id changed. Call after every
/// assignment to `self.active`.
pub(crate) fn note_active_change(&mut self) {
+6 -1
View File
@@ -15,7 +15,12 @@ impl Session {
/// Runs synchronously, including job-capable commands (see [`jobs`]; [`Session::start`] runs
/// those in the background).
pub fn execute(&mut self, id: &str, params: Value) -> Result<Value> {
match self.dispatch(id, params, false)? {
let before = self.active().map(|st| (st.doc.id, st.active_layer));
let result = self.dispatch(id, params, false);
if self.active().map(|st| (st.doc.id, st.active_layer)) != before {
self.active_layer_changes = self.active_layer_changes.wrapping_add(1);
}
match result? {
jobs::Started::Done(v) => Ok(v),
// Not reached: inline dispatch never starts a job. Waiting is still correct.
jobs::Started::Job(j) => self.wait_job(j),
+18
View File
@@ -1986,3 +1986,21 @@ fn the_document_activation_generation_bumps_on_switch_and_back() {
assert_eq!(s.active_generation(), g3);
assert_eq!(s.active().unwrap().doc.id, first);
}
#[test]
fn the_active_layer_change_count_moves_only_when_a_command_changes_the_active_layer() {
let mut s = session_with_doc();
s.execute("layer.new.layer", json!({})).unwrap();
let a = s.active().unwrap().active_layer.unwrap();
s.execute("layer.new.layer", json!({})).unwrap();
let b = s.active().unwrap().active_layer.unwrap();
let n = s.active_layer_changes();
s.execute("layer.select", json!({"layer": b.0})).unwrap();
assert_eq!(s.active_layer_changes(), n, "selecting the active layer again changes nothing");
s.execute("layer.select", json!({"layer": a.0})).unwrap();
assert!(s.active_layer_changes() > n);
let m = s.active_layer_changes();
s.execute("layer.select", json!({"layer": b.0})).unwrap();
s.execute("layer.select", json!({"layer": a.0})).unwrap();
assert!(s.active_layer_changes() >= m + 2, "a round trip back to the same layer still counts");
}
+3 -2
View File
@@ -212,12 +212,13 @@ fn filter_event_before_tool(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::
Some((raw, ev, mods))
}
/// Remember a Move-way pick that changed the active layer (with this frame), so the Layers panel's
/// Remember a Move-way pick that changed the active layer (with the engine's change count after it, so
/// any later change invalidates the marker), so the Layers panel's
/// reveal can honour Expand layer group on click (layer_reveal.rs).
fn note_move_pick(app: &mut PhotocraftApp, active_before: Option<photocraft_doc::LayerId>) {
let active_after = app.session.active().and_then(|st| st.active_layer);
if active_after != active_before {
app.move_pick = active_after.map(|id| (id, app.frame));
app.move_pick = active_after.map(|id| (id, app.session.active_layer_changes()));
}
}
+3 -2
View File
@@ -429,8 +429,9 @@ pub struct PhotocraftApp {
/// A ⌘⌥⌃-click layer pick is in progress; its drag and release are swallowed (`quick_pick`).
pub(crate) quick_pick: bool,
/// The layer a canvas click picked the Move tool way (its Auto-Select, or a ⌘-click from another
/// tool) and the frame (`frame`) of the pick, until the Layers panel's reveal reads it. The
/// reveal accepts it in that frame or the next only (`layer_reveal`, #11381).
/// tool) and the engine's active-layer change count right after that pick
/// (`Session::active_layer_changes`). The Layers panel's reveal reads it when it next draws, and
/// accepts it only if nothing changed the active layer since, however long ago (`layer_reveal`, #11381).
pub(crate) move_pick: Option<(photocraft_doc::LayerId, u64)>,
/// The next tool `Down` is an Alt+right-drag that resizes the brush (#297). `tool_event`
/// takes it on every event, so a press another handler consumes can't leave it set.
@@ -389,13 +389,39 @@ fn a_pick_marker_the_hidden_layers_panel_never_read_does_not_hide_a_later_comman
}
#[test]
fn a_pick_marker_is_read_in_its_frame_and_the_next() {
fn a_pick_marker_survives_any_number_of_frames_while_the_layers_panel_is_hidden() {
let (mut app, inner, group, ctx) = closed_group_doc(Tool::Brush, false);
app.ui.tool_options.move_auto_select = false;
ctrl_click(&mut app);
app.frame += 5;
assert_eq!(crate::layer_reveal::track(&mut app, &ctx), Some(inner));
assert!(!expanded(&app, group), "the pick is still the latest change of the active layer");
}
#[test]
fn commands_after_a_pick_in_the_same_frame_or_the_next_make_it_a_command_change() {
for gap in [0, 1] {
let (mut app, inner, group, ctx) = closed_group_doc(Tool::Brush, false);
app.ui.tool_options.move_auto_select = false;
ctrl_click(&mut app);
app.frame += gap;
app.run("layer.select", json!({"layer": group.0})).unwrap();
app.run("layer.select", json!({"layer": inner.0})).unwrap();
assert_eq!(crate::layer_reveal::track(&mut app, &ctx), Some(inner));
assert!(!expanded(&app, group), "a pick {gap} frame(s) old still governs the reveal");
assert!(expanded(&app, group), "selects {gap} frame(s) after the pick reveal the layer");
}
}
#[test]
fn a_pick_marker_is_read_once_and_governs_the_next_change_only() {
let (mut app, inner, group, ctx) = closed_group_doc(Tool::Brush, false);
app.ui.tool_options.move_auto_select = false;
ctrl_click(&mut app);
assert_eq!(crate::layer_reveal::track(&mut app, &ctx), Some(inner));
assert!(!expanded(&app, group));
app.run("layer.select", json!({"layer": group.0})).unwrap();
assert_eq!(crate::layer_reveal::track(&mut app, &ctx), Some(group));
app.run("layer.select", json!({"layer": inner.0})).unwrap();
assert_eq!(crate::layer_reveal::track(&mut app, &ctx), Some(inner));
assert!(expanded(&app, group), "a later command change opens the group");
}
+5 -3
View File
@@ -27,9 +27,11 @@ pub fn track(app: &mut PhotocraftApp, ctx: &egui::Context) -> Option<LayerId> {
let index = app.session.active_index()?;
let active = app.session.active()?.active_layer;
let now = Seen(index, active);
// The canvas sets the marker in its frame and the panel may draw before or after it, so it reads the
// marker in that frame or the next. An older one is a pick the hidden panel never saw: discard.
let pick = app.move_pick.take().filter(|&(_, frame)| frame + 1 >= app.frame).map(|(id, _)| id);
// The marker says the latest active-layer change was a Move-way pick of that layer: it holds only
// while no later change happened (the engine's change count is unchanged), however many frames a
// hidden panel missed, and whether or not the final layer is the same id.
let changes = app.session.active_layer_changes();
let pick = app.move_pick.take().filter(|&(id, at)| Some(id) == active && at == changes).map(|(id, _)| id);
let before = ctx.data(|d| d.get_temp::<Seen>(seen_id()));
ctx.data_mut(|d| d.insert_temp(seen_id(), now));
match before {