tlc: wire editor Options menu toggles in F9 menubar

Add ToggleAutoIndent, ToggleShowWhitespace, ToggleWordWrap,
ToggleSyntax, ToggleRelativeLines to EditorCmd enum and dispatch
them through dispatch_editor_cmd. The Options menu now has all
five toggles alongside Settings, making them discoverable via F9
in addition to their Alt-key shortcuts.
This commit is contained in:
2026-07-05 03:16:37 +03:00
parent c0157fc30e
commit 9e2a2666e0
2 changed files with 63 additions and 3 deletions
@@ -67,6 +67,16 @@ pub enum EditorCmd {
GotoBottom,
/// Open settings dialog.
Settings,
/// Toggle auto-indent (Alt-A).
ToggleAutoIndent,
/// Toggle visible whitespace (Alt-E).
ToggleShowWhitespace,
/// Toggle word wrap (Alt-W).
ToggleWordWrap,
/// Toggle syntax highlighting (Ctrl-S).
ToggleSyntax,
/// Toggle relative line numbers (Alt-N).
ToggleRelativeLines,
}
/// Outcome of a menu-bar key press.
@@ -217,7 +227,15 @@ impl EditorMenuBar {
),
Menu::new(
"Options",
vec![MenuItem::item("Settings...", 's', EditorCmd::Settings)],
vec![
MenuItem::item("Settings...", 's', EditorCmd::Settings),
MenuItem::separator(),
MenuItem::item("Auto-indent", 'a', EditorCmd::ToggleAutoIndent),
MenuItem::item("Show whitespace", 'w', EditorCmd::ToggleShowWhitespace),
MenuItem::item("Word wrap", 'p', EditorCmd::ToggleWordWrap),
MenuItem::item("Syntax highlight", 'h', EditorCmd::ToggleSyntax),
MenuItem::item("Relative line numbers", 'r', EditorCmd::ToggleRelativeLines),
],
),
];
Self {
+44 -2
View File
@@ -952,9 +952,51 @@ bracket_flash: None,
self.prompt_input.clear();
self.mode = Mode::Prompt(PromptKind::GotoLine);
}
EditorCmd::ToggleAutoIndent => {
let on = self.toggle_auto_indent();
self.message = Some(if on {
"Auto-indent: ON".to_string()
} else {
"Auto-indent: OFF".to_string()
});
}
EditorCmd::ToggleShowWhitespace => {
let on = self.toggle_show_whitespace();
self.message = Some(if on {
"Show whitespace: ON".to_string()
} else {
"Show whitespace: OFF".to_string()
});
}
EditorCmd::ToggleWordWrap => {
let on = self.toggle_word_wrap();
self.message = Some(if on {
"Word wrap: ON".to_string()
} else {
"Word wrap: OFF".to_string()
});
}
EditorCmd::ToggleSyntax => {
self.syntax_enabled = !self.syntax_enabled;
self.message = Some(if self.syntax_enabled {
"Syntax: ON".to_string()
} else {
"Syntax: OFF".to_string()
});
}
EditorCmd::ToggleRelativeLines => {
self.relative_lines = !self.relative_lines;
self.message = Some(if self.relative_lines {
"Relative line numbers: ON".to_string()
} else {
"Relative line numbers: OFF".to_string()
});
}
EditorCmd::Settings => {
self.message = Some("Settings dialog (TBD)".to_string());
}
// Items not yet wired: New, Open, Save, SaveAs, Quit,
// Find, FindNext, FindPrev, Replace, BookmarkNext/Prev,
// GotoTop/Bottom, Settings.
// Find, FindNext, FindPrev, Replace, BookmarkNext/Prev.
_ => {
self.message = Some(format!("F9: {:?} (not yet wired)", cmd));
}