mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-05 00:21:52 +00:00
LibWeb: Avoid more unnecessary relayouts on CharacterData text change
If the CharacterData node has no layout node when we're changing its text, we don't need to mark the document for relayout. This is fine, because if the node ends up getting a layout node attached to it, we'll naturally perform relayout after that anyway.
This commit is contained in:
parent
267b84ebb6
commit
6c6f9936e2
Notes:
github-actions[bot]
2025-03-08 02:38:39 +00:00
Author: https://github.com/awesomekling
Commit: 6c6f9936e2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3852
1 changed files with 8 additions and 5 deletions
|
@ -140,13 +140,16 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
|
|||
if (characters_are_the_same)
|
||||
return {};
|
||||
|
||||
// NOTE: Since the text node's data has changed, we need to invalidate the text for rendering.
|
||||
// This ensures that the new text is reflected in layout, even if we don't end up
|
||||
// doing a full layout tree rebuild.
|
||||
if (auto* layout_node = this->layout_node(); layout_node && layout_node->is_text_node())
|
||||
if (auto* layout_node = this->layout_node(); layout_node && layout_node->is_text_node()) {
|
||||
// NOTE: Since the text node's data has changed, we need to invalidate the text for rendering.
|
||||
// This ensures that the new text is reflected in layout, even if we don't end up
|
||||
// doing a full layout tree rebuild.
|
||||
static_cast<Layout::TextNode&>(*layout_node).invalidate_text_for_rendering();
|
||||
|
||||
document().set_needs_layout(SetNeedsLayoutReason::CharacterDataReplaceData);
|
||||
// We also need to relayout.
|
||||
document().set_needs_layout(SetNeedsLayoutReason::CharacterDataReplaceData);
|
||||
}
|
||||
|
||||
document().bump_character_data_version();
|
||||
|
||||
if (m_grapheme_segmenter)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue