Skip to content

Commit

Permalink
fix(chordsv2): preserve release event order
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo committed Sep 19, 2024
1 parent 26fa76b commit a0f1b89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
12 changes: 7 additions & 5 deletions keyberon/src/chord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ impl<'a, T> ChordsV2<'a, T> {
true
}
Event::Release(_, j) => {
if presses.contains(&j) {
return true;
}
// Release the key from active chords.
achs.iter_mut().for_each(|ach| {
if !ach.participating_keys.contains(&j) {
return;
Expand All @@ -297,8 +295,12 @@ impl<'a, T> ChordsV2<'a, T> {
}
}
});
drainq.push_back(*qd);
false
if presses.is_empty() {
drainq.push_back(*qd);
false
} else {
true
}
}
})
}
Expand Down
28 changes: 23 additions & 5 deletions src/tests/sim_tests/chord_sim_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ fn sim_presses_for_old_chord_repress_into_new_chord() {
let result = simulate(
SIMPLE_OVERLAPPING_CHORD_CFG,
"d:a d:b t:50 u:a t:50 d:z t:50 u:b t:50 d:a d:b t:50 u:a t:50",
);
assert_eq!(
"t:50ms\nout:↓C\nt:102ms\nout:↑C\nt:98ms\nout:↓D\nt:10ms\nout:↑D",
result
);
)
.to_ascii();
assert_eq!("t:50ms dn:C t:101ms up:C t:99ms dn:D t:11ms up:D", result);
}

#[test]
Expand Down Expand Up @@ -321,3 +319,23 @@ fn sim_chord_eager_tapholdrelease_activation() {
result
);
}

#[test]
fn sim_chord_release_nonchord_key_has_correct_order() {
let result = simulate(
"
(defcfg concurrent-tap-hold yes)
(defsrc ralt j k)
(deflayer base _ _ _)
(defchordsv2-experimental
(j k) l 75 first-release ()
)
",
"d:ralt t:1000 d:j t:1 u:ralt t:100 u:j t:100",
)
.to_ascii();
assert_eq!(
"t:1ms dn:RAlt t:1075ms dn:J t:1ms up:RAlt t:24ms up:J",
result
);
}

0 comments on commit a0f1b89

Please sign in to comment.