Skip to content

Commit

Permalink
fix(zippy): make non-followup type correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo committed Dec 4, 2024
1 parent adc1795 commit 6a1ea9c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/kanata/output_logic/zippychord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ struct ZchDynamicState {
/// possible; after which if a chord has not been activated, zippychording is disabled. This
/// state is the counter for this deadline.
zchd_ticks_until_disable: u16,
/// Track number of activations within the same hold.
zchd_same_hold_activation_count: u16,
/// Current state of caps-word, which is a factor in handling capitalization.
zchd_is_caps_word_active: bool,
/// Current state of lsft which is a factor in handling capitalization.
Expand Down Expand Up @@ -221,6 +223,7 @@ impl ZchDynamicState {
self.zchd_characters_to_delete_on_next_activation = 0;
self.zchd_ticks_until_disable = 0;
self.zchd_enabled_state = ZchEnabledState::Enabled;
self.zchd_same_hold_activation_count = 0;
}
(ZchLastPressClassification::IsChord, false) => {
log::debug!("some released->zippy enabled");
Expand Down Expand Up @@ -338,31 +341,37 @@ impl ZchState {
// activation. This value affects both:
// - the number of backspaces that need to be done
// - the number of characters that actually need to be typed by the activation
let common_prefix_len_from_past_activation = self
.zchd
.zchd_prior_activation
.as_ref()
.map(|prior_activation| {
let current_activation_output = &a.zch_output;
let mut len: i16 = 0;
for (past, current) in prior_activation
.zch_output
.iter()
.copied()
.zip(current_activation_output.iter().copied())
{
if past.osc() == OsCode::KEY_BACKSPACE
|| current.osc() == OsCode::KEY_BACKSPACE
|| past != current
let common_prefix_len_from_past_activation = if !is_prioritized_activation
&& self.zchd.zchd_same_hold_activation_count == 0
{
0
} else {
self.zchd
.zchd_prior_activation
.as_ref()
.map(|prior_activation| {
let current_activation_output = &a.zch_output;
let mut len: i16 = 0;
for (past, current) in prior_activation
.zch_output
.iter()
.copied()
.zip(current_activation_output.iter().copied())
{
break;
if past.osc() == OsCode::KEY_BACKSPACE
|| current.osc() == OsCode::KEY_BACKSPACE
|| past != current
{
break;
}
len += 1;
}
len += 1;
}
len
})
.unwrap_or(0);
len
})
.unwrap_or(0)
};
self.zchd.zchd_prior_activation = Some(a.clone());
self.zchd.zchd_same_hold_activation_count += 1;

self.zchd
.zchd_restart_deadline(self.zch_cfg.zch_cfg_ticks_chord_deadline);
Expand Down
18 changes: 18 additions & 0 deletions src/tests/sim_tests/zippychord_sim_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,21 @@ fn sim_zippychord_smartspace_custom_punc() {
result
);
}

#[test]
fn sim_zippychord_non_followup_subsequent_with_potential_followups_available() {
let result = simulate_with_zippy_file_content(
"(defsrc)(deflayer base)(defzippy-experimental file
smart-space full)",
"d:g d:. t:10 u:g u:. t:1000 d:g d:. t:10 u:g u:. t:1000",
ZIPPY_FILE_CONTENT,
)
.to_ascii();
assert_eq!(
"dn:G t:1ms dn:BSpace up:BSpace up:G dn:G dn:I up:I dn:T up:T dn:Space up:Space t:9ms \
up:G t:1ms up:Dot t:999ms \
dn:G t:1ms dn:BSpace up:BSpace up:G dn:G dn:I up:I dn:T up:T dn:Space up:Space t:9ms \
up:G t:1ms up:Dot",
result
);
}

0 comments on commit 6a1ea9c

Please sign in to comment.