14541454function addStepNumberText (
14551455 ol ,
14561456 depth = 0 ,
1457+ indent = ' ' ,
14571458 special = [... ol .classList ].some (c => c .startsWith (' nested-' )),
14581459) {
14591460 let counter = ! special && counterByDepth[depth];
14771478 let i = (Number (ol .getAttribute (' start' )) || 1 ) - 1 ;
14781479 for (const li of ol .children ) {
14791480 const marker = document .createElement (' span' );
1480- marker .textContent = ` ${ i < cache .length ? cache[i] : getTextForIndex (i)} . ` ;
1481+ const markerText = i < cache .length ? cache[i] : getTextForIndex (i);
1482+ const extraIndent = ' ' .repeat (markerText .length + 2 );
1483+ marker .textContent = ` ${ indent}${ markerText} . ` ;
14811484 marker .setAttribute (' aria-hidden' , ' true' );
1485+ marker .setAttribute (' class' , ' list-marker' );
14821486 const attributesContainer = li .querySelector (' .attributes-tag' );
14831487 if (attributesContainer == null ) {
14841488 li .prepend (marker);
14851489 } else {
14861490 attributesContainer .insertAdjacentElement (' afterend' , marker);
14871491 }
14881492 for (const sublist of li .querySelectorAll (' :scope > ol' )) {
1489- addStepNumberText (sublist, depth + 1 , special);
1493+ addStepNumberText (sublist, depth + 1 , indent + extraIndent, special);
14901494 }
14911495 i++ ;
14921496 }
14981502 });
14991503});
15001504
1505+ // Omit indendation when copying a single algorithm step.
1506+ document .addEventListener (' copy' , evt => {
1507+ // Construct a DOM from the selection.
1508+ const doc = document .implementation .createHTMLDocument (' ' );
1509+ const domRoot = doc .createElement (' div' );
1510+ const html = evt .clipboardData .getData (' text/html' );
1511+ if (html) {
1512+ domRoot .innerHTML = html;
1513+ } else {
1514+ const selection = getSelection ();
1515+ const singleRange = selection? .rangeCount === 1 && selection .getRangeAt (0 );
1516+ const container = singleRange? .commonAncestorContainer ;
1517+ if (! container? .querySelector ? .(' .list-marker' )) {
1518+ return ;
1519+ }
1520+ domRoot .append (singleRange .cloneContents ());
1521+ }
1522+
1523+ // Preserve the indentation if there is no hidden list marker, or if selection
1524+ // of more than one step is indicated by either multiple such markers or by
1525+ // visible text before the first one.
1526+ const listMarkers = domRoot .querySelectorAll (' .list-marker' );
1527+ if (listMarkers .length !== 1 ) {
1528+ return ;
1529+ }
1530+ const treeWalker = document .createTreeWalker (domRoot, undefined , {
1531+ acceptNode (node ) {
1532+ return node .nodeType === Node .TEXT_NODE || node === listMarkers[0 ]
1533+ ? NodeFilter .FILTER_ACCEPT
1534+ : NodeFilter .FILTER_SKIP ;
1535+ },
1536+ });
1537+ while (treeWalker .nextNode ()) {
1538+ const node = treeWalker .currentNode ;
1539+ if (node .nodeType === Node .ELEMENT_NODE ) break ;
1540+ if (/ \S / u .test (node .data )) return ;
1541+ }
1542+
1543+ // Strip leading indentation from the plain text representation.
1544+ evt .clipboardData .setData (' text/plain' , domRoot .textContent .trimStart ());
1545+ if (! html) {
1546+ evt .clipboardData .setData (' text/html' , domRoot .innerHTML );
1547+ }
1548+ evt .preventDefault ();
1549+ });
1550+
15011551' use strict' ;
15021552
15031553// Update superscripts to not suffer misinterpretation when copied and pasted as plain text.
16991749
17001750span[aria- hidden= ' true' ] {
17011751 font- size: 0 ;
1752+ white- space: pre;
17021753}
17031754
17041755a {
17961847 font: inherit;
17971848 color: inherit;
17981849}
1850+ /* suppress line break opportunities between `.` and `[[FieldName]]` */
1851+ var .field :: before {
1852+ content: ' \206 0'
1853+ }
17991854
18001855var .referenced {
18011856 color: inherit;
32073262 @media print {
32083263 @page : left {
32093264 @bottom- right {
3210- content: ' © Ecma International 2024 ' ;
3265+ content: ' © Ecma International 2025 ' ;
32113266 }
32123267 }
32133268 @page : right {
32143269 @bottom- left {
3215- content: ' © Ecma International 2024 ' ;
3270+ content: ' © Ecma International 2025 ' ;
32163271 }
32173272 }
32183273 @page : first {
32433298< / ul>< / div>< div id= " menu-toggle" >< svg xmlns= " http://www.w3.org/2000/svg" style= " width:100%; height:100%; stroke:currentColor" viewBox= " 0 0 120 120" width= " 54" height= " 54" >
32443299 < title> Menu< / title>
32453300 < path stroke- width= " 10" stroke- linecap= " round" d= " M30,60 h60 M30,30 m0,5 h60 M30,90 m0,-5 h60" >< / path>
3246- </svg></div><div id="menu-spacer" class="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins<button class="unpin-all">clear</button></div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-control-abstraction-objects" title="Control Abstraction Objects"><span class="secnum">27</span> Control Abstraction Objects</a><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-iteration" title="Iteration"><span class="secnum">27.1</span> Iteration</a><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-properties-of-the-iterator-constructor" title="Properties of the Iterator Constructor"><span class="secnum">27.1.2</span> Properties of the Iterator Constructor</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-iterator.range" title="Iterator.range ( start, end, optionOrStep )"><span class="secnum">27.1.2.1</span> Iterator.range ( <var>start</var>, <var>end</var>, <var>optionOrStep</var> )</a></li></ol></li><li><span class="item-toggle">+</span><a href="#sec-numeric-range-iterator-object" title="The NumericRangeIterator Object"><span class="secnum">27.1.3</span> The <dfn tabindex="-1">NumericRangeIterator</dfn> Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-create-numeric-range-iterator" title="CreateNumericRangeIterator ( start, end, optionOrStep, type )"><span class="secnum">27.1.3.1</span> CreateNumericRangeIterator ( <var>start</var>, <var>end</var>, <var>optionOrStep</var>, <var>type</var> )</a></li><li><span class="item-toggle">+</span><a href="#sec-%numericrangeiteratorprototype%-object" title="The %NumericRangeIteratorPrototype% Object"><span class="secnum">27.1.3.2</span> The %NumericRangeIteratorPrototype% Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-properties-of-the-numericrangeiterator-prototype-object-next" title="%NumericRangeIterator%.next ( )"><span class="secnum">27.1.3.2.1</span> %NumericRangeIterator%.next ( )</a></li><li><span class="item-toggle-none"></span><a href="#sec-properties-of-the-numericrangeiterator-prototype-object-@@tostringtag" title="%NumericRangeIteratorPrototype%.[@@toStringTag]"><span class="secnum">27.1.3.2.2</span> %NumericRangeIteratorPrototype%.[@@toStringTag]</a></li></ol></li></ol></li></ol></li></ol></li></ol></div></div><div id="spec-container"><h1 class="version">Stage 1 Draft / December 8, 2024</h1><h1 class="title">Range proposal</h1>
3301+ </svg></div><div id="menu-spacer" class="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins<button class="unpin-all">clear</button></div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-control-abstraction-objects" title="Control Abstraction Objects"><span class="secnum">27</span> Control Abstraction Objects</a><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-iteration" title="Iteration"><span class="secnum">27.1</span> Iteration</a><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-properties-of-the-iterator-constructor" title="Properties of the Iterator Constructor"><span class="secnum">27.1.2</span> Properties of the Iterator Constructor</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-iterator.range" title="Iterator.range ( start, end, optionOrStep )"><span class="secnum">27.1.2.1</span> Iterator.range ( <var>start</var>, <var>end</var>, <var>optionOrStep</var> )</a></li></ol></li><li><span class="item-toggle">+</span><a href="#sec-numeric-range-iterator-object" title="The NumericRangeIterator Object"><span class="secnum">27.1.3</span> The <dfn tabindex="-1">NumericRangeIterator</dfn> Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-create-numeric-range-iterator" title="CreateNumericRangeIterator ( start, end, optionOrStep, type )"><span class="secnum">27.1.3.1</span> CreateNumericRangeIterator ( <var>start</var>, <var>end</var>, <var>optionOrStep</var>, <var>type</var> )</a></li><li><span class="item-toggle">+</span><a href="#sec-%numericrangeiteratorprototype%-object" title="The %NumericRangeIteratorPrototype% Object"><span class="secnum">27.1.3.2</span> The %NumericRangeIteratorPrototype% Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-properties-of-the-numericrangeiterator-prototype-object-next" title="%NumericRangeIterator%.next ( )"><span class="secnum">27.1.3.2.1</span> %NumericRangeIterator%.next ( )</a></li><li><span class="item-toggle-none"></span><a href="#sec-properties-of-the-numericrangeiterator-prototype-object-@@tostringtag" title="%NumericRangeIteratorPrototype%.[@@toStringTag]"><span class="secnum">27.1.3.2.2</span> %NumericRangeIteratorPrototype%.[@@toStringTag]</a></li></ol></li></ol></li></ol></li></ol></li></ol></div></div><div id="spec-container"><h1 class="version">Stage 1 Draft / January 27, 2025</h1><h1 class="title">Range proposal</h1>
32473302
32483303< emu- clause id= " sec-control-abstraction-objects" number= " 27" >
32493304 < h1>< span class = " secnum" > 27 < / span> Control Abstraction Objects< / h1>
@@ -3262,7 +3317,7 @@ <h1><span class="secnum">27.1.2.1</span> Iterator.range ( <var>start</var>, <var
32623317
32633318 < emu- clause id= " sec-numeric-range-iterator-object" >
32643319 < h1>< span class = " secnum" > 27.1 .3 < / span> The < dfn tabindex= " -1" > NumericRangeIterator< / dfn> Object < / h1>
3265- < p> A NumericRangeIterator object is an iterator that yields numbers . There is not a named < emu- xref href= " #constructor" >< a href= " https://tc39.es/ecma262/#constructor" > constructor </a></emu-xref> for NumericRangeIterator objects. Instead, NumericRangeIterator objects are created by the <emu-xref aoid="CreateNumericRangeIterator" id="_ref_2"><a href="#sec-create-numeric-range-iterator">CreateNumericRangeIterator</a></emu-xref> abstract operation as needed.</p>
3320+ < p> A NumericRangeIterator object is an < emu - xref href = " #sec- iterator-interface " >< a href = " https://tc39.es/ecma262/#sec-iterator-interface " > iterator < / a >< / emu - xref > that yields numbers . There is not a named < emu- xref href= " #constructor" >< a href= " https://tc39.es/ecma262/#constructor" > constructor </a></emu-xref> for NumericRangeIterator objects. Instead, NumericRangeIterator objects are created by the <emu-xref aoid="CreateNumericRangeIterator" id="_ref_2"><a href="#sec-create-numeric-range-iterator">CreateNumericRangeIterator</a></emu-xref> abstract operation as needed.</p>
32663321
32673322 <emu-clause id="sec-create-numeric-range-iterator" type="abstract operation" aoid="CreateNumericRangeIterator">
32683323 <h1><span class="secnum">27.1.3.1</span> CreateNumericRangeIterator ( < var > start < / var > , < var > end < / var > , < var > optionOrStep < / var > , < var > type < / var > )</h1>
@@ -3277,7 +3332,7 @@ <h1><span class="secnum">27.1.3.2</span> The %NumericRangeIteratorPrototype% Obj
32773332 <ul>
32783333 <li>has properties that are inherited by all <emu-xref href="#sec-numeric-range-iterator-object" id="_ref_4"><a href="#sec-numeric-range-iterator-object">NumericRangeIterator</a></emu-xref> Objects.</li>
32793334 <li>is an <emu-xref href="#ordinary-object"><a href="https:// tc39.es/ecma262/#ordinary-object">ordinary object</a></emu-xref>.</li>
3280- <li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-%iteratorprototype%-object"><a href="https: // tc39.es/ecma262/#sec-%iteratorprototype%-object">% IteratorPrototype%</a></emu-xref> .</li>
3335+ <li>has a <var class="field">[[Prototype]]</var> internal slot whose value is % IteratorPrototype%.</li>
32813336 <li>has the following properties:</li>
32823337 </ul>
32833338
@@ -3287,7 +3342,7 @@ <h1><span class="secnum">27.1.3.2.1</span> %NumericRangeIterator%.next ( )</h1>
32873342 </emu-clause>
32883343 <emu-clause id="sec-properties-of-the-numericrangeiterator-prototype-object-@@tostringtag">
32893344 <h1><span class="secnum">27.1.3.2.2</span> %NumericRangeIteratorPrototype%.[@@toStringTag]</h1>
3290- <p>The initial value of the <emu-xref href="#sec-well-known-symbols"><a href="https: // tc39.es/ecma262/#sec-well-known-symbols"> @@toStringTag</a></emu-xref> property is the String value <code>"NumericRangeIterator"</code>.</p>
3345+ <p>The initial value of the @@toStringTag property is the String value <code>"NumericRangeIterator"</code>.</p>
32913346 <p>This property has the attributes { < var class = " field" > [[Writable]]< / var > : < emu- val> false < / emu- val> , < var class = " field" > [[Enumerable]]< / var > : < emu- val> false < / emu- val> , < var class = " field" > [[Configurable]]< / var > : < emu- val> true < / emu- val> }.< / p>
32923347 < / emu- clause>
32933348 < / emu- clause>
0 commit comments