Abort drags when pressing escape key (#4678)

This is useful to undo a drag-and-drop, for instance
This commit is contained in:
Emil Ernerfeldt 2024-06-19 17:00:10 +02:00 committed by GitHub
parent d9c5fb04ae
commit 8ac1d613fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -27,14 +27,15 @@ impl DragAndDrop {
}
fn end_frame(ctx: &Context) {
let pointer_released = ctx.input(|i| i.pointer.any_released());
let abort_dnd =
ctx.input(|i| i.pointer.any_released() || i.key_pressed(crate::Key::Escape));
let mut is_dragging = false;
ctx.data_mut(|data| {
let state = data.get_temp_mut_or_default::<Self>(Id::NULL);
if pointer_released {
if abort_dnd {
state.payload = None;
}

View File

@ -134,6 +134,12 @@ pub(crate) fn interact(
let mut dragged = prev_snapshot.dragged;
let mut long_touched = None;
if input.key_pressed(Key::Escape) {
// Abort dragging on escape
dragged = None;
interaction.potential_drag_id = None;
}
if input.is_long_touch() {
// We implement "press-and-hold for context menu" on touch screens here
if let Some(widget) = interaction