mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-23 16:40:03 +00:00
We generated `PaintableFragment`s with a start and length represented in UTF-8 byte offsets, but failed to consider that the offsets in a `DOM::Range` are actually expressed in UTF-16 code units. This is a bit of a mess: almost all web specs use UTF-16 code units as the unit for indexing into text nodes, but we almost exclusively use UTF-8 in our code base. Arguably the best thing would for us to use UTF-16 everywhere as well: it prevents these mismatches in our implementations for the price of a bit more memory usage - and even that could potentially be optimized for. But for now, try to do the correct thing and lazily allocate UTF-16 data in a `PaintableFragment` whenever we need to index into it or if we're asked to determine the code unit offset of a pixel position.
15 lines
399 B
HTML
15 lines
399 B
HTML
<!DOCTYPE html>
|
|
<script src="include.js"></script>
|
|
😭foobar😭
|
|
<script>
|
|
test(() => {
|
|
internals.mouseDown(55, 20);
|
|
internals.movePointerTo(110, 20);
|
|
|
|
const activeRange = window.getSelection().getRangeAt(0);
|
|
printElement(activeRange.startContainer);
|
|
println(activeRange.startOffset);
|
|
printElement(activeRange.endContainer);
|
|
println(activeRange.endOffset);
|
|
});
|
|
</script>
|