Auto: Preserve path history and clean up unavailable tools

Reject pending path undo/redo during quick-mask editing without consuming history. Finish active strokes and polygon-fill boxes when tools become unavailable in either viewport. Hide unavailable tool properties for Paint and Path effects.

Add regression tests for history preservation, gesture cleanup, and effect tool controls.
This commit is contained in:
chasse20 committed 2026-11-15 21:21:52 +00:00
1 parent a43dadbaa5
commit 7ad3f70701
4 files changed
+105 -2

No files matched your search

+28
View File
@@ -669,6 +669,11 @@ impl Session {
let from = if back { &self.path_steps.0 } else { &self.path_steps.1 };
let Some((index, state)) = from.iter().enumerate().rfind(|(_, state)| !state.same_curve(&self.tool.path)) else { return Ok(false) };
// Returning false here would let undo/redo consume document history instead.
if self.quick_mask.editing {
return Err(EngineError::Other("paths can't edit the quick mask: stop editing it first".into()));
}
let path = &mut self.tool.path;
let previous = std::mem::replace(path, PathState { editing: path.editing, edited: path.edited, ..state.clone() });
if let Err(error) = self.path_live() {
@@ -1086,6 +1091,29 @@ mod tests {
assert_eq!(changed_tiles(&before, &after, LayerId(8)), BTreeSet::new());
}
#[test]
fn quick_mask_preserves_pending_path_undo_and_redo() {
let mut session = Session::new_project("t", texturecraft_geom::primitives::plane(1.0, 1), "builtin:test", None, 128).unwrap();
execute(&mut session, "tool.path", &json!({"uvPoints": [[0.2, 0.5], [0.8, 0.5]]})).unwrap();
session.path_checkpoint();
session.tool.path.points[0].y = 0.3;
session.path_live().unwrap();
for back in [true, false] {
let curve = session.tool.path.clone();
let steps = (session.path_steps.0.len(), session.path_steps.1.len());
let history = (session.history_labels(), session.redo_labels());
let pixels = session.doc.pixels.clone();
session.quick_mask.editing = true;
assert!(if back { session.undo() } else { session.redo() }.is_err());
assert!(curve.same_curve(&session.tool.path));
assert_eq!(steps, (session.path_steps.0.len(), session.path_steps.1.len()));
assert_eq!(history, (session.history_labels(), session.redo_labels()));
assert_eq!(format!("{:?}", pixels), format!("{:?}", session.doc.pixels));
session.quick_mask.editing = false;
if back { session.undo() } else { session.redo() }.unwrap();
}
}
#[test]
fn point_checkpoints_skip_noops_and_bound_retained_points() {
let mut session = Session::new_project("t", texturecraft_geom::primitives::plane(1.0, 1), "builtin:test", None, 128).unwrap();
+6 -2
View File
@@ -2510,7 +2510,9 @@ fn effect_properties(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer, effe
tr("Paint on the mesh to edit this mask. Use the Material tab's mask value for gray.")
};
ui.label(RichText::new(hint).color(tokens.text_dim));
tool_properties(app, ui);
if app.session.tool_usable(app.session.tool.tool) {
tool_properties(app, ui);
}
}
EffectKind::Path(paths) => {
ui.label(
@@ -2533,7 +2535,9 @@ fn effect_properties(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer, effe
}
});
}
tool_properties(app, ui);
if app.session.tool_usable(app.session.tool.tool) {
tool_properties(app, ui);
}
}
EffectKind::Filter(filter) => filter_properties(app, ui, id, filter),
EffectKind::ColorSelection { colors, tolerance } => crate::color_selection_editor::color_selection_properties(app, ui, effect_id, colors, *tolerance),
+40
View File
@@ -54,6 +54,7 @@ pub fn central(app: &mut TextureCraftApp, ui: &mut Ui) {
crate::toolbar::paint_bar(app, ui);
}
finish_unavailable_tool_gestures(app);
crate::id_color_pick::IdColorPick::end_when_stale(app);
let tokens = Tokens::get(ui.ctx());
let aux_view = match app.session.view {
@@ -1545,6 +1546,18 @@ fn tool_acts(app: &TextureCraftApp) -> bool {
app.ui.mode == crate::state::Mode::Painting && app.session.tool_usable(app.session.tool.tool)
}
/// Both views must close gestures even when the selection disables their input handlers.
fn finish_unavailable_tool_gestures(app: &mut TextureCraftApp) {
if !tool_acts(app) {
if app.session.stroke_active()
&& let Err(error) = app.session.end_stroke()
{
app.toast(error.to_string(), true);
}
app.session.end_polygon_fill_box();
}
}
/// Tools that paint with the brush (and show its cursor).
fn brush_tool(t: Tool) -> bool {
matches!(t, Tool::Paint | Tool::Eraser | Tool::Projection | Tool::Smudge | Tool::Clone | Tool::Path)
@@ -1996,6 +2009,33 @@ fn bake_paint_overlay(app: &TextureCraftApp, ui: &Ui, painter: &egui::Painter, t
mod tests {
use super::*;
#[test]
fn unavailable_tools_finish_strokes_and_box_fills() {
use texturecraft_engine::{StackTarget, core::LayerId, geom::primitives};
for tool in [Tool::Paint, Tool::PolygonFill] {
let session = Session::new_project("t", primitives::plane(2.0, 4), "test", None, 128).unwrap();
let mut harness = egui_kittest::Harness::builder().build_eframe(|context| TextureCraftApp::new(context, session));
let app = harness.state_mut();
app.session.tool.tool = tool;
let history = app.session.history_labels().len();
if tool == Tool::Paint {
app.session.begin_stroke_uv(Vec2::splat(0.5), 1.0).unwrap();
assert!(app.session.stroke_active());
} else {
assert!(app.session.drag_polygon_fill_box_uv(Vec2::ZERO, Vec2::ONE).unwrap() > 0);
}
app.session.target = StackTarget::Effect(LayerId(u64::MAX));
assert!(!tool_acts(app));
finish_unavailable_tool_gestures(app);
assert!(!app.session.stroke_active());
assert_eq!(app.session.history_labels().len(), history + 1);
assert_eq!(app.session.end_polygon_fill_box(), 0, "the interrupted box is already closed");
finish_unavailable_tool_gestures(app);
assert_eq!(app.session.history_labels().len(), history + 1, "cleanup records the gesture only once");
}
}
#[test]
fn stored_surfaces_release_after_a_frame_without_paths() {
use texturecraft_engine::{core::EffectKind, execute, geom::primitives};
@@ -237,3 +237,34 @@ fn tool_availability_snapshots() {
harness.state_mut().ui.mode = Mode::Rendering;
save(&mut harness, "rendering");
}
#[test]
fn unavailable_effect_tools_hide_their_properties() {
for path in [false, true] {
let mut harness = app_harness();
let session = &mut harness.state_mut().session;
let layer = add_layer(session, "layer.add.paint");
select(session, layer, json!("content"));
let (effect, usable, blocked) = if path {
let result = execute(session, "tool.path", &json!({"uvPoints": [[0.2, 0.5], [0.8, 0.5]], "commit": true})).unwrap();
(result["committed"]["effect"].as_u64().unwrap(), Tool::Path, Tool::Paint)
} else {
execute(session, "mask.add.black", &json!({"layer": layer})).unwrap();
let result = execute(session, "effect.add.paint", &json!({"layer": layer, "target": "mask"})).unwrap();
(result["effect"].as_u64().unwrap(), Tool::Paint, Tool::Smudge)
};
select(session, layer, json!(effect));
session.tool.tool = usable;
harness.run_steps(4);
assert!(shows_text(&harness, "Size"));
harness.state_mut().session.tool.tool = blocked;
harness.run_steps(4);
assert!(!shows_text(&harness, "Size"), "unavailable effect tools hide brush controls");
if let Some(directory) = std::env::var_os("TC_UI_SNAPSHOTS") {
let directory = std::path::PathBuf::from(directory);
std::fs::create_dir_all(&directory).unwrap();
let name = if path { "unavailable-path-effect.png" } else { "unavailable-mask-paint-effect.png" };
harness.render().unwrap().save(directory.join(name)).unwrap();
}
}
}