wpt / selection / selection-range-painting-after-splitText.html?splitAt=3

Open test on wpt.live | Open ref on wpt.live | wpt.fyi

Runs: Chrome 158.0.8110.0 (wpt@5ffee20ed, 2026-10-17) | Firefox 160.0a1 (wpt@d8b153fad, 2026-10-16) | Safari 254 preview (wpt@51a43ba4a, 2026-10-17) | Ladybird 1.0-401b1 (wpt@470a7adf8, 2026-10-17) | Servo Servo 0.7 (wpt@df642c414, 2026-10-17) | Blitz fb8d6c15e (wpt@cd1d8aa5b, 2026-10-17)

ChromeFirefoxSafariLadybirdServoBlitz
Total1/11/10/11/11/1NOT RUN

/selection/selection-range-painting-after-splitText.html

<!doctype html>
<html class="reftest-wait">
<head>
<meta charset="utf-8">
<meta name="variant" content="?splitAt=1"><!-- A | B[CDEFG]HI -->
<meta name="variant" content="?splitAt=2"><!-- AB[ | CDEFG]HI -->
<meta name="variant" content="?splitAt=3"><!-- AB[C | DEFG]HI -->
<meta name="variant" content="?splitAt=6"><!-- AB[CDEF | G]HI -->
<meta name="variant" content="?splitAt=7"><!-- AB[CDEFG] | HI -->
<meta name="variant" content="?splitAt=8"><!-- AB[CDEFG]H | I -->
<link rel="match" href="selection-range-painting-after-splitText-ref.html">
<title>Selection painting after Text.splitText() call</title>
<script>
"use strict";

addEventListener("DOMContentLoaded", async () => {
  const link = document.querySelector("link[rel=match]");
  link.href += location.search;
  const text = document.querySelector("p").firstChild;
  getSelection().setBaseAndExtent(text, "AB".length, text, "ABCDEFG".length);
  await new Promise(resolve => {
    requestAnimationFrame(() => requestAnimationFrame(resolve))
  });
  const splitAt = parseInt((new URLSearchParams(location.search)).get("splitAt"));
  text.splitText(splitAt);
  document.documentElement.removeAttribute("class");
}, {once: true});
</script>
</head>
<body>
  <p>ABCDEFGHI</p>
</body>
</html>

/selection/selection-range-painting-after-splitText-ref.html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Selection painting result when "CDEFG" is selected</title>
<script>
"use strict";

addEventListener("DOMContentLoaded", async () => {
  const text = document.querySelector("p").firstChild;
  const splitAt = parseInt((new URLSearchParams(location.search)).get("splitAt"));
  const newText = text.splitText(splitAt);
  const [startContainer, startOffset] = (function() {
    if (splitAt > "AB".length) {
      return [text, "AB".length];
    }
    return [newText, "AB".length - splitAt];
  })();
  const [endContainer, endOffset] = (function() {
    if (splitAt > "ABCDEFG".length) {
      return [text, "ABCDEFG".length];
    }
    return [newText, "ABCDEFG".length - splitAt];
  })();
  getSelection().setBaseAndExtent(startContainer, startOffset, endContainer, endOffset);
}, {once: true});
</script>
</head>
<body>
  <p>ABCDEFGHI</p>
</body>
</html>