Add text input handling to settings popup

Introduce a `selected_setting_new_value` field in `SettingsState` and
initialize it.
Add `Backspace` and `WildCard(char)` actions with an `Input` group, and
corresponding keybindings.
Update `event_to_action` to map wildcard characters to
`Action::WildCard`.
Handle backspace and character input in `settings_keybindings` to edit
the new field.
Display the edited value in the settings popup and include the new
actions in the UI.
This commit is contained in:
2026-03-15 22:37:11 +01:00
parent 9d4ff19b6e
commit 2dbe378470
5 changed files with 112 additions and 46 deletions
+37 -2
View File
@@ -10,12 +10,15 @@ pub enum Action {
Space,
Enter,
Esc,
Backspace,
WildCard(char),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)]
pub enum Group {
Movement,
Select,
Input,
Quit,
}
@@ -94,6 +97,24 @@ pub static KEYBINDINGS: &[KeyBinding] = &[
symbol: "Esc",
description: "Go back",
},
KeyBinding {
action: Action::Backspace,
code: KeyCode::Backspace,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
group: Group::Input,
symbol: "Backspace",
description: "Delete character",
},
KeyBinding {
action: Action::WildCard('_'),
code: KeyCode::Char('_'),
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
group: Group::Input,
symbol: "*",
description: "All keyboard characters",
},
];
pub fn binding_for(action: Action) -> Option<&'static KeyBinding> {
@@ -101,8 +122,22 @@ pub fn binding_for(action: Action) -> Option<&'static KeyBinding> {
}
pub fn event_to_action(event: &KeyEvent) -> Option<Action> {
KEYBINDINGS
if let Some(b) = KEYBINDINGS
.iter()
.find(|b| b.code == event.code && b.kind == event.kind && b.modifiers == event.modifiers)
.map(|b| b.action)
{
return Some(b.action);
}
if KEYBINDINGS.iter().any(|b| {
matches!(b.action, Action::WildCard(_))
&& b.kind == event.kind
&& b.modifiers == event.modifiers
}) {
if let KeyCode::Char(c) = event.code {
return Some(Action::WildCard(c));
}
}
None
}