Fix the Gradient tool breaking the layer deletion hotkey (#4224)

* Fix the Gradient tool breaking the layer deletion hotkey

* Fix
This commit is contained in:
Keavon Chambers
2026-06-10 22:32:39 -07:00
committed by GitHub
parent f658665d4a
commit 97324cd852

View File

@@ -192,14 +192,22 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for Grad
}
}
advertise_actions!(GradientToolMessageDiscriminant;
PointerDown,
PointerUp,
PointerMove,
DoubleClick,
Abort,
DeleteStop,
);
fn actions(&self) -> ActionList {
let mut common = actions!(GradientToolMessageDiscriminant;
PointerDown,
PointerUp,
PointerMove,
DoubleClick,
Abort,
);
// Only intercept Delete/Backspace (`DeleteStop`) while a deletable stop or midpoint is selected
if self.data.selected_gradient.as_ref().is_some_and(|selected| !matches!(selected.dragging, GradientDragTarget::New)) {
common.extend(actions!(GradientToolMessageDiscriminant; DeleteStop));
}
common
}
}
impl LayoutHolder for GradientTool {
@@ -2327,6 +2335,36 @@ mod test_gradient {
assert!(!final_positions.iter().any(|pos| (pos - 0.75).abs() < 0.05), "Stop at position 0.75 should have been deleted");
}
#[tokio::test]
async fn delete_removes_layer_when_no_stop_selected() {
let mut editor = EditorTestUtils::create();
editor.new_document().await;
// Create a layer and switch to the Gradient tool without engaging any gradient handle
editor.drag_tool(ToolType::Rectangle, -5., -3., 100., 100., ModifierKeys::empty()).await;
editor.select_tool(ToolType::Gradient).await;
assert_eq!(editor.active_document().metadata().all_layers().count(), 1, "Expected the rectangle layer to exist");
// With no color stop selected, Delete should fall through to deleting the selected layer
editor.press(Key::Delete, ModifierKeys::empty()).await;
assert_eq!(editor.active_document().metadata().all_layers().count(), 0, "Expected the layer to be deleted");
}
#[tokio::test]
async fn delete_removes_layer_after_drawing_gradient() {
let mut editor = EditorTestUtils::create();
editor.new_document().await;
// Draw a fresh gradient, which leaves `selected_gradient` set to the `New` drag target rather than a selected stop
editor.drag_tool(ToolType::Rectangle, -5., -3., 100., 100., ModifierKeys::empty()).await;
editor.drag_tool(ToolType::Gradient, 0., 0., 100., 0., ModifierKeys::empty()).await;
assert_eq!(editor.active_document().metadata().all_layers().count(), 1, "Expected the rectangle layer to exist");
// Since no stop is selected (`New` isn't a deletable handle), Delete should still delete the layer
editor.press(Key::Delete, ModifierKeys::empty()).await;
assert_eq!(editor.active_document().metadata().all_layers().count(), 0, "Expected the layer to be deleted after drawing a gradient");
}
#[tokio::test]
async fn change_spread_method() {
use graphene_std::vector::style::GradientSpreadMethod;