Consume escape keystroke when bailing out from a drag operation (#5433)

This commit is contained in:
Antoine Beyeler 2024-12-04 17:35:24 +01:00 committed by GitHub
parent cf513d215c
commit f687b27efc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 9 deletions

View File

@ -23,22 +23,30 @@ pub struct DragAndDrop {
impl DragAndDrop {
pub(crate) fn register(ctx: &Context) {
ctx.on_end_pass("debug_text", std::sync::Arc::new(Self::end_pass));
ctx.on_begin_pass("drag_and_drop_begin_pass", Arc::new(Self::begin_pass));
ctx.on_end_pass("drag_and_drop_end_pass", Arc::new(Self::end_pass));
}
fn begin_pass(ctx: &Context) {
let has_any_payload = Self::has_any_payload(ctx);
if has_any_payload {
let abort_dnd = ctx.input_mut(|i| {
i.pointer.any_released()
|| i.consume_key(crate::Modifiers::NONE, crate::Key::Escape)
});
if abort_dnd {
Self::clear_payload(ctx);
}
}
}
fn end_pass(ctx: &Context) {
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 abort_dnd {
state.payload = None;
}
is_dragging = state.payload.is_some();
});