LibWeb: Resolve Unicode FIXME in forwardDelete

This commit is contained in:
Jelle Raaijmakers 2025-09-15 12:11:22 +02:00 committed by Tim Flynn
commit b51cc00478
Notes: github-actions[bot] 2025-09-16 10:58:54 +00:00
3 changed files with 14 additions and 4 deletions

View file

@ -123,6 +123,11 @@ bool code_point_has_letter_general_category(u32 code_point)
return code_point_has_general_category(code_point, GENERAL_CATEGORY_LETTER);
}
bool code_point_has_mark_general_category(u32 code_point)
{
return code_point_has_general_category(code_point, GENERAL_CATEGORY_MARK);
}
bool code_point_has_number_general_category(u32 code_point)
{
return code_point_has_general_category(code_point, GENERAL_CATEGORY_NUMBER);

View file

@ -8,7 +8,6 @@
#include <AK/Forward.h>
#include <AK/Optional.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <LibUnicode/Forward.h>
@ -20,6 +19,7 @@ bool code_point_has_general_category(u32 code_point, GeneralCategory general_cat
bool code_point_is_printable(u32 code_point);
bool code_point_has_control_general_category(u32 code_point);
bool code_point_has_letter_general_category(u32 code_point);
bool code_point_has_mark_general_category(u32 code_point);
bool code_point_has_number_general_category(u32 code_point);
bool code_point_has_punctuation_general_category(u32 code_point);
bool code_point_has_separator_general_category(u32 code_point);

View file

@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibUnicode/CharacterTypes.h>
#include <LibUnicode/Segmenter.h>
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
#include <LibWeb/DOM/Comment.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentFragment.h>
@ -935,10 +935,15 @@ bool command_forward_delete_action(DOM::Document& document, Utf16String const&)
// 5. If node is a Text node and offset is not node's length:
if (auto const* text_node = as_if<DOM::Text>(*node); text_node && offset != node->length()) {
// 1. Let end offset be offset plus one.
auto end_offset = text_node->grapheme_segmenter().next_boundary(offset).value_or(offset + 1);
auto& grapheme_segmenter = text_node->grapheme_segmenter();
auto end_offset = grapheme_segmenter.next_boundary(offset).value_or(offset + 1);
// FIXME: 2. While end offset is not node's length and the end offsetth code unit of node's data has general category M
// 2. While end offset is not node's length and the end offsetth code unit of node's data has general category M
// when interpreted as a Unicode code point, add one to end offset.
while (end_offset != node->length()
&& Unicode::code_point_has_mark_general_category(text_node->data().code_point_at(end_offset))) {
end_offset = grapheme_segmenter.next_boundary(end_offset).value_or(end_offset + 1);
}
// 3. Call collapse(node, offset) on the context object's selection.
MUST(selection.collapse(node, offset));