diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-20 21:39:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-20 21:39:07 +0200 |
commit | 563a377f6b5da578673f7c645d6f904505148cc1 (patch) | |
tree | 19965db17388c2f061100dc2b50f6112e4da152a | |
parent | 5c15c249769e0f854d43734bf7841eaed3a0ae26 (diff) | |
download | serenity-563a377f6b5da578673f7c645d6f904505148cc1.zip |
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. :^)
-rw-r--r-- | Libraries/LibGUI/TextEditor.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
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())) { |