This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 14231 - Force values of runs of consecutive nodes, not individual nodes
Summary: Force values of runs of consecutive nodes, not individual nodes
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - HTML Editing APIs (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Aryeh Gregor
QA Contact: HTML Editing APIs spec bugbot
Depends on: 13996
  Show dependency treegraph
Reported: 2011-09-21 17:41 UTC by Aryeh Gregor
Modified: 2011-09-21 20:50 UTC (History)
2 users (show)

See Also:


Description Aryeh Gregor 2011-09-21 17:41:31 UTC
Consider the following test case for bold:

  <p>[foo</p><p> <span>bar</span> </p><p>baz]</p>

We wrap each of the inline nodes one by one:

1) <p>[foo</p><p> <span>bar</span> </p><p>baz]</p>
2) <p>[<b>foo</b></p><p> <span>bar</span> </p><p>baz]</p>
3) <p>[<b>foo</b></p><p> <b><span>bar</span></b> </p><p>baz]</p>
4) <p>[<b>foo</b></p><p> <b><span>bar</span> </b></p><p>baz]</p>
5) <p>[<b>foo</b></p><p> <b><span>bar</span> </b></p><p><b>baz</b>]</p>

Notice how when going from 2->3, we skip the space before <span>bar</span>.  That's because it's an invisible node, so we don't want to create a <b> to wrap it in (bug 13996).  This is to avoid wrapping standalone spaces like in
  <p>[foo</p> <p>bar]</p>
But the second space we do wrap, because we'll add invisible nodes to existing adjacent wrappers just fine.  This is needed for cases like
  <span>[foo</span> <span>bar]</span>
where we want
  <b><span>[foo</span> <span>bar]</span></b>
rather than
  <b><span>[foo</span></b> <b><span>bar]</span></b>

The only way I see to fix this is to rewrite "setting the selection's value" to look at whole runs of adjacent nodes before deciding which ones to force.  Then we can force a whole run if it contains any visible editable node, whether there are invisible nodes before or after.
Comment 1 Aryeh Gregor 2011-09-21 20:50:19 UTC
It turns out there was a simpler way to fix the problem:

Essentially, we just refuse to wrap invisible nodes by themselves.  But when merging into an adjacent sibling, we skip over any intervening invisible nodes, and if we decide to merge, we bring the invisible nodes along too.  So the test case now becomes

1) <p>[foo</p><p> <span>bar</span> </p><p>baz]</p>
2) <p>[<b>foo</b></p><p> <span>bar</span> </p><p>baz]</p>
3) <p>[<b>foo</b></p><p> <b><span>bar</span></b> </p><p>baz]</p>

The last space doesn't get wrapped, because it's invisible.  By contrast:

1) <span>[foo</span><!--bar--><span>baz]</span>
2) <b><span>[foo</span></b><!--bar--><span>baz]</span>
2) <b><span>[foo</span><!--bar--><span>baz]</span></b>

The invisible node isn't wrapped by itself, but when we want to wrap the final "baz", we stick it into the existing <b> along with the intervening invisible node.