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. :^)
This commit is contained in:
Andreas Kling 2020-04-20 21:39:07 +02:00
parent 5c15c24976
commit 563a377f6b
Notes: sideshowbarker 2024-07-19 07:26:01 +09:00

View file

@ -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())) {