mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
Suites leave out changes made by keys lent to a canvas session control
The key stage counts the lent keys session members take (keys::lent_taken). The activation and drive suites read it around their input: a key the canvas lent its session control is that control's, with no AccessKit twin on the focused stop.
This commit is contained in:
@@ -36,7 +36,9 @@ pub use intents::settle;
|
||||
pub use intents::take_submit;
|
||||
#[doc(hidden)]
|
||||
pub use intents::with_window_intents;
|
||||
pub(crate) use intents::{Lent, context_request, give_back, lend, request_context, route_whole_reset, scope_escape, take_cancel, take_window_cancel};
|
||||
pub(crate) use intents::{
|
||||
Lent, context_request, give_back, lend, lent_taken, request_context, route_whole_reset, scope_escape, take_cancel, take_window_cancel,
|
||||
};
|
||||
pub(crate) use nodes::{redirect_node, register_expanded, register_node};
|
||||
pub(crate) use route::{activated_member, begin, layout_of, pasted_text, queue_activate, queue_edit, take_shortcuts};
|
||||
|
||||
@@ -205,6 +207,8 @@ pub(crate) struct Stage {
|
||||
modal_open: bool,
|
||||
/// The held Enter began before the open modal layer: its repeats reach nobody until a fresh press.
|
||||
enter_stale: bool,
|
||||
/// How many lent keys session members have taken (`lend`), counted over the viewport's life.
|
||||
lent_taken: u64,
|
||||
}
|
||||
|
||||
fn with<R>(ctx: &Context, viewport: ViewportId, f: impl FnOnce(&mut Stage) -> R) -> R {
|
||||
|
||||
@@ -338,12 +338,15 @@ pub(crate) fn give_back(ctx: &Context, to: Id, lent: Lent) {
|
||||
current(ctx, |stage| {
|
||||
let Some(own) = stage.routed.get_mut(&Some(to)) else { return };
|
||||
let mut back = Vec::new();
|
||||
let lent_items = lent.items.len();
|
||||
for (from, intent) in lent.items {
|
||||
if let Some(at) = own.items.iter().position(|item| item.intent == intent) {
|
||||
back.push((from, own.items.remove(at)));
|
||||
}
|
||||
}
|
||||
let nudge = lent.nudge.and_then(|from| own.nudge.take().map(|nudge| (from, nudge)));
|
||||
let taken = lent_items - back.len() + usize::from(lent.nudge.is_some() && nudge.is_none());
|
||||
stage.lent_taken += taken as u64;
|
||||
for (from, item) in back {
|
||||
stage.routed.entry(from).or_default().items.push(item);
|
||||
}
|
||||
@@ -353,6 +356,12 @@ pub(crate) fn give_back(ctx: &Context, to: Id, lent: Lent) {
|
||||
});
|
||||
}
|
||||
|
||||
/// How many lent keys session members have taken so far in the current viewport: a check of keyboard parity reads
|
||||
/// it before and after its input, since a lent key is the session control's, not the focused component's.
|
||||
pub(crate) fn lent_taken(ctx: &Context) -> u64 {
|
||||
current(ctx, |stage| stage.lent_taken)
|
||||
}
|
||||
|
||||
/// Takes the window's untaken `Cancel` (Escape) while nothing has focus.
|
||||
pub(crate) fn take_window_cancel(ctx: &Context) -> bool {
|
||||
with_window_intents(ctx, false, |window| window.take(Intent::Cancel))
|
||||
|
||||
@@ -204,8 +204,11 @@ fn every_intent_has_a_declared_action(subject: &Subject) -> Result<(), String> {
|
||||
let focus_before = fixture.tree().focused_key();
|
||||
let number = |tree: &AccessTree| tree.numeric_of(focus_before).and_then(|numeric| numeric.value);
|
||||
let number_before = number(fixture.tree());
|
||||
let lent_before = crate::runtime::keys::lent_taken(fixture.ctx());
|
||||
fixture.key(key, Modifiers::NONE);
|
||||
fixture.settle();
|
||||
// A key the canvas lent its session control (a crop frame) is that control's, not the focused stop's.
|
||||
let lent = crate::runtime::keys::lent_taken(fixture.ctx()) != lent_before;
|
||||
// The step the key took, from the focused node's number: an arrow's meaning is the control's own.
|
||||
let step = step.map(|by_key| match (number_before, number(fixture.tree())) {
|
||||
(Some(before), Some(after)) if after > before => Declared::Increment,
|
||||
@@ -214,7 +217,7 @@ fn every_intent_has_a_declared_action(subject: &Subject) -> Result<(), String> {
|
||||
});
|
||||
let could_step = step.is_some_and(|step| if step == Declared::Increment { steps_before.0 } else { steps_before.1 });
|
||||
let clicked = fixture.take_outputs().iter().any(|output| output.clicked);
|
||||
let changed = !fixture.data().changed_since(&before).is_empty();
|
||||
let changed = !lent && !fixture.data().changed_since(&before).is_empty();
|
||||
let radios = fixture.tree().with_role(Role::RADIO_BUTTON);
|
||||
let tree = fixture.tree();
|
||||
let roving =
|
||||
|
||||
@@ -286,7 +286,10 @@ fn runs_of(story: &Story, probe: &Probe, plan: Plan) -> Runs {
|
||||
let mut fixture = input_fixture(story);
|
||||
let before = fixture.data().snapshot();
|
||||
fixture.take_outputs();
|
||||
let lent_before = crate::runtime::keys::lent_taken(fixture.ctx());
|
||||
run(&mut fixture, plan, variant);
|
||||
// A key the canvas lent its session control is that control's: it has no AccessKit twin on the focused stop.
|
||||
let lent = crate::runtime::keys::lent_taken(fixture.ctx()) != lent_before;
|
||||
let changed = !fixture.data().changed_since(&before).is_empty();
|
||||
let kinds: Vec<EditKind> = fixture.take_outputs().into_iter().flat_map(|output| output.edits).collect();
|
||||
let name = variant_name(plan, variant);
|
||||
@@ -297,6 +300,9 @@ fn runs_of(story: &Story, probe: &Probe, plan: Plan) -> Runs {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if lent {
|
||||
continue;
|
||||
}
|
||||
if !changed {
|
||||
unchanged_by.push(name);
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user