mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-05 08:31:51 +00:00
LibWeb: Do not insert "return" key presses into input element values
When the return key is pressed, we try to handle it as a commit action for input elements. However, we would then go on to actually insert the return key's code point (U+000D) into the input element. This would be sanitized out, but would leave the input element in a state where it thinks it has text to commit. This would result in a change event being fired when the return key is pressed multiple times in a row. We were also firing the beforeinput/input events twice for all return key presses. To fix this, this patch changes the input event target to signify if it actually handled the return key. If not (i.e. for textarea elements), only then do we insert the code point. We also must not fall through to the generic key handler, to avoid the repeated input events.
This commit is contained in:
parent
206ec6694c
commit
5f0f97b3cc
Notes:
github-actions[bot]
2025-03-22 16:29:13 +00:00
Author: https://github.com/trflynn89
Commit: 5f0f97b3cc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4036
8 changed files with 26 additions and 16 deletions
|
@ -781,17 +781,18 @@ void FormAssociatedTextControlElement::handle_delete(DeleteDirection direction)
|
|||
MUST(set_range_text(String {}, selection_start, selection_end, Bindings::SelectionMode::End));
|
||||
}
|
||||
|
||||
void FormAssociatedTextControlElement::handle_return_key()
|
||||
EventResult FormAssociatedTextControlElement::handle_return_key()
|
||||
{
|
||||
auto& html_element = form_associated_element_to_html_element();
|
||||
if (is<HTMLInputElement>(html_element)) {
|
||||
auto& input_element = static_cast<HTMLInputElement&>(html_element);
|
||||
if (auto* form = input_element.form()) {
|
||||
form->implicitly_submit_form().release_value_but_fixme_should_propagate_errors();
|
||||
return;
|
||||
}
|
||||
input_element.commit_pending_changes();
|
||||
}
|
||||
auto* input_element = as_if<HTMLInputElement>(form_associated_element_to_html_element());
|
||||
if (!input_element)
|
||||
return EventResult::Dropped;
|
||||
|
||||
if (auto* form = input_element->form())
|
||||
form->implicitly_submit_form().release_value_but_fixme_should_propagate_errors();
|
||||
else
|
||||
input_element->commit_pending_changes();
|
||||
|
||||
return EventResult::Handled;
|
||||
}
|
||||
|
||||
void FormAssociatedTextControlElement::collapse_selection_to_offset(size_t position)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue