W54: ToggleOverwrite editor F9 command (MC CK_InsertOverwrite)

Add ToggleOverwrite EditorCmd variant, wire it into the Options
menu, and add a dispatch handler that toggles the overwrite
flag and shows [OVR]/[INS] in the status message (mirrors the
existing INS key behavior now accessible from the F9 menu).

Added 1 unit test verifying [OVR]→[INS] cycle.

Tests: 1416 pass (was 1415), zero warnings.
This commit is contained in:
2026-07-07 13:05:28 +03:00
parent 7a9e3f3466
commit eb5b428fa4
2 changed files with 24 additions and 0 deletions
@@ -89,6 +89,8 @@ pub enum EditorCmd {
BlockSave,
/// Close the current buffer (keep editor open).
Close,
/// Toggle insert/overwrite mode (INS key, MC CK_InsertOverwrite).
ToggleOverwrite,
}
/// Outcome of a menu-bar key press.
@@ -261,6 +263,8 @@ impl EditorMenuBar {
MenuItem::item("Word wrap", 'p', EditorCmd::ToggleWordWrap),
MenuItem::item("Syntax highlight", 'h', EditorCmd::ToggleSyntax),
MenuItem::item("Relative line numbers", 'r', EditorCmd::ToggleRelativeLines),
MenuItem::separator(),
MenuItem::item("Insert/Overwrite", 'i', EditorCmd::ToggleOverwrite),
],
),
];
@@ -1545,6 +1545,14 @@ impl Editor {
self.message = Some("No selection".to_string());
}
}
EditorCmd::ToggleOverwrite => {
self.overwrite = !self.overwrite;
self.message = Some(if self.overwrite {
"[OVR]".to_string()
} else {
"[INS]".to_string()
});
}
EditorCmd::Close => {
if self.modified {
self.mode = Mode::Prompt(PromptKind::SaveBeforeClose);
@@ -3913,5 +3921,17 @@ mod tests {
let _ = e.dispatch_editor_cmd(crate::editor::menubar::EditorCmd::InsertFile);
assert!(e.mode.is_prompt());
}
#[test]
fn toggle_overwrite_cycles_ovr_ins() {
let mut e = make_empty();
// Default is Insert mode (not overwrite).
// Toggle once → overwrite on.
let _ = e.dispatch_editor_cmd(crate::editor::menubar::EditorCmd::ToggleOverwrite);
assert_eq!(e.message, Some("[OVR]".to_string()));
// Toggle again → overwrite off.
let _ = e.dispatch_editor_cmd(crate::editor::menubar::EditorCmd::ToggleOverwrite);
assert_eq!(e.message, Some("[INS]".to_string()));
}
}