mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 18:27:00 +01:00
keys: a focused canvas's untaken Enter reaches the window's intents, as its Escape does
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1a55a2f92c
commit
cbbfa814d4
2 files changed
+43
-16
No files matched your search
@@ -1923,8 +1923,8 @@ fn a_drag_held_in_the_band_inside_the_canvas_edge_scrolls_the_view() {
|
||||
}
|
||||
|
||||
/// A canvas whose app reads the window's intents after the tool host, last in its UI: returns the fixture and how many
|
||||
/// Cancels the window took.
|
||||
fn window_reading_canvas(tool: impl CanvasTool + 'static) -> (Fixture, Rc<Cell<u32>>) {
|
||||
/// of `intent` the window took.
|
||||
fn window_reading_canvas(tool: impl CanvasTool + 'static, intent: craft_behavior::Intent) -> (Fixture, Rc<Cell<u32>>) {
|
||||
let tool = RefCell::new(tool);
|
||||
let cancels = Rc::new(Cell::new(0));
|
||||
let seen = Rc::clone(&cancels);
|
||||
@@ -1936,7 +1936,7 @@ fn window_reading_canvas(tool: impl CanvasTool + 'static) -> (Fixture, Rc<Cell<u
|
||||
}
|
||||
});
|
||||
craft_ui::runtime::keys::with_window_intents(ui.ctx(), false, |window| {
|
||||
let took = window.take(craft_behavior::Intent::Cancel);
|
||||
let took = window.take(intent.clone());
|
||||
seen.set(seen.get() + u32::from(took));
|
||||
took
|
||||
});
|
||||
@@ -1950,8 +1950,9 @@ fn window_reading_canvas(tool: impl CanvasTool + 'static) -> (Fixture, Rc<Cell<u
|
||||
#[trial]
|
||||
fn a_focused_canvas_leaves_the_cancel_no_tool_took_to_the_window() {
|
||||
for takes in [false, true] {
|
||||
let cancel = craft_behavior::Intent::Cancel;
|
||||
let (mut fixture, cancels) =
|
||||
if takes { window_reading_canvas(Recorder::default()) } else { window_reading_canvas(Probe::new("main", &Log::default())) };
|
||||
if takes { window_reading_canvas(Recorder::default(), cancel) } else { window_reading_canvas(Probe::new("main", &Log::default()), cancel) };
|
||||
let canvas = fixture.by_role(Role::CANVAS).remove(0);
|
||||
fixture.click(&canvas).settle();
|
||||
cancels.set(0);
|
||||
@@ -1961,6 +1962,23 @@ fn a_focused_canvas_leaves_the_cancel_no_tool_took_to_the_window() {
|
||||
}
|
||||
}
|
||||
|
||||
/// On a canvas focused by a click, a plain Enter the tool does not take reaches the window's intents once, as its
|
||||
/// Escape does, and one the tool takes does not: the page around the canvas acts on the Enter its tool leaves.
|
||||
#[trial]
|
||||
fn a_focused_canvas_leaves_the_submit_no_tool_took_to_the_window() {
|
||||
for takes in [false, true] {
|
||||
let submit = craft_behavior::Intent::Submit;
|
||||
let (mut fixture, submits) =
|
||||
if takes { window_reading_canvas(Recorder::default(), submit) } else { window_reading_canvas(Probe::new("main", &Log::default()), submit) };
|
||||
let canvas = fixture.by_role(Role::CANVAS).remove(0);
|
||||
fixture.click(&canvas).settle();
|
||||
submits.set(0);
|
||||
fixture.frame(vec![key_press(Key::Enter, Modifiers::NONE)]).settle();
|
||||
let want = if takes { 0 } else { 1 };
|
||||
assert_eq!(submits.get(), want, "the window sees the Enter only when the tool leaves it (tool takes it: {takes})");
|
||||
}
|
||||
}
|
||||
|
||||
/// A tool that records whether its context shows the precise cursor, in each pass.
|
||||
struct PreciseProbe(Rc<Cell<Option<bool>>>);
|
||||
|
||||
|
||||
@@ -317,7 +317,8 @@ pub fn intents_of(ctx: &Context, id: Option<Id>, rtl: bool) -> Intents {
|
||||
///
|
||||
/// The window's intents are the keys the runtime routes to no component this pass: an Escape (`Intent::Cancel`)
|
||||
/// or a plain Enter (`Intent::Submit`) while no framework stop is focused, and the arrows' nudge; with a framework
|
||||
/// stop focused, its unused Escape, unless it is a text field. A component or a
|
||||
/// stop focused, its unused Escape, unless it is a text field, and, with a canvas or a control in it focused, its unused
|
||||
/// Enter. A component or a
|
||||
/// scope that runs earlier in the pass takes them first (an open dialog takes the Escape that closes it, a canvas
|
||||
/// session the one that ends it), so an app that hosts the runtime reads them last in its UI to see what no
|
||||
/// component took. `rtl` reads horizontal moves in the window's direction.
|
||||
@@ -339,19 +340,27 @@ fn offer_window_intents(ctx: &Context, rtl: bool, take: impl FnOnce(&mut Intents
|
||||
// palette; the document's editor and a canvas control lend it as any other control does.
|
||||
let focused = focus::focused_rec(ctx)
|
||||
.filter(|rec| rec.stop.keys.owner != OwnerClass::Text || rec.stop.keys.is_document_editor() || focus::is_canvas_member(ctx, rec))
|
||||
.map(|rec| rec.stop.id);
|
||||
.map(|rec| (rec.stop.id, rec.stop.keys.chrome_key || focus::is_canvas_member(ctx, &rec)));
|
||||
let mut window = intents_of(ctx, None, rtl);
|
||||
// The focused stop's leftover Escape stays in its slot until taken.
|
||||
let lent_cancel =
|
||||
focused.filter(|id| !window.items.iter().any(|(item, _)| *item == Intent::Cancel) && holds(ctx, Some(*id), &Intent::Cancel)).map(|id| {
|
||||
window.items.push((Intent::Cancel, false));
|
||||
(id, window.items.len() - 1)
|
||||
});
|
||||
// The focused stop's leftover Escape, and a focused canvas's leftover Enter, stay in its slot until taken: a canvas
|
||||
// routes Enter to its tool and leaves the rest to the scopes around it, as it does Escape.
|
||||
let mut lent = Vec::new();
|
||||
if let Some((id, canvas)) = focused {
|
||||
for intent in [Intent::Cancel, Intent::Submit] {
|
||||
if (intent == Intent::Cancel || canvas) && !window.items.iter().any(|(item, _)| *item == intent) && holds(ctx, Some(id), &intent) {
|
||||
window.items.push((intent.clone(), false));
|
||||
lent.push((intent, window.items.len() - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
let taken = take(&mut window);
|
||||
if let Some((id, at)) = lent_cancel {
|
||||
let (_, cancel_taken) = window.items.remove(at);
|
||||
if cancel_taken && !crate::runtime::measure::active(ctx) {
|
||||
current(ctx, |stage| take_from(stage, Some(id), &Intent::Cancel));
|
||||
for (intent, at) in lent.into_iter().rev() {
|
||||
let (_, lent_taken) = window.items.remove(at);
|
||||
if lent_taken
|
||||
&& !crate::runtime::measure::active(ctx)
|
||||
&& let Some((id, _)) = focused
|
||||
{
|
||||
current(ctx, |stage| take_from(stage, Some(id), &intent));
|
||||
}
|
||||
}
|
||||
if taken {
|
||||
|
||||
Reference in new issue
Block a user