mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-01 13:47:21 -06:00
Shortcuts: an exact Shift binding for the typed character wins over a plain binding at Shift+Comma or Shift+Period
This commit is contained in:
@@ -731,8 +731,8 @@ fn dispatch(app: &mut VectorcraftApp, ctx: &egui::Context, accept: impl FnMut(&H
|
||||
let mirror = crate::shortcut_editor::current();
|
||||
let dispatcher = &mut app.dispatcher;
|
||||
ctx.input_mut(|i| {
|
||||
// Shift+Comma and Shift+Period follow their key positions when no chord for the
|
||||
// logical press is bound. An explicit shifted logical binding takes precedence.
|
||||
// An explicit shifted logical binding takes precedence. Otherwise, Shift+Comma and
|
||||
// Shift+Period follow their key positions when no chord for the press is bound.
|
||||
for e in &mut i.events {
|
||||
let input = craft_keymap::KeyInput::from_egui(e, crate::keymap::platform());
|
||||
if let egui::Event::Key { key, physical_key: Some(physical), modifiers, pressed: true, .. } = e
|
||||
@@ -749,12 +749,12 @@ fn dispatch(app: &mut VectorcraftApp, ctx: &egui::Context, accept: impl FnMut(&H
|
||||
let mods = craft_keymap::Mods::from_egui(modifiers, crate::keymap::platform());
|
||||
let logical_chord = craft_keymap::Chord::new(mods, logical);
|
||||
let position_chord = craft_keymap::Chord::new(mods, position);
|
||||
if !dispatcher.layout().candidates(&input).iter().any(|chord| crate::keymap::lookup(&mirror.keymap, chord).is_some()) {
|
||||
if crate::keymap::lookup(&mirror.keymap, &logical_chord).is_some() {
|
||||
*physical = *key;
|
||||
} else if crate::keymap::lookup(&mirror.keymap, &position_chord).is_some() {
|
||||
*key = *physical;
|
||||
}
|
||||
if crate::keymap::lookup(&mirror.keymap, &logical_chord).is_some() {
|
||||
*physical = *key;
|
||||
} else if crate::keymap::lookup(&mirror.keymap, &position_chord).is_some()
|
||||
&& !dispatcher.layout().candidates(&input).iter().any(|chord| crate::keymap::lookup(&mirror.keymap, chord).is_some())
|
||||
{
|
||||
*key = *physical;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1251,6 +1251,27 @@ fn resolved_logical_binding_wins_over_position_alias() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_shifted_logical_binding_wins_over_plain_text_binding() {
|
||||
let mut app = remembered_paint_app();
|
||||
crate::keymap::set_override(&mut app.ui.shortcut_overrides, "view.rulers", ";");
|
||||
crate::keymap::set_override(&mut app.ui.shortcut_overrides, "view.grid", "Shift+;");
|
||||
let rulers_before = app.ui.view.rulers;
|
||||
let grid_before = app.ui.view.grid;
|
||||
let journal_before = app.session.journal.len();
|
||||
frame(
|
||||
&mut app,
|
||||
vec![
|
||||
egui::Event::ModifiersChanged(Modifiers::SHIFT),
|
||||
egui::Event::Key { key: Key::Semicolon, physical_key: Some(Key::Comma), pressed: true, repeat: false, modifiers: Modifiers::SHIFT },
|
||||
egui::Event::Text(";".into()),
|
||||
],
|
||||
);
|
||||
assert_eq!(app.ui.view.grid, !grid_before, "Shift+; runs Show Grid");
|
||||
assert_eq!(app.ui.view.rulers, rulers_before, "plain ; does not run Show Rulers");
|
||||
assert!(app.session.journal.since(journal_before).iter().all(|(command, _)| !command.starts_with("paint.")), "the press runs no paint command");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_shifted_punctuation_binding_runs_once() {
|
||||
let mut app = remembered_paint_app();
|
||||
|
||||
Reference in New Issue
Block a user