More delete improvements
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 07 Jun 2011 10:52:46 -0600
changeset 240 00d6df816fc3
parent 239 2692317e2a27
child 241 caf93d645904
More delete improvements
autoimplementation.html
editcommands.html
implementation.js
source.html
--- a/autoimplementation.html	Tue Jun 07 10:21:41 2011 -0600
+++ b/autoimplementation.html	Tue Jun 07 10:52:46 2011 -0600
@@ -342,6 +342,8 @@
 		'<b>foo[bar</b><i>baz]quz</i>',
 		'<p>foo</p><p>[bar]</p><p>baz</p>',
 		'<p>foo</p><p>{bar}</p><p>baz</p>',
+		'<p>foo</p><p>{bar</p>}<p>baz</p>',
+		'<p>foo</p>{<p>bar}</p><p>baz</p>',
 		'<p>foo</p>{<p>bar</p>}<p>baz</p>',
 
 		'<p>foo[bar<p>baz]quz',
@@ -362,9 +364,11 @@
 		'<p>foo[</p><p>]bar</p>',
 		'<p>foo[</p><p>]bar<br>baz</p>',
 		'foo[<p>]bar</p>',
+		'foo{<p>}bar</p>',
 		'foo[<p>]bar<br>baz</p>',
 		'foo[<p>]bar</p>baz',
 		'<p>foo[</p>]bar',
+		'<p>foo{</p>}bar',
 		'<p>foo[</p>]bar<br>baz',
 		'<p>foo[</p>]bar<p>baz</p>',
 		'foo[<div><p>]bar</div>',
--- a/editcommands.html	Tue Jun 07 10:21:41 2011 -0600
+++ b/editcommands.html	Tue Jun 07 10:52:46 2011 -0600
@@ -978,12 +978,6 @@
 I'm using it mostly because it's convenient and seems relatively sensible.  If
 we really want to use it, we probably want to change its name.
 
-<p class=XXX>This treats selections in elements the same as selections in
-nearby text nodes, if there are any.  This might not be desired in all cases.
-Needs research into what sorts of selections the user can create.  E.g.,
-Gecko treats it differently if you select all the text in a table vs. selecting
-the table itself.
-
 <ol>
   <li>If <var title="">range</var> is null, abort these steps and do nothing.
 
@@ -1040,10 +1034,19 @@
     <li>Let <var title="">reference node</var> be the <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> of <var title="">start node</var>
     with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> equal to <var title="">start offset</var>.
 
-    <li>If <var title="">reference node</var> is an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with no <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>children</a>,
-    break from this loop.
-    <!-- Don't descend into it, since then it won't get deleted even if it's
-    selected. -->
+    <li>If <var title="">reference node</var> is a <a href=#prohibited-paragraph-child>prohibited paragraph
+    child</a> or an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with no <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>children</a>, break from this loop.
+    <!--
+    Don't descend into an element with no children, since then it won't get
+    deleted even if it's selected.  Don't descend into a prohibited paragraph
+    child, because then we might wind up not mergings blocks when we should,
+    e.g.
+
+      foo{<p>}bar</p>
+      -> foo<p>{}bar</p>
+
+    and nothing gets changed.
+    -->
 
     <li>Set <var title="">start node</var> to <var title="">reference node</var> and <var title="">start
     offset</var> to 0.
@@ -1063,8 +1066,8 @@
     <li>Let <var title="">reference node</var> be the <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> of <var title="">end node</var>
     with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-indexof title=concept-indexof>index</a> equal to <var title="">end offset</var> minus one.
 
-    <li>If <var title="">reference node</var> is an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with no <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>children</a>,
-    break from this loop.
+    <li>If <var title="">reference node</var> is a <a href=#prohibited-paragraph-child>prohibited paragraph
+    child</a> or an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with no <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>children</a>, break from this loop.
 
     <li>Set <var title="">end node</var> to <var title="">reference node</var> and <var title="">end
     offset</var> to the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-node-length title=concept-node-length>length</a> of <var title="">reference node</var>.
@@ -2567,6 +2570,23 @@
     <li>Abort these steps.
   </ol>
 
+  <li>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:
+
+  <ol>
+    <li>Let <var title="">start node</var> be the <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> of <var title="">node</var> 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.
+
+    <li><a href=#remove-extraneous-line-breaks-at-the-end-of>Remove extraneous line breaks at the end of</a> <var title="">start
+    node</var>.
+
+    <li><a href=#delete-the-contents>Delete the contents</a> of the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a> with <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a>
+    (<var title="">start node</var>, <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-node-length title=concept-node-length>length</a> of <var title="">start node</var>) and
+    <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-end title=concept-range-end>end</a> (<var title="">node</var>, <var title="">offset</var>).
+
+    <li>Abort these steps.
+  </ol>
+
   <li class=XXX>Lots more cases to handle.
 </ol>
 
--- a/implementation.js	Tue Jun 07 10:21:41 2011 -0600
+++ b/implementation.js	Tue Jun 07 10:52:46 2011 -0600
@@ -776,8 +776,8 @@
 		range = node1;
 	} else {
 		range = document.createRange();
-		range.setStart(arguments[0], arguments[1]);
-		range.setEnd(arguments[2], arguments[3]);
+		range.setStart(node1, offset1);
+		range.setEnd(node2, offset2);
 	}
 
 	// "If range is null, abort these steps and do nothing."
