Skip to content

Commit

Permalink
LibWeb: Fix "incorrect behavior on select()" LadybirdBrowser#1446
Browse files Browse the repository at this point in the history
This patch resolves the problem outlined in issue LadybirdBrowser#1446, where the
cursor_position node could be substituted with any other existing
node by the mousedown event. Previously, if this new node was not
equal to m_text_node, the function would return prematurely without
updating the selection.

With this fix, we ensure that the selection is properly updated in
such cases, rather than simply exiting the function.
  • Loading branch information
An-n-ya committed Sep 20, 2024
1 parent 5ac0e81 commit e25160f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@ HTMLInputElement::ValueAttributeMode HTMLInputElement::value_attribute_mode() co

void HTMLInputElement::selection_was_changed(size_t selection_start, size_t selection_end)
{
if (!m_text_node || !document().cursor_position() || document().cursor_position()->node() != m_text_node)
if (!m_text_node)
return;

document().set_cursor_position(DOM::Position::create(realm(), *m_text_node, selection_end));
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void HTMLTextAreaElement::queue_firing_input_event()

void HTMLTextAreaElement::selection_was_changed(size_t selection_start, size_t selection_end)
{
if (!m_text_node || !document().cursor_position() || document().cursor_position()->node() != m_text_node)
if (!m_text_node)
return;

document().set_cursor_position(DOM::Position::create(realm(), *m_text_node, selection_end));
Expand Down

0 comments on commit e25160f

Please sign in to comment.