refactor(cmd): simplify commit and navigation logic

Simplify the return value of CommitFormula::execute to use a vec! macro and
move the page_cat_data helper function in navigation.rs for better
organization.

Co-Authored-By: fiddlerwoaroof/git-smart-commit (gemma-4-31B-it-UD-Q4_K_XL.gguf)
This commit is contained in:
Edward Langley
2026-04-14 01:03:25 -07:00
parent 648e50860e
commit f3996da2ec
2 changed files with 45 additions and 44 deletions

View File

@ -222,22 +222,23 @@ impl Cmd for CommitFormula {
}
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
let buf = ctx.buffers.get("formula").cloned().unwrap_or_default();
let mut effects: Vec<Box<dyn Effect>> = Vec::new();
// Default formula target to _Measure (the virtual measure category).
// _Measure dynamically includes all formula targets.
effects.push(Box::new(effect::AddFormula {
raw: buf,
target_category: "_Measure".to_string(),
}));
effects.push(effect::mark_dirty());
effects.push(effect::set_status("Formula added"));
effects.push(effect::change_mode(AppMode::FormulaPanel));
effects
vec![
Box::new(effect::AddFormula {
raw: buf,
target_category: "_Measure".to_string(),
}),
effect::mark_dirty(),
effect::set_status("Formula added"),
effect::change_mode(AppMode::FormulaPanel),
]
}
}
/// Shared helper: read a buffer, trim it, and if non-empty, produce add + dirty
/// + status effects. If empty, return to CategoryPanel.
///
/// Buffer clearing is handled by the keymap (Enter → [commit, clear-buffer]).
fn commit_add_from_buffer(
ctx: &CmdContext,