@@ -816,10 +816,11 @@
 		// start offset."
 		var referenceNode = startNode.childNodes[startOffset];
 
-		// "If reference node is an Element with no children, break from this
-		// loop."
-		if (referenceNode.nodeType == Node.ELEMENT_NODE
-		&& !referenceNode.hasChildNodes()) {
+		// "If reference node is a prohibited paragraph child or an Element
+		// with no children, break from this loop."
+		if (isProhibitedParagraphChild(referenceNode)
+		|| (referenceNode.nodeType == Node.ELEMENT_NODE
+		&& !referenceNode.hasChildNodes())) {
 			break;
 		}
 
@@ -851,10 +852,11 @@
 		// offset minus one."
 		var referenceNode = endNode.childNodes[endOffset - 1];
 
-		// "If reference node is an Element with no children, break from this
-		// loop."
-		if (referenceNode.nodeType == Node.ELEMENT_NODE
-		&& !referenceNode.hasChildNodes()) {
+		// "If reference node is a prohibited paragraph child or an Element
+		// with no children, break from this loop."
+		if (isProhibitedParagraphChild(referenceNode)
+		|| (referenceNode.nodeType == Node.ELEMENT_NODE
+		&& !referenceNode.hasChildNodes())) {
 			break;
 		}
 
@@ -3240,6 +3242,23 @@
 			// "Abort these steps."
 			return;
 		}
+
+		// "If node has a child with index offset − 1:"
+		if (0 <= offset -1
+		&& offset - 1 < node.childNodes.length) {
+			// "Let start node be the child of node with index offset − 1."
+			var startNode = node.childNodes[offset - 1];
+
+			// "Remove extraneous line breaks at the end of start node."
+			removeExtraneousLineBreaksAtTheEndOf(startNode);
+
+			// "Delete the contents of the range with start (start node, length
+			// of start node) and end (node, offset)."
+			deleteContents(startNode, getNodeLength(startNode), node, offset);
+
+			// "Abort these steps."
+			return;
+		}
 		break;
 
 		case "fontname":
--- a/source.html	Tue Jun 07 10:21:41 2011 -0600
+++ b/source.html	Tue Jun 07 10:52:46 2011 -0600
@@ -934,12 +934,6 @@
 I'm using it mostly because it's convenient and seems relatively sensible.  If
 we really want to use it, we probably want to change its name.
 
-<p class=XXX>This treats selections in elements the same as selections in
-nearby text nodes, if there are any.  This might not be desired in all cases.
-Needs research into what sorts of selections the user can create.  E.g.,
-Gecko treats it differently if you select all the text in a table vs. selecting
-the table itself.
-
 <ol>
   <li>If <var>range</var> is null, abort these steps and do nothing.
 
@@ -996,10 +990,19 @@
     <li>Let <var>reference node</var> be the [[child]] of <var>start node</var>
     with [[index]] equal to <var>start offset</var>.
 
-    <li>If <var>reference node</var> is an [[element]] with no [[children]],
-    break from this loop.
-    <!-- Don't descend into it, since then it won't get deleted even if it's
-    selected. -->
+    <li>If <var>reference node</var> is a <span>prohibited paragraph
+    child</span> or an [[element]] with no [[children]], break from this loop.
+    <!--
+    Don't descend into an element with no children, since then it won't get
+    deleted even if it's selected.  Don't descend into a prohibited paragraph
+    child, because then we might wind up not mergings blocks when we should,
+    e.g.
+
+      foo{<p>}bar</p>
+      -> foo<p>{}bar</p>
+
+    and nothing gets changed.
+    -->
 
     <li>Set <var>start node</var> to <var>reference node</var> and <var>start
     offset</var> to 0.
@@ -1019,8 +1022,8 @@
     <li>Let <var>reference node</var> be the [[child]] of <var>end node</var>
     with [[index]] equal to <var>end offset</var> minus one.
 
-    <li>If <var>reference node</var> is an [[element]] with no [[children]],
-    break from this loop.
+    <li>If <var>reference node</var> is a <span>prohibited paragraph
+    child</span> or an [[element]] with no [[children]], break from this loop.
 
     <li>Set <var>end node</var> to <var>reference node</var> and <var>end
     offset</var> to the [[nodelength]] of <var>reference node</var>.
@@ -2548,6 +2551,23 @@
     <li>Abort these steps.
   </ol>
 
+  <li>If <var>node</var> has a [[child]] with [[index]] <var>offset</var>
+  &minus; 1:
+
+  <ol>
+    <li>Let <var>start node</var> be the [[child]] of <var>node</var> with
+    [[index]] <var>offset</var> &minus; 1.
+
+    <li><span>Remove extraneous line breaks at the end of</span> <var>start
+    node</var>.
+
+    <li><span>Delete the contents</span> of the [[range]] with [[rangestart]]
+    (<var>start node</var>, [[nodelength]] of <var>start node</var>) and
+    [[rangeend]] (<var>node</var>, <var>offset</var>).
+
+    <li>Abort these steps.
+  </ol>
+
   <li class=XXX>Lots more cases to handle.
 </ol>