Skip to content

Add definition for composed selection range #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 117 additions & 31 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2786,11 +2786,13 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
<p>If <var>child</var> is non-null:

<ol>
<li><p>For each <a>live range</a> whose <a for=range>start node</a> is <var>parent</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>start node</a> is <var>parent</var> and
<a for=range>start offset</a> is greater than <var>child</var>'s <a for=tree>index</a>, increase
its <a for=range>start offset</a> by <var>count</var>.

<li><p>For each <a>live range</a> whose <a for=range>end node</a> is <var>parent</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>end node</a> is <var>parent</var> and
<a for=range>end offset</a> is greater than <var>child</var>'s <a for=tree>index</a>, increase
its <a for=range>end offset</a> by <var>count</var>.
</ol>
Expand Down Expand Up @@ -3034,11 +3036,21 @@ optional <i>suppress observers flag</i>, run these steps:
<li><p>For each <a>live range</a> whose <a for=range>end node</a> is an <a>inclusive descendant</a>
of <var>node</var>, set its <a for=range>end</a> to (<var>parent</var>, <var>index</var>).

<li><p>For each <a>live range</a> whose <a for=range>start node</a> is <var>parent</var> and
<li><p>For each <a>composed selection range</a> whose <a for=range>start node</a> is a
<a>shadow-including inclusive descendant</a> of <var>node</var>, set its <a for=range>start</a> to
(<var>parent</var>, <var>index</var>).

<li><p>For each <a>composed selection range</a> whose <a for=range>end node</a> is a
<a>shadow-including inclusive descendant</a> of <var>node</var>, set its <a for=range>end</a> to
(<var>parent</var>, <var>index</var>).

<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>start node</a> is <var>parent</var> and
<a for=range>start offset</a> is greater than <var>index</var>, decrease its
<a for=range>start offset</a> by 1.

<li><p>For each <a>live range</a> whose <a for=range>end node</a> is <var>parent</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>end node</a> is <var>parent</var> and
<a for=range>end offset</a> is greater than <var>index</var>, decrease its
<a for=range>end offset</a> by 1.

Expand Down Expand Up @@ -4497,20 +4509,24 @@ each <a for=tree>descendant</a> <a>exclusive <code>Text</code> node</a> <var>nod
<p>While <var>currentNode</var> is an <a>exclusive <code>Text</code> node</a>:

<ol>
<li><p>For each <a>live range</a> whose <a for=range>start node</a> is <var>currentNode</var>,
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>start node</a> is <var>currentNode</var>,
add <var>length</var> to its <a for=range>start offset</a> and set its
<a for=range>start node</a> to <var>node</var>.

<li><p>For each <a>live range</a> whose <a for=range>end node</a> is <var>currentNode</var>, add
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>end node</a> is <var>currentNode</var>, add
<var>length</var> to its <a for=range>end offset</a> and set its <a for=range>end node</a> to
<var>node</var>.

<li><p>For each <a>live range</a> whose <a for=range>start node</a> is <var>currentNode</var>'s
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>start node</a> is <var>currentNode</var>'s
<a for=tree>parent</a> and <a for=range>start offset</a> is <var>currentNode</var>'s
<a for=tree>index</a>, set its <a for=range>start node</a> to <var>node</var> and its
<a for=range>start offset</a> to <var>length</var>.

<li><p>For each <a>live range</a> whose <a for=range>end node</a> is <var>currentNode</var>'s
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>end node</a> is <var>currentNode</var>'s
<a for=tree>parent</a> and <a for=range>end offset</a> is <var>currentNode</var>'s
<a for=tree>index</a>, set its <a for=range>end node</a> to <var>node</var> and its
<a for=range>end offset</a> to <var>length</var>.
Expand Down Expand Up @@ -5775,7 +5791,7 @@ are:
<hr>

<p>The <dfn method for=Document><code>createRange()</code></dfn> method steps are to return a new
<a>live range</a> with (<a>this</a>, 0) as its <a for=range>start</a> an <a for=range>end</a>.
<a>live range</a> with (<a>this</a>, 0) as its <a for=range>start</a> and <a for=range>end</a>.

<p class=note>The {{Range/Range()}} constructor can be used instead.

Expand Down Expand Up @@ -7577,21 +7593,25 @@ string called <dfn export id=concept-cd-data for=CharacterData>data</dfn>.
<var>node</var>'s <a for=CharacterData>data</a>.

