LibWeb: Only set the editable text cursor position if necessary
When the user clicks on a text node, the event handler sets the cursor position to the location that was clicked. But it would then be set back to 0 in the DOM node's focus handler. Leave the cursor alone, unless the the DOM node was never set as the cursor position node (which will occur when the user clicks on the DOM node, but outside the shadow text node). In that case, move the cursor to the end of the text node. The end result here is that the cursor is placed where the user clicked, or set to the end of node if the user clicked outside of the shadow text node.
This commit is contained in:
parent
48e5d28ec9
commit
fc37c4ad40
Notes:
github-actions[bot]
2024-09-08 07:48:34 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/fc37c4ad40b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1320
2 changed files with 4 additions and 2 deletions
|
@ -1147,7 +1147,8 @@ void HTMLInputElement::did_receive_focus()
|
|||
if (m_placeholder_text_node)
|
||||
m_placeholder_text_node->invalidate_style(DOM::StyleInvalidationReason::DidReceiveFocus);
|
||||
|
||||
document().set_cursor_position(DOM::Position::create(realm(), *m_text_node, 0));
|
||||
if (auto cursor = document().cursor_position(); !cursor || m_text_node != cursor->node())
|
||||
document().set_cursor_position(DOM::Position::create(realm(), *m_text_node, m_text_node->length()));
|
||||
}
|
||||
|
||||
void HTMLInputElement::did_lose_focus()
|
||||
|
|
|
@ -77,7 +77,8 @@ void HTMLTextAreaElement::did_receive_focus()
|
|||
if (m_placeholder_text_node)
|
||||
m_placeholder_text_node->invalidate_style(DOM::StyleInvalidationReason::DidReceiveFocus);
|
||||
|
||||
document().set_cursor_position(DOM::Position::create(realm(), *m_text_node, 0));
|
||||
if (auto cursor = document().cursor_position(); !cursor || m_text_node != cursor->node())
|
||||
document().set_cursor_position(DOM::Position::create(realm(), *m_text_node, 0));
|
||||
}
|
||||
|
||||
void HTMLTextAreaElement::did_lose_focus()
|
||||
|
|
Loading…
Add table
Reference in a new issue