mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 19:55:06 +00:00
LibWeb: Update the document's cursor after setting an <input>'s value
The spec step here explicitly says to "move the text entry cursor position to the end of the text control".
This commit is contained in:
parent
d5d6f9bc92
commit
7e92ff062e
1 changed files with 6 additions and 1 deletions
|
@ -371,11 +371,13 @@ String HTMLInputElement::value() const
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> HTMLInputElement::set_value(String const& value)
|
WebIDL::ExceptionOr<void> HTMLInputElement::set_value(String const& value)
|
||||||
{
|
{
|
||||||
|
auto& realm = this->realm();
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/input.html#dom-input-value-filename
|
// https://html.spec.whatwg.org/multipage/input.html#dom-input-value-filename
|
||||||
if (type_state() == TypeAttributeState::FileUpload) {
|
if (type_state() == TypeAttributeState::FileUpload) {
|
||||||
// On setting, if the new value is the empty string, empty the list of selected files; otherwise, throw an "InvalidStateError" DOMException.
|
// On setting, if the new value is the empty string, empty the list of selected files; otherwise, throw an "InvalidStateError" DOMException.
|
||||||
if (!value.is_empty())
|
if (!value.is_empty())
|
||||||
return WebIDL::InvalidStateError::create(realm(), "Setting value of input type file to non-empty string"_fly_string);
|
return WebIDL::InvalidStateError::create(realm, "Setting value of input type file to non-empty string"_fly_string);
|
||||||
m_selected_files = nullptr;
|
m_selected_files = nullptr;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -401,6 +403,9 @@ WebIDL::ExceptionOr<void> HTMLInputElement::set_value(String const& value)
|
||||||
if (m_text_node && (m_value != old_value)) {
|
if (m_text_node && (m_value != old_value)) {
|
||||||
m_text_node->set_data(m_value);
|
m_text_node->set_data(m_value);
|
||||||
update_placeholder_visibility();
|
update_placeholder_visibility();
|
||||||
|
|
||||||
|
if (auto* browsing_context = document().browsing_context())
|
||||||
|
browsing_context->set_cursor_position(DOM::Position::create(realm, *m_text_node, m_text_node->data().bytes().size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue