ui-contract: Shift or Alt with Escape that the keymap binds to an enabled command runs it: the key stage read every Escape without Cmd or Ctrl as the scope's escape, so a command bound to Shift+Escape never ran; a plain Escape keeps its meaning

This commit is contained in:
bflatastic
2026-11-23 21:26:07 +07:00
parent df0b910dcc
commit 46b9fe002d
2 changed files with 34 additions and 2 deletions
+4 -2
View File
@@ -324,8 +324,10 @@ impl Strip<'_> {
let bare_tab = key == Key::Tab && !mods.cmd && !mods.ctrl && !mods.alt;
// Alt and Shift ride along, as with Enter: a canvas tool reads them; Cmd and Ctrl chords are the app's. While
// the focused stop records, Escape with any modifier held is a chord for the recorder; only plain Escape is a
// scope escape. Over an open press any Escape is the press's cancel: a borrowed tool's drag holds Cmd.
let escape = key == Key::Escape && (self.press_captured || (!mods.cmd && !mods.ctrl && !(self.records && !mods.is_none())));
// scope escape. Over an open press any Escape is the press's cancel: a borrowed tool's drag holds Cmd. Shift or
// Alt with Escape that the keymap binds to an enabled command is that command's chord.
let bound = || !mods.is_none() && self.layout.candidates(input).iter().any(|chord| (self.bound)(chord));
let escape = key == Key::Escape && (self.press_captured || (!mods.cmd && !mods.ctrl && !(self.records && !mods.is_none()) && !bound()));
// A shortcut comes before a mnemonic: an Alt+letter the keymap binds to an enabled command runs it. On the
// focused bar a letter without Alt, Ctrl or Cmd is a title's access key, and one no title holds goes nowhere
// (the bar's access mode), so it runs no shortcut either.
@@ -527,6 +527,36 @@ fn an_app_binding_on_f6_beats_the_pane_move() {
assert_eq!(f6_under(Some(unbound)), (true, Vec::new()), "with the pane move unbound, F6 is egui's");
}
/// What a press of Escape with `mods` did with nothing focused, under `overrides`: the window cancels it raised and the
/// ids of the commands it fired.
fn escape_under(overrides: Option<craft_keymap::Overrides>, mods: Modifiers) -> (usize, Vec<String>) {
let (host, mut show) = host_window();
let mut frames = Frames::new();
if let Some(overrides) = overrides {
frames.commands(CommandInput::new().overrides(Arc::new(overrides)));
}
frames.frame(Vec::new(), &mut show);
take_output(&frames.ctx);
seen(&host);
frames.frame(vec![key_press(Key::Escape, mods), key_release(Key::Escape, mods)], &mut show);
frames.frame(Vec::new(), &mut show);
let fired = take_output(&frames.ctx).fired.into_iter().map(|fired| fired.command.id).collect();
(seen(&host).1, fired)
}
/// Tb-8 (3): Shift+Escape bound to a command runs it, as production's keymap ran it under a loaded place cursor; the
/// key stage read every Escape without Cmd or Ctrl as the scope's escape, so the binding never fired. Plain Escape keeps
/// its meaning, and an unbound Shift+Escape is still an escape.
#[trial]
fn a_command_bound_to_shift_escape_runs_and_plain_escape_still_cancels() {
let delete = EditCommands::Delete.id().to_owned();
assert_eq!(escape_under(None, Modifiers::SHIFT), (1, Vec::new()), "an unbound Shift+Escape is the window's Cancel");
let mut bound = craft_keymap::Overrides::default();
bound.insert(EditCommands::Delete.id(), vec!["Shift+Escape".to_owned()]);
assert_eq!(escape_under(Some(bound.clone()), Modifiers::SHIFT), (0, vec![delete]), "the bound Shift+Escape runs its command");
assert_eq!(escape_under(Some(bound), Modifiers::NONE), (1, Vec::new()), "a plain Escape is still the window's Cancel");
}
/// The panes the pane trials show, in order: the scope's name, its stop and its label.
const PANES: [(&str, &str, &str); 2] = [("left pane", "left", "Left"), ("right pane", "right", "Right")];