<!-- ranges -->
<li><p>For each <a>live range</a> whose <a for=range>start node</a> is <var>node</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>start node</a> is <var>node</var> and
<a for=range>start offset</a> is greater than <var>offset</var> but less than or equal to
<var>offset</var> plus <var>count</var>, set its <a for=range>start offset</a> to
<var>offset</var>.

<li><p>For each <a>live range</a> whose <a for=range>end node</a> is <var>node</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>end node</a> is <var>node</var> and
<a for=range>end offset</a> is greater than <var>offset</var> but less than or equal to
<var>offset</var> plus <var>count</var>, set its <a for=range>end offset</a> to <var>offset</var>.

<li><p>For each <a>live range</a> whose <a for=range>start node</a> is <var>node</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>start node</a> is <var>node</var> and
<a for=range>start offset</a> is greater than <var>offset</var> plus <var>count</var>, increase its
<a for=range>start offset</a> by <var>data</var>'s <a for=string>length</a> and decrease it by
<var>count</var>.

<li><p>For each <a>live range</a> whose <a for=range>end node</a> is <var>node</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>end node</a> is <var>node</var> and
<a for=range>end offset</a> is greater than <var>offset</var> plus <var>count</var>, increase its
<a for=range>end offset</a> by <var>data</var>'s <a for=string>length</a> and decrease it by
<var>count</var>.
Expand Down Expand Up @@ -7783,22 +7803,26 @@ constructor steps are to set <a>this</a>'s <a for=CharacterData>data</a> to <var
mutate ranges prematurely:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=15325 -->

<li><p>For each <a>live range</a> whose <a for=range>start node</a> is <var>node</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>start node</a> is <var>node</var> and
<a for=range>start offset</a> is greater than <var>offset</var>, set its
<a for=range>start node</a> to <var>new node</var> and decrease its <a for=range>start offset</a>
by <var>offset</var>.

<li><p>For each <a>live range</a> whose <a for=range>end node</a> is <var>node</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>end node</a> is <var>node</var> and
<a for=range>end offset</a> is greater than <var>offset</var>, set its <a for=range>end node</a>
to <var>new node</var> and decrease its <a for=range>end offset</a> by <var>offset</var>.

<!-- This shit is complicated:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=19968 -->
<li><p>For each <a>live range</a> whose <a for=range>start node</a> is <var>parent</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>start node</a> is <var>parent</var> and
<a for=range>start offset</a> is equal to the <a for=tree>index</a> of <var>node</var> plus 1,
increase its <a for=range>start offset</a> by 1.

