mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb: Clamp end offset in CharacterData::replace_data()
Makes this method to not fail if updating of start offset (which happens before update of the end offset) already moved end offset to the end of string on the following step: > 1. If range’s root is not equal to node’s root, or if bp is after the range’s end, set range’s end to bp.
This commit is contained in:
parent
da26941b50
commit
20852443d3
Notes:
github-actions[bot]
2024-10-30 18:31:04 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/20852443d38 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2024
1 changed files with 5 additions and 2 deletions
|
@ -112,8 +112,11 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
|
||||||
|
|
||||||
// 11. For each live range whose end node is node and end offset is greater than offset plus count, increase its end offset by data’s length and decrease it by count.
|
// 11. For each live range whose end node is node and end offset is greater than offset plus count, increase its end offset by data’s length and decrease it by count.
|
||||||
for (auto& range : Range::live_ranges()) {
|
for (auto& range : Range::live_ranges()) {
|
||||||
if (range->end_container() == this && range->end_offset() > (offset + count))
|
if (range->end_container() == this && range->end_offset() > (offset + count)) {
|
||||||
TRY(range->set_end(*range->end_container(), range->end_offset() + data.bytes().size() - count));
|
// AD-HOC: Clamp offset to the end of the data if it's too large.
|
||||||
|
auto new_offset = min(range->end_offset() + data.bytes().size() - count, m_data.bytes().size());
|
||||||
|
TRY(range->set_end(*range->end_container(), new_offset));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12. If node’s parent is non-null, then run the children changed steps for node’s parent.
|
// 12. If node’s parent is non-null, then run the children changed steps for node’s parent.
|
||||||
|
|
Loading…
Reference in a new issue