Files
ladybird/Tests/LibWeb/Text/input/selection-rect-with-letter-spacing.html
Jelle Raaijmakers 8654e2caf4 LibWeb: Apply letter-spacing for selection rects and grapheme bounds
Fixes the selection rect on the title text of https://modern-css.com/
being misaligned with the actual characters.
2026-02-17 10:51:48 +01:00

31 lines
727 B
HTML

<!DOCTYPE html>
<script src="include.js"></script>
<style>
p {
font-size: 48px;
letter-spacing: -.045em;
margin: 0;
}
</style>
<p>Stop writing CSS</p>
<script>
test(() => {
const p = document.querySelector("p");
const text = p.firstChild;
function rangeWidth(start, end) {
var range = document.createRange();
range.setStart(text, start);
range.setEnd(text, end);
return range.getBoundingClientRect().width;
}
var fullWidth = rangeWidth(0, text.length);
var firstHalf = rangeWidth(0, 8);
var secondHalf = rangeWidth(8, text.length);
println(`firstHalf + secondHalf: ${firstHalf + secondHalf}`);
println(`fullWidth: ${fullWidth}`);
});
</script>