1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

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
parent db1c6cf9cf
commit cc2f35badd
8 changed files with 105 additions and 41 deletions

View file

@ -56,6 +56,12 @@ public:
DisplayOnly
};
enum WrappingMode {
NoWrap,
WrapAnywhere,
WrapAtWords
};
virtual ~TextEditor() override;
const TextDocument& document() const { return *m_document; }
@ -80,8 +86,9 @@ public:
virtual int soft_tab_width() const final { return m_soft_tab_width; }
bool is_line_wrapping_enabled() const { return m_line_wrapping_enabled; }
void set_line_wrapping_enabled(bool);
WrappingMode wrapping_mode() const { return m_wrapping_mode; }
bool is_wrapping_enabled() const { return m_wrapping_mode != WrappingMode::NoWrap; }
void set_wrapping_mode(WrappingMode);
Gfx::TextAlignment text_alignment() const { return m_text_alignment; }
void set_text_alignment(Gfx::TextAlignment);
@ -299,7 +306,7 @@ private:
bool m_ruler_visible { false };
bool m_has_pending_change_notification { false };
bool m_automatic_indentation_enabled { false };
bool m_line_wrapping_enabled { false };
WrappingMode m_wrapping_mode { WrappingMode::WrapAnywhere };
bool m_has_visible_list { false };
bool m_visualize_trailing_whitespace { true };
int m_line_spacing { 4 };