From 563a377f6b5da578673f7c645d6f904505148cc1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 20 Apr 2020 21:39:07 +0200 Subject: [PATCH] LibGUI: Fix unpleasant selection behavior when dragging far to the left If you select some text and drag the cursor outside the widget on the left hand side, we would previously suddenly snap the selection cursor to the end of the line instead of keeping it at the start of the line as you would expect. This patch fixes that. :^) --- Libraries/LibGUI/TextEditor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index a79163a0c9..967ab401ec 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -163,7 +163,10 @@ TextPosition TextEditor::text_position_at(const Gfx::Point& a_position) const size_t column_index; switch (m_text_alignment) { case Gfx::TextAlignment::CenterLeft: - column_index = (position.x() + glyph_width() / 2) / glyph_width(); + if (position.x() <= 0) + column_index = 0; + else + column_index = (position.x() + glyph_width() / 2) / glyph_width(); if (is_line_wrapping_enabled()) { for_each_visual_line(line_index, [&](const Gfx::Rect& rect, const StringView&, size_t start_of_line) { if (rect.contains_vertically(position.y())) {