fix(ui): cancel unfinished polygon on lasso tool switch (#4021)

This commit is contained in:
Nigel Ihza Firdausy authored and GitHub committed 2026-10-12 19:17:25 -04:00
1 parent 67c90e307f
commit fd4ba52f79
2 files changed
+31

No files matched your search

+5
View File
@@ -1056,6 +1056,11 @@ impl PhotocraftApp {
type_transform::cancel_stale(self);
crate::cam_transform::cancel_stale(self);
crate::lasso_ui::cancel_stale(self);
// A polygon under construction belongs to the Polygonal Lasso tool, not the next tool.
if self.ui.tool != Tool::PolygonLasso {
self.ui.polygon.clear();
self.ui.polygon_mode.clear();
}
crate::crop_ui::cancel_stale(self);
let ids: Vec<DocId> = self.session.documents().iter().map(|d| d.doc.id).collect();
// Where the document of view `i` is now. Views not tracked yet keep their index.
+26
View File
@@ -82,6 +82,32 @@ fn near(r: Rect, x0: i32, y0: i32, x1: i32, y1: i32) -> bool {
r.x0.abs_diff(x0) <= 1 && r.y0.abs_diff(y0) <= 1 && r.x1.abs_diff(x1) <= 1 && r.y1.abs_diff(y1) <= 1
}
#[test]
fn switching_tools_discards_unfinished_polygon_without_changing_selection() {
let mut app = polygon_app();
app.run("select.rect", json!({"x": 200, "y": 150, "width": 50, "height": 50})).unwrap();
let before = app.session.active().unwrap().doc.selection.as_ref().unwrap().content_bounds();
let history = app.session.active().unwrap().history.past_len();
ev(&mut app, "down", 20.0, 20.0, Modifiers::NONE);
ev(&mut app, "up", 20.0, 20.0, Modifiers::NONE);
assert_eq!(app.ui.polygon.len(), 1);
assert_eq!(app.ui.polygon_mode, "replace");
assert!(crate::canvas::polygon_replaces_selection(&app));
app.ui.tool = Tool::QuickSelection;
app.sync_views();
assert!(app.ui.polygon.is_empty());
assert!(app.ui.polygon_mode.is_empty());
assert!(!crate::canvas::polygon_replaces_selection(&app));
assert_eq!(app.session.active().unwrap().doc.selection.as_ref().unwrap().content_bounds(), before);
assert_eq!(app.session.active().unwrap().history.past_len(), history);
app.ui.tool = Tool::PolygonLasso;
app.sync_views();
assert!(app.ui.polygon.is_empty(), "returning to the tool must start a fresh outline");
}
#[test]
fn double_click_closes_the_polygon_at_the_last_point() {
let mut h = harness();