From 9d74659f3bf27af8ff4ce4484842e1bffbe9abcc Mon Sep 17 00:00:00 2001 From: Young-Jin Park Date: Mon, 27 Dec 2021 03:31:05 -0800 Subject: [PATCH] LibGUI: Fix leading whitespaces when text is wrapped This commit should fix a bug where using leading whitespaces when a line is wrapped results in a crash. Now it should correctly highlight the leading whitespaces even when the leading whitespaces are longer than a line. --- Userland/Libraries/LibGUI/TextEditor.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index e1e5c5c427..14bcdac140 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -653,12 +653,10 @@ void TextEditor::paint_event(PaintEvent& event) painter.fill_rect_with_dither_pattern(whitespace_rect, Color(), Color(255, 192, 192)); } } - 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) { + if (start_of_visual_line < physical_column) { + size_t end_of_leading_whitespace = min(physical_column - start_of_visual_line, visual_line_text.length()); Gfx::IntRect whitespace_rect { content_x_for_position({ line_index, start_of_visual_line }), visual_line_rect.y(),