diff --git a/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp b/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp index 95895d8069..657b46db2b 100644 --- a/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -16,20 +17,20 @@ namespace Web { -void EditEventHandler::handle_delete_character_after(const DOM::Position& cursor_position) +void EditEventHandler::handle_delete_character_after(DOM::Position const& cursor_position) { - if (cursor_position.offset_is_at_end_of_node()) { + auto& node = *static_cast(const_cast(cursor_position.node())); + auto& text = node.data(); + + auto next_grapheme_offset = Unicode::next_grapheme_segmentation_boundary(Utf8View { text }, cursor_position.offset()); + if (!next_grapheme_offset.has_value()) { // FIXME: Move to the next node and delete the first character there. return; } - auto& node = *static_cast(const_cast(cursor_position.node())); - auto& text = node.data(); - auto code_point_length = Utf8View(text).iterator_at_byte_offset(cursor_position.offset()).underlying_code_point_length_in_bytes(); - StringBuilder builder; builder.append(text.substring_view(0, cursor_position.offset())); - builder.append(text.substring_view(cursor_position.offset() + code_point_length)); + builder.append(text.substring_view(*next_grapheme_offset)); node.set_data(builder.to_deprecated_string()); // FIXME: When nodes are removed from the DOM, the associated layout nodes become stale and still diff --git a/Userland/Libraries/LibWeb/Page/EditEventHandler.h b/Userland/Libraries/LibWeb/Page/EditEventHandler.h index 4091c3c096..20e2a889b9 100644 --- a/Userland/Libraries/LibWeb/Page/EditEventHandler.h +++ b/Userland/Libraries/LibWeb/Page/EditEventHandler.h @@ -20,7 +20,7 @@ public: virtual ~EditEventHandler() = default; - virtual void handle_delete_character_after(const DOM::Position&); + virtual void handle_delete_character_after(DOM::Position const&); virtual void handle_delete(DOM::Range&); virtual void handle_insert(DOM::Position, u32 code_point);