<li><p>For each <a>live range</a> whose <a for=range>end node</a> is <var>parent</var> and
<li><p>For each <a>live range</a> or <a>composed selection range</a> whose
<a for=range>end node</a> is <var>parent</var> and
<a for=range>end offset</a> is equal to the <a for=tree>index</a> of <var>node</var> plus 1,
increase its <a for=range>end offset</a> by 1.
</ol>
Expand Down Expand Up @@ -8144,9 +8168,16 @@ interface Range : AbstractRange {
<p>Objects implementing the {{Range}} interface are known as
<dfn export id=concept-live-range>live ranges</dfn>.

<p>A <dfn export id=concept-composed-selection-range>composed selection range</dfn> is a
<a>range</a> with an associated <a>live range</a> called
<dfn export id=concept-legacy-selection-range for="composed selection range">legacy selection range</dfn>.

<p class=note>Algorithms that modify a <a>tree</a> (in particular the <a for=/>insert</a>,
<a for=/>remove</a>, <a>replace data</a>, and <a lt="split a Text node">split</a> algorithms) modify
<a>live ranges</a> associated with that <a>tree</a>.
<a>live ranges</a> and <a>composed selection range</a> associated with that <a>tree</a>.

<p class=note>The <a for="composed selection range">legacy selection range</a> is used to maintain
backward compatibility with the {{Selection/getRangeAt()}} API.

<p>The <dfn export id=concept-range-root for="live range">root</dfn> of a <a>live range</a> is the
<a for=tree>root</a> of its <a for=range>start node</a>.
Expand Down Expand Up @@ -8250,9 +8281,9 @@ to set <a>this</a>'s <a for=range>start</a> and <a for=range>end</a> to
<hr>

<p>To
<dfn export id=concept-range-bp-set lt="set the start|set the end" for=Range>set the start or end</dfn>
of a <var>range</var> to a <a>boundary point</a> (<var>node</var>, <var>offset</var>), run these
steps:
<dfn export id=concept-range-bp-set lt="set the start|set the end" for="live range">
set the start or end</dfn> of a <a>live range</a> <var>range</var> to a <a>boundary point</a>
(<var>node</var>, <var>offset</var>), run these steps:

<ol>
<li>If <var>node</var> is a <a>doctype</a>, then <a>throw</a> an
Expand All @@ -8265,41 +8296,95 @@ steps:
<a>boundary point</a>
(<var>node</var>, <var>offset</var>).

<li>If <var>range</var> is the <a for="composed selection range">legacy selection range</a> of a
<a>composed selection range</a>, set <var>selection range</var> to that
<a>composed selection range</a>.

<li>Otherwise, set <var>selection range</var> to null.

<li>
<dl class=switch>
<dt>If these steps were invoked as "set the start"
<dd>
<ol>
<li>If <var>range</var>'s
<a for="live range">root</a> is not equal to
<var>node</var>'s <a for=tree>root</a>,
or if <var>bp</var> is
<var>node</var>'s <a for=tree>root</a>, then:
<ol>
<li>Set <var>range</var>'s <a for=range>end</a>
to <var>bp</var>.

<li>If <var>selection range</var> is not null and
<var>range</var>'s <a for=range>start node</a>'s
<a>shadow-including root</a> is not
<var>node</var>'s <a>shadow-including root</a>,
set <var>selection range</var>’s
<a for="range">end</a> to <var>bp</var>.
</ol>

<li>Otherwise, if <var>bp</var> is
<a for="boundary point">after</a> the
<var>range</var>'s <a for=range>end</a>, set
<var>range</var>'s <a for=range>end</a>
to <var>bp</var>.
<var>range</var>'s <a for=range>end</a>, then:
<ol>
<li>Set <var>range</var>'s <a for=range>end</a>
to <var>bp</var>.

<li>If <var>selection range</var> is not null,
set <var>selection range</var>’s
<a for="range">end</a> to <var>bp</var>.
</ol>

<li>Set <var>range</var>'s
<a for=range>start</a> to <var>bp</var>.

<li>If <var>selection range</var> is not null,
set <var>selection range</var>’s
<a for="range">start</a> to <var>bp</var>.
</ol>
<dt>If these steps were invoked as "set the end"
<dd>
<ol>
<li>If <var>range</var>'s
<a for="live range">root</a> is not equal to
<var>node</var>'s <a for=tree>root</a>,
or if <var>bp</var> is
<var>node</var>'s <a for=tree>root</a>, then:
<ol>
<li>Set <var>range</var>'s <a for=range>start</a>
to <var>bp</var>.

<li>If <var>selection range</var> is not null and
<var>range</var>'s <a for=range>start node</a>'s
<a>shadow-including root</a> is not
<var>node</var>'s <a>shadow-including root</a>,
set <var>selection range</var>’s
<a for="range">start</a> to <var>bp</var>.
</ol>

<li>Otherwise, if <var>bp</var> is
<a for="boundary point">before</a> the
<var>range</var>'s <a for=range>start</a>, set
<var>range</var>'s <a for=range>start</a>
to <var>bp</var>.
<var>range</var>'s <a for=range>start</a>, then:
<ol>
<li>Set <var>range</var>'s <a for=range>start</a>
to <var>bp</var>.

<li>If <var>selection range</var> is not null,
set <var>selection range</var>’s
<a for="range">start</a> to <var>bp</var>.
</ol>

<li>Set <var>range</var>'s
<a for=range>end</a> to <var>bp</var>.

<li>If <var>selection range</var> is not null,
set <var>selection range</var>’s
<a for="range">end</a> to <var>bp</var>.
</ol>
</dl>
</ol>

<p class=note>The <a>composed selection range</a>'s <a for=range>start</a> and
<a for=range>end</a> can have different <a for=tree>roots</a>, but will have the
same <a for=Node>node document</a>.

<p>The <dfn method for=Range><code>setStart(<var>node</var>, <var>offset</var>)</code></dfn> method
steps are to <a>set the start</a> of <a>this</a> to <a>boundary point</a>
(<var>node</var>, <var>offset</var>).
Expand Down Expand Up @@ -10441,6 +10526,7 @@ David Håsäther,
David Hyatt,
Deepak Sherveghar,
Dethe Elza,
Di Zhang,
Dimitri Glazkov,
Domenic Denicola,
Dominic Cooney,
Expand Down