mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 04:04:25 +00:00
Key stage: a canvas tool's state-dependent claims hold while a non-text member of the canvas's arena (a frame part) is focused
This commit is contained in:
@@ -72,6 +72,9 @@ pub(crate) struct FocusedRecord {
|
||||
pub(crate) claims: Vec<craft_keymap::Chord>,
|
||||
/// The component of the focused stop: only its state-dependent claims hold.
|
||||
pub(crate) focused: Option<Id>,
|
||||
/// The arena root of the focused stop when the stop is a non-text member of an arena (a part of a canvas's frame
|
||||
/// overlay): the root's state-dependent claims hold too, so a canvas tool's keys work with a part focused.
|
||||
pub(crate) root: Option<Id>,
|
||||
/// The focused stop switches pages with Ctrl+Tab.
|
||||
pub(crate) pages: bool,
|
||||
pub(crate) menu_bar: bool,
|
||||
|
||||
@@ -678,6 +678,7 @@ pub(super) fn end(state: &mut State, focused: Option<Id>, on_app_widget: bool, f
|
||||
state.record = super::FocusedRecord {
|
||||
claims: keys.map(|keys| keys.claims.to_vec()).unwrap_or_default(),
|
||||
focused: stop.as_ref().map(|stop| stop.id),
|
||||
root: stop.as_ref().filter(|stop| stop.root != stop.id && !stop.text).map(|stop| stop.root),
|
||||
pages: stop.as_ref().is_some_and(|stop| stop.role.pages),
|
||||
keys,
|
||||
menu_bar: std::mem::take(&mut state.menu_bar),
|
||||
|
||||
@@ -344,7 +344,7 @@ enum PressUse {
|
||||
/// bare End where it declares `EndKey::EndMode`.
|
||||
pub(super) fn focused_claims(record: &focus::FocusedRecord, stage: &Stage) -> Vec<Chord> {
|
||||
let mut claims = record.claims.clone();
|
||||
claims.extend(stage.claims.iter().filter(|(owner, _)| Some(*owner) == record.focused).map(|(_, chord)| *chord));
|
||||
claims.extend(stage.claims.iter().filter(|(owner, _)| Some(*owner) == record.focused || Some(*owner) == record.root).map(|(_, chord)| *chord));
|
||||
// A bare End belongs to a stop that declares `EndKey::EndMode`: it reads the key as a claimed chord and toggles its
|
||||
// mode, so no collection navigation or scroll owner takes it as a move to the end.
|
||||
if record.keys.is_some_and(|keys| keys.end == EndKey::EndMode) {
|
||||
|
||||
@@ -22,15 +22,15 @@ use std::sync::Arc;
|
||||
pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
|
||||
let os = crate::runtime::windows::os_of(ctx);
|
||||
let target = focus::focused_rec(ctx);
|
||||
let (batch, nodes, captures) = current(ctx, |stage| {
|
||||
let (batch, nodes, captures, held_claims) = current(ctx, |stage| {
|
||||
stage.routed.clear();
|
||||
stage.contexts.clear();
|
||||
stage.claimed.clear();
|
||||
stage.activated.clear();
|
||||
stage.claims.clear();
|
||||
let held_claims = std::mem::take(&mut stage.claims);
|
||||
stage.last_open_edits = std::mem::take(&mut stage.open_edits);
|
||||
stage.last_nodes = std::mem::take(&mut stage.nodes);
|
||||
(std::mem::take(&mut stage.batch), stage.last_nodes.clone(), std::mem::take(&mut stage.captures))
|
||||
(std::mem::take(&mut stage.batch), stage.last_nodes.clone(), std::mem::take(&mut stage.captures), held_claims)
|
||||
});
|
||||
let modal = overlay::any_open(ctx, overlay::OpenFilter::Modal);
|
||||
let stale_repeat = |stale: &mut bool, press: &Press| {
|
||||
@@ -96,6 +96,7 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
|
||||
}
|
||||
}
|
||||
let focused = target.as_ref().map(|rec| rec.stop.id);
|
||||
let root = target.as_ref().filter(|rec| rec.stop.root != rec.stop.id && !rec.stop.text).map(|rec| rec.stop.root);
|
||||
// The web sends a chord's key press and its clipboard event: the command reaches the component once.
|
||||
let mut clips = batch.clips.clone();
|
||||
clips.dedup();
|
||||
@@ -125,7 +126,12 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
|
||||
for chord in &batch.claimed {
|
||||
match driven.and_then(|driven| driven.intent_of(chord)) {
|
||||
Some(intent) => push(&mut routed, driven.map(|driven| driven.list), intent, false),
|
||||
None => claimed.extend(captures.iter().find(|(_, held)| held == chord).map(|(owner, _)| *owner).or(focused).map(|id| (id, *chord))),
|
||||
None => {
|
||||
// A capture's owner, else the claim's: the focused component's own, then its arena root's.
|
||||
let held = |owner: Option<Id>| held_claims.iter().find(|(id, held)| Some(*id) == owner && held == chord).map(|(id, _)| *id);
|
||||
let owner = captures.iter().find(|(_, held)| held == chord).map(|(owner, _)| *owner);
|
||||
claimed.extend(owner.or_else(|| held(focused)).or_else(|| held(root)).or(focused).map(|id| (id, *chord)));
|
||||
}
|
||||
}
|
||||
}
|
||||
for request in &batch.access {
|
||||
|
||||
Reference in New Issue
Block a user