LibWeb: Return correct selection_rect when the node is at the end

When the selection state of the node is SelectionState::End, the end
position of the selection within the fragment is not properly
calculated, because it forgets to subtract m_start from index_in_node,
unlike SelectionState::StartAndEnd. This resulted in a wrong selection
shadow being painted when the node is at the end of the selection.

This change resolves #5880.
This commit is contained in:
Tetsui Ohkubo 2021-08-11 22:30:38 +09:00 committed by Andreas Kling
parent c27abaabc4
commit 2edf4b7f61
Notes: sideshowbarker 2024-07-18 05:39:49 +09:00

View file

@ -137,7 +137,7 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const
return {};
auto selection_start_in_this_fragment = 0;
auto selection_end_in_this_fragment = min(selection.end().index_in_node, m_length);
auto selection_end_in_this_fragment = min(selection.end().index_in_node - m_start, m_length);
auto pixel_distance_to_first_selected_character = font.width(text.substring_view(0, selection_start_in_this_fragment));
auto pixel_width_of_selection = font.width(text.substring_view(selection_start_in_this_fragment, selection_end_in_this_fragment - selection_start_in_this_fragment)) + 1;