From 881f4997047ccb98447700503b065216d31abeab Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sun, 24 Apr 2022 18:26:34 +0200 Subject: [PATCH] LibGUI: Fix text wrap artifact when selecting text The issue was caused by the usage of the selection_end_column_within_line variable as if it was the visual line. This is fixed by taking the minimum between this value and the length of a visual line. --- Userland/Libraries/LibGUI/TextEditor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 93cf86c055..5e4ef18e4b 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -686,8 +686,8 @@ void TextEditor::paint_event(PaintEvent& event) } if (physical_line_has_selection && window()->focused_widget() == this) { - 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 const start_of_selection_within_visual_line = (size_t)max(0, (int)selection_start_column_within_line - (int)start_of_visual_line); + size_t const end_of_selection_within_visual_line = min(selection_end_column_within_line - start_of_visual_line, visual_line_text.length()); bool current_visual_line_has_selection = start_of_selection_within_visual_line != end_of_selection_within_visual_line && ((line_index != selection.start().line() && line_index != selection.end().line())