LibWeb: Delete entire graphemes when the delete/backspace key is pressed

We currently delete a single code unit. If the user presses backspace on
a multi code point emoji, they are going to expect the entire emoji to
be removed. This now matches the behavior of Chrome and Firefox.
This commit is contained in:
Timothy Flynn 2025-08-14 15:25:19 -04:00 committed by Jelle Raaijmakers
commit c369f68eff
Notes: github-actions[bot] 2025-08-14 20:22:53 +00:00
8 changed files with 69 additions and 19 deletions

View file

@ -829,13 +829,12 @@ void FormAssociatedTextControlElement::handle_delete(DeleteDirection direction)
if (selection_start == selection_end) {
if (direction == DeleteDirection::Backward) {
if (selection_start > 0)
MUST(set_range_text({}, selection_start - 1, selection_end, Bindings::SelectionMode::End));
if (auto offset = text_node->grapheme_segmenter().previous_boundary(m_selection_end); offset.has_value())
selection_start = *offset;
} else {
if (selection_start < text_node->length_in_utf16_code_units())
MUST(set_range_text({}, selection_start, selection_end + 1, Bindings::SelectionMode::End));
if (auto offset = text_node->grapheme_segmenter().next_boundary(m_selection_end); offset.has_value())
selection_end = *offset;
}
return;
}
MUST(set_range_text({}, selection_start, selection_end, Bindings::SelectionMode::End));