mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
TextEditor: Visualize leading whitespace
This commit is contained in:
parent
f6892d1ede
commit
6d3d097832
Notes:
sideshowbarker
2024-07-18 21:05:57 +09:00
Author: https://github.com/lucastarche Commit: https://github.com/SerenityOS/serenity/commit/6d3d0978324 Pull-request: https://github.com/SerenityOS/serenity/pull/5859
@ -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())
|
||||
|
@ -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 };
|
||||
|
Loading…
Reference in New Issue
Block a user