mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
fwstub-1: keymap rule 3 exception (lead ruling): with Shift held, a binding of the Shift-kept chord runs before the Shift-dropped one (German Ctrl+Shift+0 runs Ctrl+Shift+= Superscript, not Ctrl+= Subscript); recording, candidates and matches keep rule 3; layout docs; test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e162b30930
commit
01dee65d91
3 files changed
+39
-7
No files matched your search
@@ -13,7 +13,13 @@
|
||||
//! without Shift). A digit-row press that types punctuation also matches its position's digit,
|
||||
//! after the punctuation: AZERTY's `-` key runs Ctrl+- and, when that has no binding, Ctrl+6.
|
||||
//! 3. **Punctuation:** the character typed, without Shift when the layout needs Shift for it
|
||||
//! (German `/` is ⇧7, so ⇧⌘7 is ⌘/; US `:` is ⇧;, so ⇧; is `:`). A Shift binding on a US
|
||||
//! (German `/` is ⇧7, so ⇧⌘7 is ⌘/; US `:` is ⇧;, so ⇧; is `:`). One exception, for the
|
||||
//! command a press runs (lead ruling, [`Matcher`](crate::Matcher)): when the person held Shift
|
||||
//! and the keymap binds the chord with Shift kept, that binding wins over the Shift-dropped
|
||||
//! chord's; on a layout where `=` is ⇧0, Ctrl+Shift+0 runs Ctrl+Shift+= (Word's Superscript),
|
||||
//! not Ctrl+= (Subscript), and Ctrl+= only when Ctrl+Shift+= is unbound. Recording
|
||||
//! ([`Layout::resolve`]), [`Layout::candidates`] and [`Layout::matches`] keep rule 3. A Shift
|
||||
//! binding on a US
|
||||
//! base key also matches the same press (`Shift+;` matches `:`), and `=` and `+` stand for
|
||||
//! each other so zoom keys work with and without Shift. egui has no key for the characters the
|
||||
//! ISO key next to left Shift types (`<` and `>` on Turkish Q) and reports both as that key,
|
||||
|
||||
@@ -119,15 +119,23 @@ struct Match<'a> {
|
||||
accept: &'a dyn Fn(&CommandRef) -> bool,
|
||||
}
|
||||
|
||||
/// The chords one press can run, most specific first: the layout's candidates, then Delete and Backspace standing
|
||||
/// for each other.
|
||||
struct Chords(Vec<Chord>);
|
||||
/// The chords one press can run, most specific first: the chord with the Shift the layout dropped kept (rule 3's
|
||||
/// exception), the layout's candidates, then Delete and Backspace standing for each other.
|
||||
struct Chords(Vec<Chord>, Chord);
|
||||
|
||||
impl Chords {
|
||||
/// `None` when the press names no key.
|
||||
fn of(layout: &Layout, input: &KeyInput) -> Option<Chords> {
|
||||
let mut chords = layout.candidates(input);
|
||||
chords.first()?;
|
||||
let meant = chords.first().copied()?;
|
||||
// Rule 3's exception (`layout` docs): where the layout dropped the Shift the person held for a symbol that
|
||||
// needs it, the chord with Shift kept is tried first, so its binding wins over the dropped chord's. The press
|
||||
// still means the dropped chord (a double press, `Hit::exact`).
|
||||
if input.mods.shift && !meant.mods.shift && meant.key.is_symbol() {
|
||||
let kept = Chord::new(input.mods, meant.key);
|
||||
chords.retain(|chord| *chord != kept);
|
||||
chords.insert(0, kept);
|
||||
}
|
||||
let twins: Vec<Chord> = chords
|
||||
.iter()
|
||||
.filter_map(|c| match c.key {
|
||||
@@ -137,12 +145,12 @@ impl Chords {
|
||||
})
|
||||
.collect();
|
||||
chords.extend(twins);
|
||||
Some(Chords(chords))
|
||||
Some(Chords(chords, meant))
|
||||
}
|
||||
|
||||
/// The chord the press means ([`Layout::resolve`]).
|
||||
fn first(&self) -> Chord {
|
||||
self.0[0]
|
||||
self.1
|
||||
}
|
||||
|
||||
/// The first chord with a binding, pressed twice when `double`.
|
||||
|
||||
@@ -217,3 +217,21 @@ fn a_refused_command_leaves_its_chord_to_the_next_binding() {
|
||||
let all = Matcher::new().press(&Layout::new(), &km, &press).map(|hit| hit.command);
|
||||
assert_eq!(all, Some(cmd("view.zoomIn")), "a plain press accepts every command");
|
||||
}
|
||||
|
||||
/// Rule 3's exception (lead ruling): on a layout where `=` is ⇧0 (German), Ctrl+Shift+0 types `=` with Shift held.
|
||||
/// Rule 3 reads it as Ctrl+=, but when the keymap binds Ctrl+Shift+= that binding runs (Word's Superscript, not
|
||||
/// Subscript), as the old app did; with Ctrl+Shift+= unbound the press is Ctrl+= as before. The layout's own reading,
|
||||
/// which recording and claims use, keeps rule 3.
|
||||
#[test]
|
||||
fn a_held_shift_runs_the_shift_kept_binding_before_rule_3_drops_it() {
|
||||
let shift_zero = KeyInput::new(Mods { cmd: true, ctrl: false, alt: false, shift: true }).with_typed(Key::Equals).with_physical(Key::Num0);
|
||||
let ran = |defs: Vec<CommandDef>| {
|
||||
let km = Keymap::new(defs, Scopes::new(), Platform::Linux);
|
||||
let press = Press { input: &shift_zero, repeat: false, now: 0.0, active: &Active::NONE, outer: &[] };
|
||||
Matcher::new().press(&Layout::new(), &km, &press).map(|hit| hit.command)
|
||||
};
|
||||
let both = vec![app("format.subscript", &["Cmd+="]), app("format.superscript", &["Cmd+Shift+="])];
|
||||
assert_eq!(ran(both), Some(cmd("format.superscript")), "the Shift-kept binding wins");
|
||||
assert_eq!(ran(vec![app("format.subscript", &["Cmd+="])]), Some(cmd("format.subscript")), "unbound, rule 3 holds");
|
||||
assert_eq!(Layout::new().resolve(&shift_zero), Some(chord("Cmd+=")), "the press is still recorded as rule 3 reads it");
|
||||
}
|
||||
Reference in new issue
Block a user