space commands here we go again
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// client/src/config/key_sequences.rs
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
use std::time::{Duration, Instant};
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ParsedKey {
|
||||
@@ -25,19 +26,21 @@ impl KeySequenceTracker {
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
info!("KeySequenceTracker.reset() from {:?}", self.current_sequence);
|
||||
self.current_sequence.clear();
|
||||
self.last_key_time = Instant::now();
|
||||
}
|
||||
|
||||
pub fn add_key(&mut self, key: KeyCode) -> bool {
|
||||
// Check if timeout has expired
|
||||
let now = Instant::now();
|
||||
if now.duration_since(self.last_key_time) > self.timeout {
|
||||
info!("KeySequenceTracker timeout — reset before adding {:?}", key);
|
||||
self.reset();
|
||||
}
|
||||
|
||||
self.current_sequence.push(key);
|
||||
self.last_key_time = now;
|
||||
info!("KeySequenceTracker state after add: {:?}", self.current_sequence);
|
||||
true
|
||||
}
|
||||
|
||||
@@ -115,26 +118,21 @@ pub fn string_to_keycode(s: &str) -> Option<KeyCode> {
|
||||
pub fn parse_binding(binding: &str) -> Vec<ParsedKey> {
|
||||
let mut sequence = Vec::new();
|
||||
|
||||
// Handle different binding formats
|
||||
let parts: Vec<String> = if binding.contains('+') {
|
||||
// Format with explicit '+' separators like "g+left"
|
||||
binding.split('+').map(|s| s.to_string()).collect()
|
||||
} else if binding.contains(' ') {
|
||||
// Format with spaces like "g left"
|
||||
binding.split(' ').map(|s| s.to_string()).collect()
|
||||
} else if is_compound_key(binding) {
|
||||
// A single compound key like "left" or "enter"
|
||||
vec![binding.to_string()]
|
||||
// Split into multi-key sequence:
|
||||
// - If contains space → sequence split by space
|
||||
// - Else split by '+'
|
||||
let parts: Vec<&str> = if binding.contains(' ') {
|
||||
binding.split(' ').collect()
|
||||
} else {
|
||||
// Simple character sequence like "gg"
|
||||
binding.chars().map(|c| c.to_string()).collect()
|
||||
binding.split('+').collect()
|
||||
};
|
||||
|
||||
for part in &parts {
|
||||
if let Some(key) = parse_key_part(part) {
|
||||
sequence.push(key);
|
||||
for part in parts {
|
||||
if let Some(parsed) = parse_key_part(part) {
|
||||
sequence.push(parsed);
|
||||
}
|
||||
}
|
||||
|
||||
sequence
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user