ui-contract: a bare Tab where it would toggle the panels runs the enabled command the keymap binds to it, when that is not a chrome command: an app command that took Tab from Toggle Panels never ran, as the Tab gate only took chrome commands

This commit is contained in:
bflatastic
2026-11-23 20:27:43 +07:00
parent 157714c25a
commit eb7fe4ff00
3 changed files with 50 additions and 3 deletions
+3
View File
@@ -217,6 +217,9 @@ struct TabPress {
input: KeyInput,
/// An auto-repeat of a key that is still held.
repeat: bool,
/// When and where among the frame's events it arrived, as a [`Shortcut`] has them.
at: Option<f64>,
place: usize,
}
#[derive(Clone)]
+14 -3
View File
@@ -421,7 +421,7 @@ impl Strip<'_> {
true
}
PressUse::Tab => {
batch.tabs.push(TabPress { input: *input, repeat });
batch.tabs.push(TabPress { input: *input, repeat, at, place: batch.place });
false
}
PressUse::CtrlTab => {
@@ -838,8 +838,10 @@ pub fn textless_paste(ctx: &Context) -> bool {
/// Takes the Tab and F6 moves the input hook recorded, for the focus service's begin hook. The pass's root env is
/// installed by now, so a bare Tab that passes the chrome gate and has a chrome command bound to it becomes that
/// command's toggle for the running viewport; any other Tab moves focus. A repeat of a toggling press is dropped: it
/// neither toggles again nor moves focus.
/// command's toggle for the running viewport; one the keymap binds to another enabled command instead (an app command
/// the chrome command yielded the chord to) is that command's press, which the routing hook after this one hands the
/// dispatcher; any other Tab moves focus. A repeat of a toggling or firing press is dropped: it neither acts again nor
/// moves focus.
pub(crate) fn take_nav(ctx: &Context) -> NavKeys {
let (mut nav, tabs) = current(ctx, |stage| {
let mut nav = std::mem::take(&mut stage.batch.nav);
@@ -851,10 +853,19 @@ pub(crate) fn take_nav(ctx: &Context) -> NavKeys {
}
let viewport = crate::runtime::egui::pass::current_viewport(ctx);
let gate = tab_toggles_now(ctx);
let layout = layout_of(ctx);
let fires = |input: &KeyInput| layout.candidates(input).iter().any(|chord| commands::runs_now(ctx, chord));
for press in tabs {
match gate.then(|| chrome_toggle_of(ctx, &press.input)).flatten() {
Some(toggle) if !press.repeat => request_chrome_toggle(ctx, viewport, toggle),
Some(_) => {}
None if gate && fires(&press.input) => {
if !press.repeat {
let TabPress { input, at, place, .. } = press;
let shortcut = Shortcut { input, phase: FirePhase::Press, press: None, canvas: false, at, place };
current(ctx, |stage| stage.batch.shortcuts.push(shortcut));
}
}
None => nav.tabs.push(!press.input.mods.shift),
}
}
@@ -276,3 +276,36 @@ fn a_dialog_opened_in_a_pass_takes_its_escape_after_focus_moved() {
press(&mut frames, &mut show, Key::Escape, Modifiers::NONE);
assert_eq!(cancels.get(), 1, "the dialog opened in the pass takes it");
}
/// A bare Tab that an app command took from Toggle Panels (the window shortcut yields its default chord to the app's
/// binding) runs that command where Tab would toggle the panels, and still moves focus from a text field. Guards
/// against a Tab gate that only took chrome commands, so an app command bound to Tab never ran.
#[trial]
fn tab_runs_the_app_command_bound_to_it_where_it_would_toggle_the_panels() {
use crate::runtime::commands::{AppCatalog, Binding, CommandDef, Scope};
let catalog = Binding::parse("Tab")
.ok()
.and_then(|binding| AppCatalog::new(vec![CommandDef::new("trialTab.dock", "Dock", Scope::app()).with_default(binding)], 1).ok());
assert!(catalog.is_some(), "the trial's catalog is valid");
let mut show = with_canvas;
let mut frames = Frames::new();
frames.root({
let mut root = RootEnv::default();
root.tab_toggles_chrome = true;
root
});
if let Some(catalog) = catalog {
frames.commands(CommandInput::new().catalog(catalog));
}
frames.frame(Vec::new(), &mut show);
take_output(&frames.ctx);
let mut tab = |frames: &mut Frames| {
frames.frame(vec![key_press(Key::Tab, Modifiers::NONE), key_release(Key::Tab, Modifiers::NONE)], &mut show);
let out = take_output(&frames.ctx);
(out.chrome_toggles, out.fired.into_iter().map(|fired| fired.command.id).collect::<Vec<_>>())
};
assert_eq!(tab(&mut frames), (Vec::new(), vec!["trialTab.dock".to_owned()]), "nothing focused: the app's command runs");
assert_eq!(egui_focused(&frames.ctx), None, "and the press moved no focus");
focus_on(&mut frames, &mut with_canvas, "field");
assert!(tab(&mut frames).1.is_empty(), "a text field keeps Tab as its focus move");
}