Skip to content

Commit

Permalink
fix(chordsv2): remove old code causing dup activations
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo committed Jan 25, 2025
1 parent bc55298 commit 6f9c54d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
21 changes: 0 additions & 21 deletions keyberon/src/chord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,20 +368,6 @@ impl<'a, T> ChordsV2<'a, T> {
chord_candidates.retain(|chc| chc.participating_keys.contains(&press));
for chc in chord_candidates.iter() {
min_timeout = std::cmp::min(min_timeout, chc.pending_duration);
if chc.pending_duration <= since
&& chc
.participating_keys
.iter()
.all(|pk| accumulated_presses.contains(pk))
{
// Invariant:
// This should only happen at most once per iteration
// due to needing an exact match with accumulated presses.
// Later iterations are "better" choices
// if more than one timed_out_chord is found,
// because they consume more presses.
timed_out_chord = Some((chc, accumulated_presses.len() as u8));
}
}
chord_candidates.len()
} else {
Expand Down Expand Up @@ -523,13 +509,6 @@ impl<'a, T> ChordsV2<'a, T> {
}
}

if let Some((chord, consumed_presses)) = timed_out_chord {
self.queue.drain(0..usize::from(consumed_presses));
let ach = get_active_chord(chord, since, self.next_coord(), relevant_release_found);
let overflow = self.active_chords.push(ach);
assert!(overflow.is_ok(), "active chords has room");
}

// Clear presses from the queue if they were consumed by a chord.
if self.active_chords.len() > prev_active_chords_len {
self.queue.retain(|qd| match qd.event {
Expand Down
27 changes: 27 additions & 0 deletions src/tests/sim_tests/chord_sim_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,30 @@ fn sim_chord_oneshot() {
result
);
}

#[test]
fn sim_chord_timeout_events() {
let result = simulate(
"
(defcfg
concurrent-tap-hold yes
process-unmapped-keys yes
)
(defvirtualkeys
v-macro-word-end (macro spc)
)
(defsrc a b c)
(defchordsv2-experimental
(a b c) (macro x y z (on-press tap-vkey v-macro-word-end)) 200 all-released ()
(a b) (macro x y (on-press tap-vkey v-macro-word-end)) 200 all-released ()
)
(deflayer base a b c)
",
"d:a t:10 d:b t:3000 u:a u:b t:100",
)
.to_ascii();
assert_eq!(
"t:201ms dn:X t:1ms up:X t:1ms dn:Y t:1ms up:Y t:4ms dn:Space t:1ms up:Space",
result
);
}

0 comments on commit 6f9c54d

Please sign in to comment.