feat(ui): simplify AppMode minibuffer handling and panel rendering

Refactor AppMode to use MinibufferConfig for all text-entry modes. Update
command implementations to use new mode constructors. Introduce
PanelContent trait and replace panel structs with content types. Adjust
rendering to use Panel::new and minibuffer configuration. Update imports
and add MinibufferConfig struct. No functional changes; all behavior
preserved.

Co-Authored-By: fiddlerwoaroof/git-smart-commit (bartowski/nvidia_Nemotron-Cascade-2-30B-A3B-GGUF)
This commit is contained in:
Edward Langley
2026-04-07 02:04:46 -07:00
parent de047ddf1a
commit 4b11b6e321
9 changed files with 376 additions and 320 deletions

View File

@ -373,17 +373,9 @@ impl Cmd for EnterMode {
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
let mut effects: Vec<Box<dyn Effect>> = Vec::new();
// Clear the corresponding buffer when entering a text-entry mode
let buffer_name = match &self.0 {
AppMode::CommandMode { .. } => Some("command"),
AppMode::Editing { .. } => Some("edit"),
AppMode::FormulaEdit { .. } => Some("formula"),
AppMode::CategoryAdd { .. } => Some("category"),
AppMode::ExportPrompt { .. } => Some("export"),
_ => None,
};
if let Some(name) = buffer_name {
if let Some(mb) = self.0.minibuffer() {
effects.push(Box::new(effect::SetBuffer {
name: name.to_string(),
name: mb.buffer_key.to_string(),
value: String::new(),
}));
}
@ -623,9 +615,7 @@ impl Cmd for EnterEditMode {
name: "edit".to_string(),
value: self.initial_value.clone(),
}),
effect::change_mode(AppMode::Editing {
buffer: String::new(),
}),
effect::change_mode(AppMode::editing()),
]
}
}
@ -764,9 +754,7 @@ impl Cmd for EnterExportPrompt {
"enter-export-prompt"
}
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
vec![effect::change_mode(AppMode::ExportPrompt {
buffer: String::new(),
})]
vec![effect::change_mode(AppMode::export_prompt())]
}
}
@ -869,9 +857,7 @@ impl Cmd for SearchOrCategoryAdd {
panel: Panel::Category,
open: true,
}),
effect::change_mode(AppMode::CategoryAdd {
buffer: String::new(),
}),
effect::change_mode(AppMode::category_add()),
]
}
}
@ -1237,9 +1223,7 @@ impl Cmd for EnterFormulaEdit {
"enter-formula-edit"
}
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
vec![effect::change_mode(AppMode::FormulaEdit {
buffer: String::new(),
})]
vec![effect::change_mode(AppMode::formula_edit())]
}
}
@ -1302,10 +1286,7 @@ impl Cmd for OpenItemAddAtCursor {
}
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
if let Some(cat_name) = ctx.cat_at_cursor() {
vec![effect::change_mode(AppMode::ItemAdd {
category: cat_name,
buffer: String::new(),
})]
vec![effect::change_mode(AppMode::item_add(cat_name))]
} else {
vec![effect::set_status(
"No category selected. Press n to add a category first.",
@ -2543,21 +2524,11 @@ pub fn default_registry() -> CmdRegistry {
"category-panel" => AppMode::CategoryPanel,
"view-panel" => AppMode::ViewPanel,
"tile-select" => AppMode::TileSelect,
"command" => AppMode::CommandMode {
buffer: String::new(),
},
"category-add" => AppMode::CategoryAdd {
buffer: String::new(),
},
"editing" => AppMode::Editing {
buffer: String::new(),
},
"formula-edit" => AppMode::FormulaEdit {
buffer: String::new(),
},
"export-prompt" => AppMode::ExportPrompt {
buffer: String::new(),
},
"command" => AppMode::command_mode(),
"category-add" => AppMode::category_add(),
"editing" => AppMode::editing(),
"formula-edit" => AppMode::formula_edit(),
"export-prompt" => AppMode::export_prompt(),
other => return Err(format!("Unknown mode: {other}")),
};
Ok(Box::new(EnterMode(mode)))