From 7791d7324cbb0960949fae8f25bebcf33e3bb23c Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Fri, 4 Dec 2026 11:32:10 +0530 Subject: [PATCH] fix(ui): drop Enter before the runtime routes it while Revert asks The UI runtime's input hook routes Enter to the shared question's accepting answer before any app code runs in the pass, so consuming the key in the dialog's show() came too late and Enter answered Revert. The raw input hook now drops Enter while the Revert question is open. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/app.rs | 7 ++++--- crates/ui-egui/src/panels/unsaved.rs | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index d08a10f1f..11ec38b31 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -178,9 +178,9 @@ impl eframe::App for EffectcraftApp { } /// Hand the runtime this frame's root values (`before_input`), then feed pending synthetic input into `raw_input` - /// only once fonts are ready (so a non-drawing pass never consumes - /// a batch), then prepare pointer wrapping; ending a numeric scrub clears the history merge key so the next edit - /// starts a new undo step. + /// only once fonts are ready (so a non-drawing pass never consumes a batch), drop Enter while the Revert question is + /// open, then prepare pointer wrapping; ending a numeric scrub clears the history merge key so the next edit starts + /// a new undo step. fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) { self.before_input(ctx); raw_input.events.append(&mut self.forwarded.events); @@ -193,6 +193,7 @@ impl eframe::App for EffectcraftApp { if self.fonts_ready { self.feed_synthetic(raw_input); } + crate::panels::unsaved::hold_back_enter(self, raw_input); crate::menus::hold_mini_flowchart_keys(self, ctx, raw_input); if pointer_wrap::prepare_input(ctx, raw_input, injected) { self.session.history.merge_key = None; diff --git a/crates/ui-egui/src/panels/unsaved.rs b/crates/ui-egui/src/panels/unsaved.rs index 6b6975705..d120a4988 100644 --- a/crates/ui-egui/src/panels/unsaved.rs +++ b/crates/ui-egui/src/panels/unsaved.rs @@ -106,6 +106,16 @@ pub(crate) fn is_revert(app: &EffectcraftApp) -> bool { app.dialog_state.unsaved.command.as_ref().is_some_and(|(id, _)| id == "file.revert") } +/// Revert discards work, so Enter must not answer it: while the Revert question is open, the frame's Enter presses are +/// dropped from `raw` before the pass. The shared question takes Enter as its accepting answer (Revert), and the UI +/// runtime's input hook routes the key to it before any of EffectCraft's code runs in the pass, so the key has to go +/// here, in `App::raw_input_hook`, ahead of that hook. +pub(crate) fn hold_back_enter(app: &EffectcraftApp, raw: &mut egui::RawInput) { + if app.dialog == Some(Dialog::UnsavedChanges) && is_revert(app) { + raw.events.retain(|event| !matches!(event, egui::Event::Key { key: egui::Key::Enter, .. })); + } +} + /// The shared question for the waiting command: Quit asks before quitting, Revert asks to discard, the rest before /// closing. fn question(app: &EffectcraftApp) -> UnsavedChangesDialog { @@ -125,11 +135,6 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { app.dialog = None; return; } - // Revert discards work: Enter must not answer it. The shared question takes Enter as Revert at this craft-libs pin; - // this runs before the dialog host in the same pass, so the host never sees the key. - if is_revert(app) { - ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Enter)); - } match app.framework_dialogs.take::() { Some(DialogResult::Ok(a)) => answer_with(app, ctx, a.answer), Some(_) => answer_with(app, ctx, CloseAnswer::Cancel), @@ -217,6 +222,8 @@ mod tests { raw.events.push(egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }); raw.events.push(egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers }); } + // `App::raw_input_hook`'s part, before the runtime's input hook. + hold_back_enter(app, &mut raw); let mut out = ctx.run_ui(raw, |ui| { app.auto.begin_frame(); crate::panels::dialogs::show(app, ui.ctx());