diff --git a/keyboard_layout/src/layout.rs b/keyboard_layout/src/layout.rs index c63ebd8..7302301 100644 --- a/keyboard_layout/src/layout.rs +++ b/keyboard_layout/src/layout.rs @@ -453,6 +453,13 @@ impl Layout { (base, mods) } + /// If the layout has at least one layer configured as hold layer + pub fn has_hold_layers(&self) -> bool { + self.layerkeys + .iter() + .any(|lk| std::matches!(lk.modifiers, LayerModifiers::Hold(_))) + } + /// If the layout has at least one layer configured as one-shot layer pub fn has_one_shot_layers(&self) -> bool { self.layerkeys diff --git a/layout_evaluation/src/ngram_mapper/bigram_mapper.rs b/layout_evaluation/src/ngram_mapper/bigram_mapper.rs index 2dc16b2..5f65b0d 100644 --- a/layout_evaluation/src/ngram_mapper/bigram_mapper.rs +++ b/layout_evaluation/src/ngram_mapper/bigram_mapper.rs @@ -83,11 +83,11 @@ impl OnDemandBigramMapper { map_bigrams(bigrams, layout, exclude_line_breaks); if layout.has_one_shot_layers() { - bigram_keys_vec = self.process_one_shot_layers(bigram_keys_vec, layout); + bigram_keys_vec = self.process_one_shot_modifiers(bigram_keys_vec, layout); } - let bigram_keys = if self.split_modifiers.enabled { - self.split_bigram_modifiers(bigram_keys_vec, layout) + let bigram_keys = if self.split_modifiers.enabled && layout.has_hold_layers() { + self.process_hold_modifiers(bigram_keys_vec, layout) } else { bigram_keys_vec.into_iter().collect() }; @@ -135,7 +135,7 @@ impl OnDemandBigramMapper { /// /// Each bigram of higher-layer symbols will transform into a series of bigrams with permutations of /// the involved base-keys and modifers. However, the base-key will always be after its modifier. - fn split_bigram_modifiers(&self, bigrams: BigramIndicesVec, layout: &Layout) -> BigramIndices { + fn process_hold_modifiers(&self, bigrams: BigramIndicesVec, layout: &Layout) -> BigramIndices { let mut bigram_w_map = AHashMap::with_capacity(bigrams.len() / 3); bigrams.into_iter().for_each(|((k1, k2), w)| { @@ -190,7 +190,7 @@ impl OnDemandBigramMapper { bigram_w_map } - fn process_one_shot_layers( + fn process_one_shot_modifiers( &self, bigrams: BigramIndicesVec, layout: &Layout, diff --git a/layout_evaluation/src/ngram_mapper/trigram_mapper.rs b/layout_evaluation/src/ngram_mapper/trigram_mapper.rs index 41ccc2e..6dfd47d 100644 --- a/layout_evaluation/src/ngram_mapper/trigram_mapper.rs +++ b/layout_evaluation/src/ngram_mapper/trigram_mapper.rs @@ -90,11 +90,11 @@ impl OnDemandTrigramMapper { map_trigrams(trigrams, layout, exclude_line_breaks); if layout.has_one_shot_layers() { - trigram_keys_vec = self.process_one_shot_layers(trigram_keys_vec, layout); + trigram_keys_vec = self.process_one_shot_modifiers(trigram_keys_vec, layout); } - let trigram_keys = if self.split_modifiers.enabled { - self.split_trigram_modifiers(trigram_keys_vec, layout) + let trigram_keys = if self.split_modifiers.enabled && layout.has_hold_layers() { + self.process_hold_modifiers(trigram_keys_vec, layout) } else { trigram_keys_vec.into_iter().collect() }; @@ -140,7 +140,7 @@ impl OnDemandTrigramMapper { /// trigram can be large (tens of trigrams) if multiple symbols of the trigram are accessed using multiple modifiers. // this is one of the most intensive functions of the layout evaluation - fn split_trigram_modifiers( + fn process_hold_modifiers( &self, trigrams: TrigramIndicesVec, layout: &Layout, @@ -276,7 +276,7 @@ impl OnDemandTrigramMapper { trigram_w_map } - fn process_one_shot_layers( + fn process_one_shot_modifiers( &self, trigrams: TrigramIndicesVec, layout: &Layout, diff --git a/layout_evaluation/src/ngram_mapper/unigram_mapper.rs b/layout_evaluation/src/ngram_mapper/unigram_mapper.rs index 7877186..eed6b2b 100644 --- a/layout_evaluation/src/ngram_mapper/unigram_mapper.rs +++ b/layout_evaluation/src/ngram_mapper/unigram_mapper.rs @@ -57,11 +57,11 @@ impl OnDemandUnigramMapper { let (mut unigram_keys_vec, not_found_weight) = map_unigrams(unigrams, layout); if layout.has_one_shot_layers() { - unigram_keys_vec = self.process_one_shot_layers(unigram_keys_vec, layout); + unigram_keys_vec = self.process_one_shot_modifiers(unigram_keys_vec, layout); } - let unigram_keys = if self.split_modifiers.enabled { - Self::split_unigram_modifiers(unigram_keys_vec, layout) + let unigram_keys = if self.split_modifiers.enabled && layout.has_hold_layers() { + Self::process_hold_modifiers(unigram_keys_vec, layout) } else { unigram_keys_vec.into_iter().collect() }; @@ -85,7 +85,7 @@ impl OnDemandUnigramMapper { /// /// Each unigram of a higher-layer symbol will transform into a unigram with the base-layer key and one /// for each modifier involved in accessing the higher layer. - fn split_unigram_modifiers(unigrams: UnigramIndicesVec, layout: &Layout) -> UnigramIndices { + fn process_hold_modifiers(unigrams: UnigramIndicesVec, layout: &Layout) -> UnigramIndices { let mut idx_w_map = AHashMap::with_capacity(unigrams.len() / 3); unigrams.into_iter().for_each(|(k, w)| { let (base, mods) = layout.resolve_modifiers(&k); @@ -117,7 +117,7 @@ impl OnDemandUnigramMapper { idx_w_map } - fn process_one_shot_layers( + fn process_one_shot_modifiers( &self, unigrams: UnigramIndicesVec, layout: &Layout,