From a965521cbaad77be1db4fb6e4c43b15314259d4b Mon Sep 17 00:00:00 2001 From: vasilito Date: Mon, 6 Jul 2026 20:35:38 +0300 Subject: [PATCH] W28: Editor F9 Format menu (P1 audit gap) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../tui/tlc/source/src/editor/menubar.rs | 21 ++++++++++++++----- .../recipes/tui/tlc/source/src/editor/mod.rs | 3 +++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/local/recipes/tui/tlc/source/src/editor/menubar.rs b/local/recipes/tui/tlc/source/src/editor/menubar.rs index 8018b35d4d..3609e6656d 100644 --- a/local/recipes/tui/tlc/source/src/editor/menubar.rs +++ b/local/recipes/tui/tlc/source/src/editor/menubar.rs @@ -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] diff --git a/local/recipes/tui/tlc/source/src/editor/mod.rs b/local/recipes/tui/tlc/source/src/editor/mod.rs index 352e28017b..4df082fc20 100644 --- a/local/recipes/tui/tlc/source/src/editor/mod.rs +++ b/local/recipes/tui/tlc/source/src/editor/mod.rs @@ -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 {