W28: Editor F9 Format menu (P1 audit gap)

The F9 audit found the editor had no Format menu at all. MC
has a dedicated Format menu with paragraph format, sort,
insert date/time, and external formatter entries.

Add a Format menu to the editor F9 menubar with 'Format paragraph'
(wired to the existing Editor::format_paragraph method, also
reachable via Alt-P). Sort, insert date/time, and external
formatter are documented as follow-ups.

- EditorCmd::FormatParagraph variant
- dispatch_editor_cmd handles it by calling format_paragraph()
- Format menu inserted between Edit and Search in the menubar

Updated 2 existing tests that counted menus (6→7) and checked
menu index (2→3 for Search after Format).

Tests: 1393 pass, zero warnings.
This commit is contained in:
2026-07-06 20:35:38 +03:00
parent f966f6e449
commit a965521cba
2 changed files with 19 additions and 5 deletions
@@ -79,6 +79,8 @@ pub enum EditorCmd {
ToggleRelativeLines,
/// Edit the user menu file (MC `CK_EditUserMenu`).
EditUserMenu,
/// Alt-P — reformat the paragraph at the cursor.
FormatParagraph,
}
/// Outcome of a menu-bar key press.
@@ -201,6 +203,14 @@ impl EditorMenuBar {
MenuItem::item("Paste", 'v', EditorCmd::Paste),
],
),
Menu::new(
"Format",
vec![MenuItem::item(
"Format paragraph",
'p',
EditorCmd::FormatParagraph,
)],
),
Menu::new(
"Search",
vec![
@@ -583,9 +593,9 @@ mod tests {
}
#[test]
fn new_has_six_menus() {
fn new_has_seven_menus() {
let m = mb();
assert_eq!(m.menu_count(), 6);
assert_eq!(m.menu_count(), 7);
assert_eq!(
m.active_items().len(),
7 // File menu has 7 entries
@@ -677,13 +687,14 @@ mod tests {
#[test]
fn letter_hotkey_selects_menu_by_title() {
let mut m = mb();
// 'S' should jump to Search menu (third).
// 'S' should jump to Search menu (fourth, after File/Edit/Format).
let _ = m.handle_key(k('s'));
// 's' might match 's' for Search (Se...) or s in 'Bookmark'...
// First match wins. The first menu whose title starts with
// the given char wins. Title 'File' starts with 'f' (no match).
// 'Edit' starts with 'e' (no). 'Search' starts with 's' (match).
assert_eq!(m.active_menu(), 2);
// 'Edit' starts with 'e' (no). 'Format' starts with 'f' (no).
// 'Search' starts with 's' (match).
assert_eq!(m.active_menu(), 3);
}
#[test]
@@ -1226,6 +1226,9 @@ impl Editor {
"Auto-indent: OFF".to_string()
});
}
EditorCmd::FormatParagraph => {
self.format_paragraph();
}
EditorCmd::ToggleShowWhitespace => {
let on = self.toggle_show_whitespace();
self.message = Some(if on {