summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2022-02-10 18:22:44 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-28 14:00:27 +0100
commit1172fd682ac48c7d7f132c7ff2532c51898a3552 (patch)
tree6c814c3ff57c9fffe5bb8fb1702813c0d468095d /Userland
parent9c2e89e8b8be2c2923b76c38c7f1fd316e6a8b18 (diff)
downloadserenity-1172fd682ac48c7d7f132c7ff2532c51898a3552.zip
TextEditor: Support multiline highlighting for trailing space
The last commit fixes a bug, but also exposes the fact that trailing space highlighting isn't really supported on multiple lines. This patch correct the wrong behavior by adding an offset to adjust rectangle's position.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index ee1a72f092..486321240a 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -512,7 +512,11 @@ void TextEditor::paint_event(PaintEvent& event)
size_t selection_end_column_within_line = selection.end().line() == line_index ? selection.end().column() : line.length();
size_t visual_line_index = 0;
+ size_t last_start_of_visual_line = 0;
+ Optional<size_t> multiline_trailing_space_offset {};
for_each_visual_line(line_index, [&](Gfx::IntRect const& visual_line_rect, auto& visual_line_text, size_t start_of_visual_line, [[maybe_unused]] bool is_last_visual_line) {
+ ScopeGuard update_last_start_of_visual_line { [&]() { last_start_of_visual_line = start_of_visual_line; } };
+
if (is_focused() && is_multi_line() && line_index == m_cursor.line() && is_cursor_line_highlighted()) {
Gfx::IntRect visible_content_line_rect {
visible_content_rect().x(),
@@ -650,7 +654,10 @@ void TextEditor::paint_event(PaintEvent& event)
physical_column = 0;
size_t end_of_visual_line = (start_of_visual_line + visual_line_text.length());
if (physical_column < end_of_visual_line) {
+ physical_column -= multiline_trailing_space_offset.value_or(0);
+
size_t visual_column = physical_column > start_of_visual_line ? (physical_column - start_of_visual_line) : 0;
+
Gfx::IntRect whitespace_rect {
content_x_for_position({ line_index, physical_column }),
visual_line_rect.y(),
@@ -658,6 +665,9 @@ void TextEditor::paint_event(PaintEvent& event)
visual_line_rect.height()
};
painter.fill_rect_with_dither_pattern(whitespace_rect, Color(), Color(255, 192, 192));
+
+ if (!multiline_trailing_space_offset.has_value())
+ multiline_trailing_space_offset = physical_column - last_start_of_visual_line;
}
}
if (m_visualize_leading_whitespace && line.leading_spaces() > 0) {