diff options
author | lucastarche <lucastarche@gmail.com> | 2021-03-17 13:52:42 -0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-25 11:01:49 +0100 |
commit | 6d3d0978324944d910cbacca574b27d43eaec490 (patch) | |
tree | 3b28950cd57d308b9320d8fc28010c207ef12501 /Userland/Libraries/LibGUI | |
parent | f6892d1ede29a8627cc06263cfbe8b554210e11d (diff) | |
download | serenity-6d3d0978324944d910cbacca574b27d43eaec490.zip |
TextEditor: Visualize leading whitespace
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.cpp | 23 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.h | 4 |
2 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 8e39173d2c..b9d804b944 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -640,6 +640,21 @@ void TextEditor::paint_event(PaintEvent& event) } } + if (m_visualize_leading_whitespace && line.leading_spaces() > 0) { + size_t physical_column = line.leading_spaces(); + size_t end_of_leading_whitespace = (start_of_visual_line + physical_column); + size_t end_of_visual_line = (start_of_visual_line + visual_line_text.length()); + if (end_of_leading_whitespace < end_of_visual_line) { + Gfx::IntRect whitespace_rect { + content_x_for_position({ line_index, start_of_visual_line }), + visual_line_rect.y(), + font().width(visual_line_text.substring_view(0, end_of_leading_whitespace)), + visual_line_rect.height() + }; + painter.fill_rect_with_dither_pattern(whitespace_rect, Color(), Color(192, 255, 192)); + } + } + if (physical_line_has_selection) { size_t start_of_selection_within_visual_line = (size_t)max(0, (int)selection_start_column_within_line - (int)start_of_visual_line); size_t end_of_selection_within_visual_line = selection_end_column_within_line - start_of_visual_line; @@ -1764,6 +1779,14 @@ void TextEditor::set_visualize_trailing_whitespace(bool enabled) update(); } +void TextEditor::set_visualize_leading_whitespace(bool enabled) +{ + if (m_visualize_leading_whitespace == enabled) + return; + m_visualize_leading_whitespace = enabled; + update(); +} + void TextEditor::set_should_autocomplete_automatically(bool value) { if (value == should_autocomplete_automatically()) diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h index a841dd0982..3abb87b1d6 100644 --- a/Userland/Libraries/LibGUI/TextEditor.h +++ b/Userland/Libraries/LibGUI/TextEditor.h @@ -81,6 +81,9 @@ public: void set_visualize_trailing_whitespace(bool); bool visualize_trailing_whitespace() const { return m_visualize_trailing_whitespace; } + void set_visualize_leading_whitespace(bool); + bool visualize_leading_whitespace() const { return m_visualize_leading_whitespace; } + virtual bool is_automatic_indentation_enabled() const final { return m_automatic_indentation_enabled; } void set_automatic_indentation_enabled(bool enabled) { m_automatic_indentation_enabled = enabled; } @@ -319,6 +322,7 @@ private: bool m_automatic_indentation_enabled { false }; WrappingMode m_wrapping_mode { WrappingMode::NoWrap }; bool m_visualize_trailing_whitespace { true }; + bool m_visualize_leading_whitespace { false }; int m_line_spacing { 4 }; size_t m_soft_tab_width { 4 }; int m_horizontal_content_padding { 3 }; |