TextEditor: Implement word wrapping

Add a new wrapping mode to the TextEditor that will wrap lines at the
spaces between words.

Replace the previous menubar checkbox 'Wrapping Mode' in HackStudio and
the TextEditor with an exclusive submenu which allows switching between
'No wrapping', 'Wrap anywhere' and 'Wrap at words'. 'Wrap anywhere' (the
new 'Wrap lines') is still the default mode.

Setting the wrapping mode in the constructors of the TextEditorWidget
and HackStudio has been removed, it is now set when constructing the
menubar actions.
This commit is contained in:
Zac 2021-01-09 22:47:48 +10:00 committed by Andreas Kling
commit cc2f35badd
Notes: sideshowbarker 2024-07-18 22:36:50 +09:00
8 changed files with 105 additions and 41 deletions

View file

@ -875,13 +875,30 @@ void HackStudioWidget::create_edit_menubar(GUI::MenuBar& menubar)
edit_menu.add_separator();
auto line_wrapping_action = GUI::Action::create_checkable("Line wrapping", [this](auto& action) {
for (auto& wrapper : m_all_editor_wrappers) {
wrapper.editor().set_line_wrapping_enabled(action.is_checked());
}
m_wrapping_mode_actions.set_exclusive(true);
auto& wrapping_mode_menu = edit_menu.add_submenu("Wrapping mode");
m_no_wrapping_action = GUI::Action::create_checkable("No wrapping", [&](auto&) {
for (auto& wrapper : m_all_editor_wrappers)
wrapper.editor().set_wrapping_mode(GUI::TextEditor::WrappingMode::NoWrap);
});
line_wrapping_action->set_checked(current_editor().is_line_wrapping_enabled());
edit_menu.add_action(line_wrapping_action);
m_wrap_anywhere_action = GUI::Action::create_checkable("Wrap anywhere", [&](auto&) {
for (auto& wrapper : m_all_editor_wrappers)
wrapper.editor().set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAnywhere);
});
m_wrap_at_words_action = GUI::Action::create_checkable("Wrap at words", [&](auto&) {
for (auto& wrapper : m_all_editor_wrappers)
wrapper.editor().set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAtWords);
});
m_wrapping_mode_actions.add_action(*m_no_wrapping_action);
m_wrapping_mode_actions.add_action(*m_wrap_anywhere_action);
m_wrapping_mode_actions.add_action(*m_wrap_at_words_action);
wrapping_mode_menu.add_action(*m_no_wrapping_action);
wrapping_mode_menu.add_action(*m_wrap_anywhere_action);
wrapping_mode_menu.add_action(*m_wrap_at_words_action);
m_wrap_anywhere_action->set_checked(true);
edit_menu.add_separator();