1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:47:35 +00:00

LibWeb: Return the position at end-of-line in TextCursor hit-test

When starting to drag the cursor below the text, we would start the
selection from the closest point in the line above in the last
fragment. This is not the behavior seen in other browsers, and it
causes weird behavior when the cursor is to the left of the last
fragment, for instances when trying to select with the text
`before <span>middle</span> after`.

By starting the selection from the _end_ of the last fragment,
including the line end character, selection behavior is similar to
that of other browsers.
This commit is contained in:
Andreas Oppebøen 2022-11-29 09:32:36 +01:00 committed by Sam Atkins
parent 44ef0ac41c
commit ad25a415ae

View file

@ -700,7 +700,7 @@ Optional<HitTestResult> PaintableWithLines::hit_test(Gfx::FloatPoint const& posi
return HitTestResult { *fragment.layout_node().paintable(), fragment.text_index_at(position.x()) };
}
if (fragment_absolute_rect.top() <= position.y())
last_good_candidate = HitTestResult { *fragment.layout_node().paintable(), fragment.text_index_at(position.x()) };
last_good_candidate = HitTestResult { *fragment.layout_node().paintable(), fragment.length() + 1 };
}
}