Skip to content

Commit

Permalink
Consume escape keystroke when bailing out from a drag operation (#5433)
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 authored Dec 4, 2024
1 parent cf513d2 commit f687b27
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions crates/egui/src/drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 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;
fn begin_pass(ctx: &Context) {
let has_any_payload = Self::has_any_payload(ctx);

ctx.data_mut(|data| {
let state = data.get_temp_mut_or_default::<Self>(Id::NULL);
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 {
state.payload = None;
Self::clear_payload(ctx);
}
}
}

fn end_pass(ctx: &Context) {
let mut is_dragging = false;

ctx.data_mut(|data| {
let state = data.get_temp_mut_or_default::<Self>(Id::NULL);
is_dragging = state.payload.is_some();
});

Expand Down

0 comments on commit f687b27

Please sign in to comment.