From ec985c5e59280baba50341f0b09014e1d780a88b Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 18:25:59 -0500 Subject: [PATCH] Leave unused Escape to the window from notices --- crates/ui-widgets/src/notices/notice.rs | 4 ++-- crates/ui-widgets/tests/it/notices.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/ui-widgets/src/notices/notice.rs b/crates/ui-widgets/src/notices/notice.rs index c6775199b9..f84c62142d 100644 --- a/crates/ui-widgets/src/notices/notice.rs +++ b/crates/ui-widgets/src/notices/notice.rs @@ -12,7 +12,7 @@ use crate::primitives::{HAlign, IconSpec, TextRun, Wrap}; use crate::runtime::commands::CommandRef; use crate::runtime::env::{EnvView, Label}; use crate::style::{ComponentStyle, IconLook, Insets, StyleColor, StyleCx, SurfaceKind, SurfaceLook, TextLook, TypeRole, UiTokens}; -use craft_behavior::{Flow, IconId, Intent, Metrics, NavShape, PartKey, Proposal, Roving, Sense}; +use craft_behavior::{Flow, IconId, Metrics, NavShape, PartKey, Proposal, Roving, Sense}; use craft_i18n::Format; use craft_theme::{Rgba, Stateful, States, Variant, variant::Tone}; use egui::{Align, Pos2, Rect, Response, Vec2}; @@ -751,7 +751,7 @@ impl Component for Notice<'_> { } } } - if cx.part_activated(DISMISS).is_some() || (self.dismiss && cx.core.intents.take(Intent::Cancel)) { + if cx.part_activated(DISMISS).is_some() { self.dismissed = true; } } diff --git a/crates/ui-widgets/tests/it/notices.rs b/crates/ui-widgets/tests/it/notices.rs index ac7d737deb..1ae69779ac 100644 --- a/crates/ui-widgets/tests/it/notices.rs +++ b/crates/ui-widgets/tests/it/notices.rs @@ -67,6 +67,27 @@ fn a_notice_reports_its_action_and_dismissal_in_a_frame_that_runs_twice() { assert_eq!(taken.get().1, 1, "the dismissal is reported once"); } +#[trial] +fn escape_on_a_notice_action_reaches_the_window() { + let dismissed = Rc::new(Cell::new(false)); + let cancelled = Rc::new(Cell::new(false)); + let (seen, window) = (dismissed.clone(), cancelled.clone()); + let mut fixture = Fixture::new(move |ui| { + let out = Notice::new(Tone::Info, "Document repaired").dismiss().action(NoticeAction::new("Details")).show(ui); + seen.set(seen.get() || out.dismissed); + craft_ui::runtime::keys::with_window_intents(ui.ctx(), false, |intents| { + let took = intents.take_exact(&craft_behavior::Intent::Cancel); + window.set(window.get() || took); + took + }); + }); + fixture.settle(); + fixture.key(egui::Key::Tab, egui::Modifiers::NONE); + fixture.key(egui::Key::Escape, egui::Modifiers::NONE); + assert!(cancelled.get(), "Escape the notice action leaves reaches the window"); + assert!(!dismissed.get(), "Escape does not press the notice's dismiss button"); +} + /// A centred notice hosts the app's own leaf under its actions: the leaf sits centred under them, and a click on it /// reaches the app through the leaf's output. #[trial]