Skip to content

Commit 7b2b399

Browse files
authored
[css-highlight-api] Fix examples' Ranges (#6033)
* Fix examples 2 and 3 to set the range endpoints to the text node instead of `document.body`. Authored-by: Fernando Fiori <ffiori@github.com>
1 parent c1e4878 commit 7b2b399

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

css-highlight-api-1/Overview.bs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,15 @@ Painting</h4>
308308
</style>
309309
<body>Lorem Ipsum.
310310
<script>
311+
let textNode = document.body.firstChild;
312+
311313
let r1 = new Range();
312-
r1.setStart(document.body, 1);
313-
r1.setEnd(document.body, 5);
314+
r1.setStart(textNode, 1);
315+
r1.setEnd(textNode, 5);
314316

315317
let r2 = new Range();
316-
r2.setStart(document.body, 3);
317-
r2.setEnd(document.body, 7);
318+
r2.setStart(textNode, 3);
319+
r2.setEnd(textNode, 7);
318320

319321
CSS.highlights.add(new Highlight("sample", r1, r2));
320322
</script>
@@ -389,13 +391,15 @@ Priority of Overlapping Highlights</h4>
389391
</style>
390392
<body>Some text
391393
<script>
394+
let textNode = document.body.firstChild;
395+
392396
let r1 = new Range();
393-
r1.setStart(document.body, 0);
394-
r1.setEnd(document.body, 6);
397+
r1.setStart(textNode, 0);
398+
r1.setEnd(textNode, 6);
395399

396400
let r2 = new Range();
397-
r2.setStart(document.body, 3);
398-
r2.setEnd(document.body, 9);
401+
r2.setStart(textNode, 3);
402+
r2.setEnd(textNode, 9);
399403

400404
CSS.highlights.add(new Highlight("foo", r1));
401405
CSS.highlights.add(new Highlight("bar", r2));

0 commit comments

Comments
 (0)