W50: Editor MarkAll, InsertFile, BlockSave, Close commands
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.
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user