From f0341aa53da5cf817083420d238e6d00a4c73ead Mon Sep 17 00:00:00 2001 From: vasilito Date: Tue, 7 Jul 2026 12:32:24 +0300 Subject: [PATCH] W50: Editor MarkAll, InsertFile, BlockSave, Close commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MC parity gap: the editor F9 menu was missing 4 commands that MC has. This adds them all: - MarkAll (CK_MarkAll): select all text via start_selection + set_position(0) + set_position(len) - InsertFile (CK_InsertFile): open SaveAs-style prompt to pick a file to insert at the cursor (reuses PromptKind::InsertFile) - BlockSave (CK_BlockSave): open SaveAs prompt pre-filled with the selected text, saves selection to a different file - Close (CK_Close): close current buffer (prompt save if dirty) All 4 added to the F9 File and Edit menus. Test updated for new file menu item count (7→11). Tests: 1407 pass, zero warnings. --- .../tui/tlc/source/src/editor/menubar.rs | 16 ++++++++++- .../recipes/tui/tlc/source/src/editor/mod.rs | 27 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/local/recipes/tui/tlc/source/src/editor/menubar.rs b/local/recipes/tui/tlc/source/src/editor/menubar.rs index 3609e6656d..bd6b6744a2 100644 --- a/local/recipes/tui/tlc/source/src/editor/menubar.rs +++ b/local/recipes/tui/tlc/source/src/editor/menubar.rs @@ -81,6 +81,14 @@ pub enum EditorCmd { EditUserMenu, /// Alt-P — reformat the paragraph at the cursor. FormatParagraph, + /// Alt-Shift-A — select all text. + MarkAll, + /// Insert contents of another file at the cursor. + InsertFile, + /// Save the current selection to a different file. + BlockSave, + /// Close the current buffer (keep editor open). + Close, } /// Outcome of a menu-bar key press. @@ -189,6 +197,10 @@ impl EditorMenuBar { MenuItem::item("Save", 's', EditorCmd::Save), MenuItem::item("Save as...", 'a', EditorCmd::SaveAs), MenuItem::separator(), + MenuItem::item("Insert file...", 'i', EditorCmd::InsertFile), + MenuItem::item("Save block as...", 'k', EditorCmd::BlockSave), + MenuItem::separator(), + MenuItem::item("Close", 'c', EditorCmd::Close), MenuItem::item("Quit", 'q', EditorCmd::Quit), ], ), @@ -201,6 +213,8 @@ impl EditorMenuBar { MenuItem::item("Cut", 'x', EditorCmd::Cut), MenuItem::item("Copy", 'c', EditorCmd::Copy), MenuItem::item("Paste", 'v', EditorCmd::Paste), + MenuItem::separator(), + MenuItem::item("Select all", 'a', EditorCmd::MarkAll), ], ), Menu::new( @@ -598,7 +612,7 @@ mod tests { assert_eq!(m.menu_count(), 7); assert_eq!( m.active_items().len(), - 7 // File menu has 7 entries + 11 // File menu: New, Open, sep, Save, SaveAs, sep, InsertFile, BlockSave, sep, Close, Quit ); } diff --git a/local/recipes/tui/tlc/source/src/editor/mod.rs b/local/recipes/tui/tlc/source/src/editor/mod.rs index 61ac391b77..3bea5c047f 100644 --- a/local/recipes/tui/tlc/source/src/editor/mod.rs +++ b/local/recipes/tui/tlc/source/src/editor/mod.rs @@ -1525,6 +1525,33 @@ impl Editor { *self = new_editor; self.message = Some(format!("Editing user menu: {}", path.display())); } + EditorCmd::MarkAll => { + let len = self.buffer.len(); + self.cursor.set_position(0, &self.buffer); + self.cursor.start_selection(); + self.cursor.set_position(len, &self.buffer); + } + EditorCmd::InsertFile => { + self.prompt_input.clear(); + self.mode = Mode::Prompt(PromptKind::InsertFile); + } + EditorCmd::BlockSave => { + if let Some(text) = self.cursor.selected_text(&self.buffer) { + self.prompt_input.clear(); + self.prompt_input.text = text; + self.prompt_input.cursor = self.prompt_input.text.chars().count(); + self.mode = Mode::Prompt(PromptKind::SaveAs); + } else { + self.message = Some("No selection".to_string()); + } + } + EditorCmd::Close => { + if self.modified { + self.mode = Mode::Prompt(PromptKind::SaveBeforeClose); + } else { + *self = Self::new_empty(); + } + } _ => { self.message = Some(format!("F9: {:?} (not yet wired)", cmd)); }