فهرست منبع

LibWeb: Use correct offset value when replacing character data

Previously, the range's end offset was being set using it's previous
value.
Tim Ledbetter 1 سال پیش
والد
کامیت
0577a664dd

+ 1 - 0
Tests/LibWeb/Text/expected/DOM/Delete-from-text-node-with-associated-range.txt

@@ -0,0 +1 @@
+foo

+ 15 - 0
Tests/LibWeb/Text/input/DOM/Delete-from-text-node-with-associated-range.html

@@ -0,0 +1,15 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        const text = new Text("foobar");
+
+        const range = document.createRange();
+        range.setEnd(text, 5);
+        
+        text.deleteData(5, 1);
+        text.deleteData(4, 1);
+        text.deleteData(3, 1);
+
+        println(text.data);
+    })
+</script>

+ 1 - 1
Userland/Libraries/LibWeb/DOM/CharacterData.cpp

@@ -98,7 +98,7 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
     // 9. For each live range whose end node is node and end offset is greater than offset but less than or equal to offset plus count, set its end offset to offset.
     // 9. For each live range whose end node is node and end offset is greater than offset but less than or equal to offset plus count, set its end offset to offset.
     for (auto& range : Range::live_ranges()) {
     for (auto& range : Range::live_ranges()) {
         if (range->end_container() == this && range->end_offset() > offset && range->end_offset() <= (offset + count))
         if (range->end_container() == this && range->end_offset() > offset && range->end_offset() <= (offset + count))
-            TRY(range->set_end(*range->end_container(), range->end_offset()));
+            TRY(range->set_end(*range->end_container(), offset));
     }
     }
 
 
     // 10. For each live range whose start node is node and start offset is greater than offset plus count, increase its start offset by data’s length and decrease it by count.
     // 10. For each live range whose start node is node and start offset is greater than offset plus count, increase its start offset by data’s length and decrease it by count.