mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-03 21:02:39 +02:00
LibWeb: Update the document cursor position when the selection changes
Otherwise, it looks a bit awkward where the cursor position does not update while the selection is elsewhere. Note that this requires passing along the raw selection positions from `set the selection range` to the elements. Otherwise, consider what will happen if we set the selection start and end to the same value. By going through the API accessor, we hit the case where the start and end are the same value, and return the document cursor position. This would mean the cursor position would not be updated. The test changes here more closely match what Firefox produces now. It is not a 100% match; the `select event fired` test case isn't right. The problem is the event fires for the input element, but we most recently focused the textarea element. Thus, when we retrieve the selection from the input element, we return the document's cursor position, which is actually in the textarea element. The fix will ultimately be to fully implement the following: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-textarea/input-cursor That is, each input / textarea element should separately track its own text cursor position. (cherry picked from commit fd289deb44e0fc26f54a133c637c136bf0716cd5)
This commit is contained in:
committed by
Nico Weber
parent
9f9c9c8bcb
commit
af3222b686
@@ -2385,13 +2385,15 @@ HTMLInputElement::ValueAttributeMode HTMLInputElement::value_attribute_mode() co
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
void HTMLInputElement::selection_was_changed()
|
||||
void HTMLInputElement::selection_was_changed(size_t selection_start, size_t selection_end)
|
||||
{
|
||||
document().set_cursor_position(DOM::Position::create(realm(), *m_text_node, selection_end));
|
||||
|
||||
auto selection = document().get_selection();
|
||||
if (!selection || selection->range_count() == 0)
|
||||
return;
|
||||
|
||||
MUST(selection->set_base_and_extent(*m_text_node, selection_start().value(), *m_text_node, selection_end().value()));
|
||||
MUST(selection->set_base_and_extent(*m_text_node, selection_start, *m_text_node, selection_end));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user