Fix #1229: the Polygonal Lasso tool removes its last vertex on Backspace (follow-up to #1262) (#1338)

* Fix #1229: the Polygonal Lasso tool removes its last vertex on Backspace

Alt-click polygon mode. The Polygonal Lasso tool itself keeps its points
elsewhere (ui.polygon), so there Backspace still reached Edit › Clear and
wiped the layer, the data loss reported in #1229. It now removes the last
vertex there too (Delete as well), a right-click does the same, and
removing the only vertex cancels the polygon.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UHgFEHEsefoQoBParH47JA

* Pipette cursor test: Windows draws the precise crosshair itself

input_tests::eyedropper_and_alt_sampling_show_a_pipette (#1028) expected
the OS crosshair with Other Cursors = Precise, but on Windows the canvas
draws its own crosshair and hides the OS cursor (visible_crosshair), so
the test failed on every Windows run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UHgFEHEsefoQoBParH47JA

---------

Co-authored-by: Claude <[email protected]>
This commit is contained in:
BFlatandClaude Opus 5.5 authored and GitHub committed 2026-10-09 08:07:54 +07:00
1 parent 619095bfd0
commit c4d1c1f8d1
3 files changed
+59 -1

No files matched your search

+18 -1
View File
@@ -2113,7 +2113,12 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
{
crate::canvas_tool_menu::open_transform(app, [p.x, p.y]);
}
let lasso_retracted = tool == Tool::Lasso && response.secondary_clicked() && crate::lasso_ui::undo_last_vertex(app);
let lasso_retracted = response.secondary_clicked()
&& match tool {
Tool::Lasso => crate::lasso_ui::undo_last_vertex(app),
Tool::PolygonLasso => polygon_retract(app),
_ => false,
};
if tool == Tool::Lasso {
crate::lasso_ui::canvas_input(app, &ctx, &xf, &response);
(buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false);
@@ -3310,6 +3315,18 @@ fn polygon_click(app: &mut PhotocraftApp, x: f64, y: f64, mods: egui::Modifiers)
app.ui.polygon.push([x, y]);
}
/// Remove the Polygonal Lasso's last vertex (⌫, Delete or a right-click while drawing, #1229);
/// removing the only one cancels the polygon. False when no polygon is being drawn.
pub fn polygon_retract(app: &mut PhotocraftApp) -> bool {
if app.ui.polygon.pop().is_none() {
return false;
}
if app.ui.polygon.is_empty() {
app.ui.polygon_mode.clear();
}
true
}
/// A new-selection polygonal (or magnetic) lasso is being drawn, so the selection it will replace
/// is hidden.
pub fn polygon_replaces_selection(app: &PhotocraftApp) -> bool {
+32
View File
@@ -286,6 +286,38 @@ fn cmd_drag_inside_the_selection_floats_it_with_the_polygonal_lasso() {
assert_eq!(app.ui.polygon.len(), 1);
}
#[test]
fn backspace_delete_and_right_click_remove_the_last_vertex() {
// #1229: ⌫ took Edit › Clear and wiped the layer while a polygon was being drawn.
let mut h = harness();
for (x, y) in [(50.0, 50.0), (150.0, 50.0), (150.0, 120.0)] {
click(&mut h, x, y, Modifiers::NONE);
// Past egui's double-click window, so each click adds a vertex.
h.run_steps(20);
}
assert_eq!(h.state().ui.polygon.len(), 3);
let st = h.state().session.active().unwrap();
let (layer, steps) = (st.active_layer.unwrap(), st.history.past_len());
for key in [egui::Key::Backspace, egui::Key::Delete] {
h.event(egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
h.run_steps(2);
}
assert_eq!(h.state().ui.polygon.len(), 1);
// A right-click removes the last one and cancels the polygon, without a context menu.
let p = screen(&h, 90.0, 90.0);
h.event(egui::Event::PointerMoved(p));
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE });
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(2);
assert!(h.state().ui.polygon.is_empty() && h.state().ui.polygon_mode.is_empty());
assert!(h.state().ui.canvas_tool_menu.is_none());
let st = h.state().session.active().unwrap();
assert!(st.doc.layer(layer).is_some(), "the layer survives");
assert_eq!(st.history.past_len(), steps, "nothing was edited");
}
/// ⌥ held: a drag draws freehand into the polygon; releasing ⌥ goes back to straight segments,
/// and the polygon stays open (a new selection, even though ⌥ was held at the first click).
#[test]
+9
View File
@@ -316,6 +316,15 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {
return;
}
}
// The Polygonal Lasso tool likewise: ⌫/Delete removes the last vertex (#1229), and never
// reaches Edit › Clear while a polygon is being drawn.
if !app.ui.polygon.is_empty() {
let mods = ctx.input(|i| i.modifiers);
if !mods.command && !mods.ctrl && !mods.shift && ctx.input_mut(|i| i.consume_key(mods, Key::Backspace) || i.consume_key(mods, Key::Delete)) {
crate::canvas::polygon_retract(app);
return;
}
}
// Inline type editing eats text and navigation keys; ⌘-shortcuts still reach the menus.
let editing = crate::type_tool::handle_keys(app, ctx);
// Registry, UI and menu-catalogue shortcuts (see [`crate::shortcut_dispatch::bindings`]).