mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
TextEditor: Visualize leading whitespace
This commit is contained in:
parent
f6892d1ede
commit
6d3d097832
2 changed files with 27 additions and 0 deletions
|
@ -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) {
|
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 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;
|
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();
|
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)
|
void TextEditor::set_should_autocomplete_automatically(bool value)
|
||||||
{
|
{
|
||||||
if (value == should_autocomplete_automatically())
|
if (value == should_autocomplete_automatically())
|
||||||
|
|
|
@ -81,6 +81,9 @@ public:
|
||||||
void set_visualize_trailing_whitespace(bool);
|
void set_visualize_trailing_whitespace(bool);
|
||||||
bool visualize_trailing_whitespace() const { return m_visualize_trailing_whitespace; }
|
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; }
|
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; }
|
void set_automatic_indentation_enabled(bool enabled) { m_automatic_indentation_enabled = enabled; }
|
||||||
|
|
||||||
|
@ -319,6 +322,7 @@ private:
|
||||||
bool m_automatic_indentation_enabled { false };
|
bool m_automatic_indentation_enabled { false };
|
||||||
WrappingMode m_wrapping_mode { WrappingMode::NoWrap };
|
WrappingMode m_wrapping_mode { WrappingMode::NoWrap };
|
||||||
bool m_visualize_trailing_whitespace { true };
|
bool m_visualize_trailing_whitespace { true };
|
||||||
|
bool m_visualize_leading_whitespace { false };
|
||||||
int m_line_spacing { 4 };
|
int m_line_spacing { 4 };
|
||||||
size_t m_soft_tab_width { 4 };
|
size_t m_soft_tab_width { 4 };
|
||||||
int m_horizontal_content_padding { 3 };
|
int m_horizontal_content_padding { 3 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue