Implement the in-process structured entry editor

Closes #21
This commit is contained in:
Hermes Agent committed 2026-08-10 07:22:55 +00:00
1 parent cf7a6216ac
commit b503de8b2e
14 files changed
+1547 -37

No files matched your search

+93 -5
View File
@@ -33,6 +33,16 @@ pub enum Action {
ScrollDown,
ScrollUp,
CloseEntry,
EditEntry,
BeginInput,
SaveEditor,
AddField,
RemoveField,
MoveFieldUp,
MoveFieldDown,
Generate,
ConfirmDiscard,
KeepEditing,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -59,7 +69,15 @@ impl ActionSpec {
const BROWSER_LIKE: &[Mode] = &[Mode::Browser, Mode::Viewer];
const UNLOCKED: &[Mode] = &[Mode::Browser, Mode::Viewer, Mode::Editor];
const OVERLAYS: &[Mode] = &[Mode::Help, Mode::Command, Mode::Dialog];
const LOCKABLE: &[Mode] = &[
Mode::Browser,
Mode::Viewer,
Mode::Editor,
Mode::Dialog,
Mode::Help,
Mode::Command,
];
const EDITOR_AND_OVERLAYS: &[Mode] = &[Mode::Editor, Mode::Help, Mode::Command, Mode::Dialog];
#[cfg(test)]
const ALL: &[Mode] = &[
Mode::Browser,
@@ -111,7 +129,7 @@ pub static ACTIONS: &[ActionSpec] = &[
label: "back",
command: "cancel",
bindings: keys!((KeyCode::Esc, KeyModifiers::NONE, "Esc")),
modes: OVERLAYS,
modes: EDITOR_AND_OVERLAYS,
},
ActionSpec {
action: Action::Lock,
@@ -121,7 +139,7 @@ pub static ACTIONS: &[ActionSpec] = &[
(KeyCode::Char('l'), KeyModifiers::CONTROL, "C-l"),
(KeyCode::Char('z'), KeyModifiers::CONTROL, "C-z"),
),
modes: UNLOCKED,
modes: LOCKABLE,
},
ActionSpec {
action: Action::Refresh,
@@ -245,14 +263,14 @@ pub static ACTIONS: &[ActionSpec] = &[
label: "reveal field",
command: "reveal",
bindings: keys!((KeyCode::Char('v'), KeyModifiers::NONE, "v")),
modes: &[Mode::Viewer],
modes: &[Mode::Viewer, Mode::Editor],
},
ActionSpec {
action: Action::Hide,
label: "hide field",
command: "hide",
bindings: keys!((KeyCode::Char('V'), KeyModifiers::SHIFT, "V")),
modes: &[Mode::Viewer],
modes: &[Mode::Viewer, Mode::Editor],
},
ActionSpec {
action: Action::Copy,
@@ -290,6 +308,76 @@ pub static ACTIONS: &[ActionSpec] = &[
bindings: keys!((KeyCode::Esc, KeyModifiers::NONE, "Esc")),
modes: &[Mode::Viewer],
},
ActionSpec {
action: Action::EditEntry,
label: "edit entry",
command: "edit-entry",
bindings: keys!((KeyCode::Char('e'), KeyModifiers::NONE, "e")),
modes: &[Mode::Viewer],
},
ActionSpec {
action: Action::BeginInput,
label: "edit field",
command: "edit-field",
bindings: keys!((KeyCode::Char('i'), KeyModifiers::NONE, "i")),
modes: &[Mode::Editor],
},
ActionSpec {
action: Action::SaveEditor,
label: "save",
command: "save",
bindings: keys!((KeyCode::Char('s'), KeyModifiers::CONTROL, "C-s")),
modes: &[Mode::Editor],
},
ActionSpec {
action: Action::AddField,
label: "add field",
command: "add-field",
bindings: keys!((KeyCode::Char('a'), KeyModifiers::NONE, "a")),
modes: &[Mode::Editor],
},
ActionSpec {
action: Action::RemoveField,
label: "remove field",
command: "remove-field",
bindings: keys!((KeyCode::Char('d'), KeyModifiers::NONE, "d")),
modes: &[Mode::Editor],
},
ActionSpec {
action: Action::MoveFieldUp,
label: "move field up",
command: "move-field-up",
bindings: keys!((KeyCode::Char('K'), KeyModifiers::SHIFT, "K")),
modes: &[Mode::Editor],
},
ActionSpec {
action: Action::MoveFieldDown,
label: "move field down",
command: "move-field-down",
bindings: keys!((KeyCode::Char('J'), KeyModifiers::SHIFT, "J")),
modes: &[Mode::Editor],
},
ActionSpec {
action: Action::Generate,
label: "generate field",
command: "generate-field",
bindings: keys!((KeyCode::Char('g'), KeyModifiers::NONE, "g")),
modes: &[Mode::Editor],
},
ActionSpec {
action: Action::ConfirmDiscard,
label: "discard edits",
command: "discard-edits",
bindings: keys!((KeyCode::Char('y'), KeyModifiers::NONE, "y")),
modes: &[Mode::Dialog],
},
ActionSpec {
action: Action::KeepEditing,
label: "keep editing",
command: "keep-editing",
bindings: keys!((KeyCode::Char('n'), KeyModifiers::NONE, "n")),
modes: &[Mode::Dialog],
},
];
pub fn resolve_key(mode: Mode, code: KeyCode, modifiers: KeyModifiers) -> Option<Action> {