Match IE/Word for backspacing links
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Thu, 28 Jul 2011 14:59:34 -0600
changeset 469 70866da14d70
parent 468 051704af5cea
child 470 c506947145fa
Match IE/Word for backspacing links

Reported-By: Rich Schwerdtfeger
Report-URL: http://www.w3.org/Bugs/Public/show_bug.cgi?id=13429
editing.html
implementation.js
source.html
tests.js
--- a/editing.html	Thu Jul 28 14:32:44 2011 -0600
+++ b/editing.html	Thu Jul 28 14:59:34 2011 -0600
@@ -5463,6 +5463,17 @@
     <a href=#invisible>invisible</a> <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a>, set <var title="">offset</var> to the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> of
     <var title="">node</var>, then set <var title="">node</var> to its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
 
+    <!--
+    When backspacing a link, Firefox 7.0a2, Chrome 14 dev, Opera 11.50, and
+    OpenOffice.org 3.2.1 Ubuntu have no special behavior.  IE9 and Word 2007
+    remove the link instead of deleting its last character.  The latter
+    behavior seems more useful and intuitive.
+    -->
+    <li>Otherwise, if <var title="">node</var> has a <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a>
+    <var title="">offset</var> &minus; 1 and that <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> is an <a href=#editable>editable</a>
+    <code class=external data-anolis-spec=html title="the a element"><a href=http://www.whatwg.org/html/#the-a-element>a</a></code>, remove that <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> from <var title="">node</var>, <a href=#preserving-its-descendants>preserving its
+    descendants</a>.  Then abort these steps.
+
     <li>Otherwise, if <var title="">node</var> has a <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a>
     <var title="">offset</var> &minus; 1 and that <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> is not a <a href=#block-node>block
     node</a> or a <code class=external data-anolis-spec=html title="the br element"><a href=http://www.whatwg.org/html/#the-br-element>br</a></code> or an <code class=external data-anolis-spec=html title="the img element"><a href=http://www.whatwg.org/html/#the-img-element>img</a></code>, set <var title="">node</var> to that
@@ -7554,6 +7565,7 @@
   Julie Parent,
   Simon Pieters,
   Michael A. Puls II,
+  Rich Schwerdtfeger,
   Henri Sivonen,
   Smylers,
   Hallvord R. M. Steen,
@@ -7563,7 +7575,7 @@
   and
   Boris Zbarsky
   for their feedback on drafts of this document and participation in related
-  mailing list discussions
+  mailing list and Bugzilla discussions
   <li>Tab Atkins, Ian Hickson, Glenn Maynard, Ms2ger, Simon Pieters, and most
   of the rest of the <a href=irc://irc.freenode.net/whatwg>#whatwg</a> crowd
   for giving quick online feedback when I have questions or need to solicit
--- a/implementation.js	Thu Jul 28 14:32:44 2011 -0600
+++ b/implementation.js	Thu Jul 28 14:59:34 2011 -0600
@@ -5618,6 +5618,16 @@
 				node = node.parentNode;
 
 			// "Otherwise, if node has a child with index offset − 1 and that
+			// child is an editable a, remove that child from node, preserving
+			// its descendants. Then abort these steps."
+			} else if (0 <= offset - 1
+			&& offset - 1 < node.childNodes.length
+			&& isEditable(node.childNodes[offset - 1])
+			&& isHtmlElement(node.childNodes[offset - 1], "a")) {
+				removePreservingDescendants(node.childNodes[offset - 1]);
+				return;
+
+			// "Otherwise, if node has a child with index offset − 1 and that
 			// child is not a block node or a br or an img, set node to that
 			// child, then set offset to the length of node."
 			} else if (0 <= offset - 1
--- a/source.html	Thu Jul 28 14:32:44 2011 -0600
+++ b/source.html	Thu Jul 28 14:59:34 2011 -0600
@@ -5466,6 +5466,17 @@
     <span>invisible</span> [[node]], set <var>offset</var> to the [[index]] of
     <var>node</var>, then set <var>node</var> to its [[parent]].
 
+    <!--
+    When backspacing a link, Firefox 7.0a2, Chrome 14 dev, Opera 11.50, and
+    OpenOffice.org 3.2.1 Ubuntu have no special behavior.  IE9 and Word 2007
+    remove the link instead of deleting its last character.  The latter
+    behavior seems more useful and intuitive.
+    -->
+    <li>Otherwise, if <var>node</var> has a [[child]] with [[index]]
+    <var>offset</var> &minus; 1 and that [[child]] is an <span>editable</span>
+    [[a]], remove that [[child]] from <var>node</var>, <span>preserving its
+    descendants</span>.  Then abort these steps.
+
     <li>Otherwise, if <var>node</var> has a [[child]] with [[index]]
     <var>offset</var> &minus; 1 and that [[child]] is not a <span>block
     node</span> or a [[br]] or an [[img]], set <var>node</var> to that
@@ -7572,6 +7583,7 @@
   Julie Parent,
   Simon Pieters,
   Michael A. Puls II,
+  Rich Schwerdtfeger,
   Henri Sivonen,
   Smylers,
   Hallvord R. M. Steen,
@@ -7581,7 +7593,7 @@
   and
   Boris Zbarsky
   for their feedback on drafts of this document and participation in related
-  mailing list discussions
+  mailing list and Bugzilla discussions
   <li>Tab Atkins, Ian Hickson, Glenn Maynard, Ms2ger, Simon Pieters, and most
   of the rest of the <a href=irc://irc.freenode.net/whatwg>#whatwg</a> crowd
   for giving quick online feedback when I have questions or need to solicit
--- a/tests.js	Thu Jul 28 14:32:44 2011 -0600
+++ b/tests.js	Thu Jul 28 14:59:34 2011 -0600
@@ -316,8 +316,19 @@
 		'<p>foo</p><br><br><p>[]bar</p>',
 		'<p>foo</p><img src=/img/lion.svg><p>[]bar',
 		'foo<img src=/img/lion.svg>[]bar',
+
+		'<a>foo</a>[]bar',
 		'<a href=/>foo</a>[]bar',
+		'<a name=abc>foo</a>[]bar',
+		'<a href=/ name=abc>foo</a>[]bar',
+		'<span><a>foo</a></span>[]bar',
+		'<span><a href=/>foo</a></span>[]bar',
+		'<span><a name=abc>foo</a></span>[]bar',
+		'<span><a href=/ name=abc>foo</a></span>[]bar',
+		'foo<a>[]bar</a>',
 		'foo<a href=/>[]bar</a>',
+		'foo<a name=abc>[]bar</a>',
+		'foo<a href=/ name=abc>[]bar</a>',
 
 		'foo &nbsp;[]bar',
 		'foo&nbsp; []bar',