feat(keymap): add ImportWizard mode with Any key pattern
Add Any key pattern as lowest priority fallback in KeyPattern enum. Add ImportWizard to ModeKey enum and its mapping from AppMode. Modify key lookup to fall back to Any pattern for unmatched keys. Change Enter key in command mode to execute ExecuteCommand. Add ImportWizard keymap that binds all keys to HandleWizardKey. Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/Qwen3.5-35B-A3B-GGUF:Q5_K_M)
This commit is contained in:
@ -18,6 +18,8 @@ pub enum KeyPattern {
|
||||
/// Matches any Char key (for text-entry modes). The actual char
|
||||
/// is available in CmdContext::key_code.
|
||||
AnyChar,
|
||||
/// Matches any key at all (lowest priority fallback).
|
||||
Any,
|
||||
}
|
||||
|
||||
/// Identifies which mode a binding applies to.
|
||||
@ -37,6 +39,7 @@ pub enum ModeKey {
|
||||
ExportPrompt,
|
||||
CommandMode,
|
||||
SearchMode,
|
||||
ImportWizard,
|
||||
}
|
||||
|
||||
impl ModeKey {
|
||||
@ -55,6 +58,7 @@ impl ModeKey {
|
||||
AppMode::ItemAdd { .. } => Some(ModeKey::ItemAdd),
|
||||
AppMode::ExportPrompt { .. } => Some(ModeKey::ExportPrompt),
|
||||
AppMode::CommandMode { .. } => Some(ModeKey::CommandMode),
|
||||
AppMode::ImportWizard => Some(ModeKey::ImportWizard),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -103,13 +107,13 @@ impl Keymap {
|
||||
self.bindings
|
||||
.get(&KeyPattern::Key(key, mods))
|
||||
.or_else(|| {
|
||||
// Fall back to AnyChar for text-entry modes
|
||||
if matches!(key, KeyCode::Char(_)) {
|
||||
self.bindings.get(&KeyPattern::AnyChar)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.or_else(|| self.bindings.get(&KeyPattern::Any))
|
||||
.map(|c| c.as_ref())
|
||||
}
|
||||
|
||||
@ -577,8 +581,7 @@ impl KeymapSet {
|
||||
// ── Command mode ─────────────────────────────────────────────────
|
||||
let mut cm = Keymap::new();
|
||||
cm.bind_cmd(KeyCode::Esc, none, cmd::EnterMode(AppMode::Normal));
|
||||
// Enter → execute_command (still handled by old handler for now —
|
||||
// the complex execute_command logic isn't easily a single Cmd)
|
||||
cm.bind_cmd(KeyCode::Enter, none, cmd::ExecuteCommand);
|
||||
cm.bind_cmd(KeyCode::Backspace, none, cmd::CommandModeBackspace);
|
||||
cm.bind_any_char(cmd::AppendChar {
|
||||
buffer: "command".to_string(),
|
||||
@ -593,6 +596,14 @@ impl KeymapSet {
|
||||
sm.bind_any_char(cmd::SearchAppendChar);
|
||||
set.insert(ModeKey::SearchMode, Arc::new(sm));
|
||||
|
||||
// ── Import wizard mode ────────────────────────────────────────────
|
||||
let mut wiz = Keymap::new();
|
||||
// All keys are dispatched to the wizard effect, which handles
|
||||
// step-specific behavior internally.
|
||||
wiz.bindings
|
||||
.insert(KeyPattern::Any, Arc::new(cmd::HandleWizardKey));
|
||||
set.insert(ModeKey::ImportWizard, Arc::new(wiz));
|
||||
|
||||
set
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user