Skip to content

Commit

Permalink
fix: move override code to after unmod (jtroo#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo authored May 26, 2024
1 parent 6adef03 commit 8a0c78b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/kanata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,13 +872,6 @@ impl Kanata {
let mut live_reload_requested = false;
let cur_keys = &mut self.cur_keys;
cur_keys.extend(layout.keycodes());
self.overrides
.override_keys(cur_keys, &mut self.override_states);
if let Some(caps_word) = &mut self.caps_word {
if caps_word.maybe_add_lsft(cur_keys) == CapsWordNextState::End {
self.caps_word = None;
}
}

// Deal with unmodded. Unlike other custom actions, this should come before key presses and
// releases. I don't quite remember why custom actions come after the key processing, but I
Expand Down Expand Up @@ -934,6 +927,14 @@ impl Kanata {
cur_keys.extend(self.unshifted_keys.iter());
}

self.overrides
.override_keys(cur_keys, &mut self.override_states);
if let Some(caps_word) = &mut self.caps_word {
if caps_word.maybe_add_lsft(cur_keys) == CapsWordNextState::End {
self.caps_word = None;
}
}

// Release keys that do not exist in the current state but exist in the previous state.
// This used to use a HashSet but it was changed to a Vec because the order of operations
// matters.
Expand Down
1 change: 1 addition & 0 deletions src/tests/sim_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod block_keys_tests;
mod capsword_sim_tests;
mod chord_sim_tests;
mod layer_sim_tests;
mod override_tests;
mod repeat_sim_tests;
mod seq_sim_tests;
mod switch_sim_tests;
Expand Down
27 changes: 27 additions & 0 deletions src/tests/sim_tests/override_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use super::*;

#[test]
fn override_with_unmod() {
let result = simulate(
"
(defoverrides
(a) (b)
(b) (a)
)
(defalias
b (unshift b)
a (unshift a)
)
(defsrc a b)
(deflayer base @a @b)
",
"d:lsft d:a t:50 u:a t:50 d:b t:50 u:b t:50 u:lsft",
)
.to_ascii()
.no_time();
assert_eq!(
"dn:LShift up:LShift dn:B up:B dn:LShift up:LShift dn:A up:A dn:LShift",
result
);
}

0 comments on commit 8a0c78b

Please sign in to comment.