feat(cmd): use new effects to improve command behavior
Update various commands to utilize the new AbortChain and CleanEmptyRecords effects. - CommitAndAdvance now pushes a mode change effect when aborting. - ToggleRecordsMode now cleans up empty records upon exiting. - EnterAdvance now emits AbortChain when at the bottom-right corner. Co-Authored-By: fiddlerwoaroof/git-smart-commit (gemma-4-26B-A4B-it-UD-Q5_K_XL.gguf)
This commit is contained in:
@ -261,6 +261,16 @@ pub enum AdvanceDir {
|
||||
Right,
|
||||
}
|
||||
|
||||
/// Return the normal-mode counterpart of an editing mode. Used by
|
||||
/// `CommitAndAdvance` to compute the mode to land in if the advance
|
||||
/// aborts (commit + exit editing at boundary).
|
||||
fn exit_mode_for(edit_mode: &AppMode) -> AppMode {
|
||||
match edit_mode {
|
||||
AppMode::RecordsEditing { .. } => AppMode::RecordsNormal,
|
||||
_ => AppMode::Normal,
|
||||
}
|
||||
}
|
||||
|
||||
/// Commit a cell edit, advance the cursor, and re-enter edit mode.
|
||||
/// Subsumes the old `CommitCellEdit` (Down) and `CommitAndAdvanceRight` (Right).
|
||||
///
|
||||
@ -286,6 +296,13 @@ impl Cmd for CommitAndAdvance {
|
||||
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
|
||||
let mut effects: Vec<Box<dyn Effect>> = Vec::new();
|
||||
commit_cell_value(ctx, &self.key, &self.value, &mut effects);
|
||||
// Pre-emptively drop to the normal counterpart of edit_mode. If the
|
||||
// advance succeeds, the trailing `EnterEditAtCursor` below will lift
|
||||
// us back into editing on the new cell. If the advance aborts
|
||||
// (e.g. already at bottom-right on Enter), `EnterEditAtCursor` is
|
||||
// skipped and we land in normal mode — which is the desired
|
||||
// "Enter at bottom-right commits and exits" behavior.
|
||||
effects.push(effect::change_mode(exit_mode_for(&self.edit_mode)));
|
||||
match self.advance {
|
||||
AdvanceDir::Down => {
|
||||
let adv = EnterAdvance {
|
||||
|
||||
Reference in New Issue
Block a user