feat(effect): add changes_mode method to Effect trait and use it in ExecuteCommand

Add a `changes_mode` method to the `Effect` trait with a default implementation
returning `false` . Implement this method for the `ChangeMode` effect to return
`true` . Update the command execution logic to use `e.changes_mode()` instead of
string matching on formatted output. Adjust the corresponding test to assert the
presence of a mode‑changing effect directly via the new method, removing the
temporary debug string.

This change introduces a clear, typed way to detect mode‑changing effects,
improving readability and reducing reliance on string inspection.

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 00:48:22 -07:00
parent 8f3a54bb38
commit de047ddf1a
2 changed files with 10 additions and 4 deletions

View File

@ -1632,7 +1632,7 @@ impl Cmd for ExecuteCommand {
effects.extend(cmd.execute(ctx));
}
// Return to Normal unless a command already changed mode
if !effects.iter().any(|e| format!("{e:?}").contains("ChangeMode")) {
if !effects.iter().any(|e| e.changes_mode()) {
effects.push(effect::change_mode(AppMode::Normal));
}
effects
@ -2955,10 +2955,9 @@ mod tests {
ctx.buffers = &bufs;
let cmd = ExecuteCommand;
let effects = cmd.execute(&ctx);
let dbg = format!("{:?}", effects);
assert!(
dbg.contains("ChangeMode"),
"Expected ChangeMode, got: {dbg}"
effects.iter().any(|e| e.changes_mode()),
"Expected a mode-changing effect"
);
}