mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 06:57:45 +00:00
LibWeb: Port CharacterData from DeprecatedString to String
The existing implementation has some pre-existing issues where it is incorrectly assumes that byte offsets are given through the IDL instead of UTF-16 code units. While making these changes, leave some FIXMEs for that.
This commit is contained in:
parent
3b12a13f17
commit
b603e860af
18 changed files with 87 additions and 81 deletions
|
@ -29,9 +29,9 @@ void EditEventHandler::handle_delete_character_after(DOM::Position const& cursor
|
|||
}
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(text.substring_view(0, cursor_position.offset()));
|
||||
builder.append(text.substring_view(*next_grapheme_offset));
|
||||
node.set_data(builder.to_deprecated_string());
|
||||
builder.append(text.bytes_as_string_view().substring_view(0, cursor_position.offset()));
|
||||
builder.append(text.bytes_as_string_view().substring_view(*next_grapheme_offset));
|
||||
node.set_data(MUST(builder.to_string()));
|
||||
|
||||
// FIXME: When nodes are removed from the DOM, the associated layout nodes become stale and still
|
||||
// remain in the layout tree. This has to be fixed, this just causes everything to be recomputed
|
||||
|
@ -49,10 +49,10 @@ void EditEventHandler::handle_delete(DOM::Range& range)
|
|||
|
||||
if (start == end) {
|
||||
StringBuilder builder;
|
||||
builder.append(start->data().substring_view(0, range.start_offset()));
|
||||
builder.append(end->data().substring_view(range.end_offset()));
|
||||
builder.append(start->data().bytes_as_string_view().substring_view(0, range.start_offset()));
|
||||
builder.append(end->data().bytes_as_string_view().substring_view(range.end_offset()));
|
||||
|
||||
start->set_data(builder.to_deprecated_string());
|
||||
start->set_data(MUST(builder.to_string()));
|
||||
} else {
|
||||
// Remove all the nodes that are fully enclosed in the range.
|
||||
HashTable<DOM::Node*> queued_for_deletion;
|
||||
|
@ -87,10 +87,10 @@ void EditEventHandler::handle_delete(DOM::Range& range)
|
|||
|
||||
// Join the start and end nodes.
|
||||
StringBuilder builder;
|
||||
builder.append(start->data().substring_view(0, range.start_offset()));
|
||||
builder.append(end->data().substring_view(range.end_offset()));
|
||||
builder.append(start->data().bytes_as_string_view().substring_view(0, range.start_offset()));
|
||||
builder.append(end->data().bytes_as_string_view().substring_view(range.end_offset()));
|
||||
|
||||
start->set_data(builder.to_deprecated_string());
|
||||
start->set_data(MUST(builder.to_string()));
|
||||
end->remove();
|
||||
}
|
||||
|
||||
|
@ -108,10 +108,10 @@ void EditEventHandler::handle_insert(DOM::Position position, u32 code_point)
|
|||
auto& node = verify_cast<DOM::Text>(*position.node());
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(node.data().substring_view(0, position.offset()));
|
||||
builder.append(node.data().bytes_as_string_view().substring_view(0, position.offset()));
|
||||
builder.append_code_point(code_point);
|
||||
builder.append(node.data().substring_view(position.offset()));
|
||||
node.set_data(builder.to_deprecated_string());
|
||||
builder.append(node.data().bytes_as_string_view().substring_view(position.offset()));
|
||||
node.set_data(MUST(builder.to_string()));
|
||||
|
||||
node.invalidate_style();
|
||||
}
|
||||
|
|
|
@ -772,7 +772,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
|
|||
}
|
||||
if (key == KeyCode::Key_End) {
|
||||
auto& node = *static_cast<DOM::Text*>(const_cast<DOM::Node*>(m_browsing_context->cursor_position().node()));
|
||||
m_browsing_context->set_cursor_position(DOM::Position { node, (unsigned)node.data().length() });
|
||||
m_browsing_context->set_cursor_position(DOM::Position { node, (unsigned)node.data().bytes().size() });
|
||||
return true;
|
||||
}
|
||||
if (!should_ignore_keydown_event(code_point)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue