Skip to content

Commit 8d4905c

Browse files
mayankleoboymoz-wptsync-bot
authored andcommitted
Register the collapsed range before clearing the old ones.
Selection::CollapseInternal() unregistered every current range and then registered a new collapsed one. When both use the same node as their closest common inclusive ancestor, that node's range list momentarily became empty, so UnregisterClosestCommonInclusiveAncestor() unmarked its whole flattened subtree and the following MarkDescendants() marked it again. Register the new range first. The node's list then never becomes empty, and the existing guards in both functions skip the two walks on their own. The same holds when either node is an ancestor of the other, where the walk that does happen now stops at the other node instead of covering it. AddRangesForSelectableNodes() adds nothing at all when it goes through AddRangesForUserSelectableNodes() and no part of the range is selectable, which leaves the registration backed by no range of this selection. Clear() has emptied the ranges by then, so the range took index 0 if it was added at all: unregister it again when it was not, and on the error path. Differential Revision: https://phabricator.services.mozilla.com/D317252 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1968416 gecko-commit: 93284149ba817a492f8e55cf0bab8db6a4ac3aec gecko-commit-git: 52a52f64306f9113dab5a028ba7472c677c46eb9 gecko-reviewers: masayuki
1 parent af48354 commit 8d4905c

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<title>Selecting a subtree after collapsing into an ancestor of the previous closest common inclusive ancestor</title>
3+
<link rel="match" href="collapse-common-ancestor-ref.html">
4+
<meta name="assert" content="Collapsing into an ancestor of the node the selection was registered on must not leave stale marks that keep the subtree from being selected again.">
5+
<div id="outer">before<div id="inner"><span>AAA</span><span>BBB</span></div>after</div>
6+
7+
<script>
8+
// Make |inner| the closest common inclusive ancestor.
9+
getSelection().setBaseAndExtent(inner.firstChild.firstChild, 0,
10+
inner.lastChild.firstChild,
11+
inner.lastChild.firstChild.length);
12+
document.body.offsetWidth;
13+
// Collapse into |outer|, an ancestor of |inner|.
14+
getSelection().collapse(outer, 1);
15+
document.body.offsetWidth;
16+
getSelection().setBaseAndExtent(outer.firstChild, 0, outer.lastChild,
17+
outer.lastChild.length);
18+
</script>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<title>Selecting a subtree after collapsing into the previous closest common inclusive ancestor</title>
3+
<link rel="match" href="collapse-common-ancestor-ref.html">
4+
<meta name="assert" content="Collapsing into the node the selection was registered on must not leave stale marks that keep the subtree from being selected again.">
5+
<div id="outer">before<div id="inner"><span>AAA</span><span>BBB</span></div>after</div>
6+
7+
<script>
8+
// Make |outer| the closest common inclusive ancestor.
9+
getSelection().setBaseAndExtent(outer.firstChild, 0, outer.lastChild,
10+
outer.lastChild.length);
11+
document.body.offsetWidth;
12+
// Collapse into |outer| itself, which neither drops nor recomputes its marks.
13+
getSelection().collapse(outer, 1);
14+
document.body.offsetWidth;
15+
getSelection().setBaseAndExtent(outer.firstChild, 0, outer.lastChild,
16+
outer.lastChild.length);
17+
</script>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<title>Selecting a subtree after collapsing into a descendant of the previous closest common inclusive ancestor</title>
3+
<link rel="match" href="collapse-common-ancestor-ref.html">
4+
<meta name="assert" content="Collapsing into a descendant of the node the selection was registered on must not leave stale marks that keep the subtree from being selected again.">
5+
<div id="outer">before<div id="inner"><span>AAA</span><span>BBB</span></div>after</div>
6+
7+
<script>
8+
// Make |outer| the closest common inclusive ancestor.
9+
getSelection().setBaseAndExtent(outer.firstChild, 0, outer.lastChild,
10+
outer.lastChild.length);
11+
document.body.offsetWidth;
12+
// Collapse into |inner|, a descendant of |outer|.
13+
getSelection().collapse(inner, 1);
14+
document.body.offsetWidth;
15+
getSelection().setBaseAndExtent(outer.firstChild, 0, outer.lastChild,
16+
outer.lastChild.length);
17+
</script>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<title>Selecting a subtree around a collapse</title>
3+
<div id="outer">before<div id="inner"><span>AAA</span><span>BBB</span></div>after</div>
4+
5+
<script>
6+
getSelection().setBaseAndExtent(outer.firstChild, 0, outer.lastChild,
7+
outer.lastChild.length);
8+
</script>

0 commit comments

Comments
 (0)