mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibWeb: Improve hit testing on the right of line boxes
We now remember the last candidate fragment when hit testing past the right end of text and use that as the fallback result if nothing else matches. This makes it possible to drag-select outside the line boxes in a way that feels mostly natural. :^)
This commit is contained in:
parent
9177eea8fe
commit
301ac3c7e5
Notes:
sideshowbarker
2024-07-19 05:19:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/301ac3c7e5d
1 changed files with 5 additions and 3 deletions
|
@ -722,7 +722,7 @@ HitTestResult LayoutBlock::hit_test(const Gfx::IntPoint& position) const
|
|||
if (!children_are_inline())
|
||||
return LayoutBox::hit_test(position);
|
||||
|
||||
HitTestResult result;
|
||||
HitTestResult last_good_candidate;
|
||||
for (auto& line_box : m_line_boxes) {
|
||||
for (auto& fragment : line_box.fragments()) {
|
||||
if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) {
|
||||
|
@ -730,11 +730,13 @@ HitTestResult LayoutBlock::hit_test(const Gfx::IntPoint& position) const
|
|||
return to<LayoutBlock>(fragment.layout_node()).hit_test(position);
|
||||
return { fragment.layout_node(), fragment.text_index_at(position.x()) };
|
||||
}
|
||||
if (fragment.absolute_rect().top() <= position.y())
|
||||
last_good_candidate = { fragment.layout_node(), fragment.text_index_at(position.x()) };
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: This should be smarter about the text position if we're hitting a block
|
||||
// that has text inside it, but `position` is to the right of the text box.
|
||||
if (last_good_candidate.layout_node)
|
||||
return last_good_candidate;
|
||||
return { absolute_rect().contains(position.x(), position.y()) ? this : nullptr };
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue