finally working properly config parsing
This commit is contained in:
@@ -186,4 +186,102 @@ impl Config {
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
// This method handles all keybinding formats, both with and without +
|
||||
pub fn matches_key_sequence_generalized(&self, sequence: &[KeyCode]) -> Option<&str> {
|
||||
if sequence.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Get string representations of the sequence
|
||||
let sequence_str = sequence.iter()
|
||||
.map(|k| crate::config::key_sequences::key_to_string(k))
|
||||
.collect::<Vec<String>>()
|
||||
.join("");
|
||||
|
||||
// Add the missing sequence_plus definition
|
||||
let sequence_plus = sequence.iter()
|
||||
.map(|k| crate::config::key_sequences::key_to_string(k))
|
||||
.collect::<Vec<String>>()
|
||||
.join("+");
|
||||
|
||||
// Check for matches in all binding formats
|
||||
for (action, bindings) in &self.keybindings {
|
||||
for binding in bindings {
|
||||
let normalized_binding = binding.to_lowercase();
|
||||
|
||||
// Check if binding matches any of our formats
|
||||
if normalized_binding == sequence_str || normalized_binding == sequence_plus {
|
||||
return Some(action);
|
||||
}
|
||||
|
||||
// Special case for + format in bindings
|
||||
if binding.contains('+') {
|
||||
let normalized_sequence = sequence.iter()
|
||||
.map(|k| crate::config::key_sequences::key_to_string(k))
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
let binding_parts: Vec<&str> = binding.split('+').collect();
|
||||
|
||||
if binding_parts.len() == sequence.len() {
|
||||
let matches = binding_parts.iter().enumerate().all(|(i, part)| {
|
||||
part.to_lowercase() == normalized_sequence[i].to_lowercase()
|
||||
});
|
||||
|
||||
if matches {
|
||||
return Some(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
// Check if the current key sequence is a prefix of a longer binding
|
||||
pub fn is_key_sequence_prefix(&self, sequence: &[KeyCode]) -> bool {
|
||||
if sequence.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get string representation of the sequence
|
||||
let sequence_str = sequence.iter()
|
||||
.map(|k| crate::config::key_sequences::key_to_string(k))
|
||||
.collect::<Vec<String>>()
|
||||
.join("");
|
||||
|
||||
// Check all bindings to see if our sequence is a prefix
|
||||
for (_, bindings) in &self.keybindings {
|
||||
for binding in bindings {
|
||||
let normalized_binding = binding.to_lowercase();
|
||||
|
||||
// Check standard format
|
||||
if normalized_binding.starts_with(&sequence_str) &&
|
||||
normalized_binding.len() > sequence_str.len() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check + format
|
||||
if binding.contains('+') {
|
||||
let binding_parts: Vec<&str> = binding.split('+').collect();
|
||||
let sequence_parts = sequence.iter()
|
||||
.map(|k| crate::config::key_sequences::key_to_string(k))
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
if binding_parts.len() > sequence_parts.len() {
|
||||
let prefix_matches = sequence_parts.iter().enumerate().all(|(i, part)| {
|
||||
binding_parts.get(i).map_or(false, |b| b.to_lowercase() == part.to_lowercase())
|
||||
});
|
||||
|
||||
if prefix_matches {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user