Revise insertOrderedList some more
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Thu, 12 May 2011 13:38:40 -0600
changeset 110 46289ac20636
parent 109 738cb934333d
child 111 b6104db990af
Revise insertOrderedList some more
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Thu May 12 12:46:02 2011 -0600
+++ b/editcommands.html	Thu May 12 13:38:40 2011 -0600
@@ -652,7 +652,7 @@
 
 
 <h2 id=normalizing-sublists-of-a-list-item><span class=secno>5 </span>Normalizing sublists of a list item</h2>
-<p>When a user agent is to <dfn id=normalize-sublists>normalize sublists</dfn> in an <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code>
+<p>When a user agent is to <dfn id=normalize-sublists>normalize sublists</dfn> in 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>
 <var title="">item</var>, it must run the following steps:
 <!--
 This algorithm implies that we don't support a sublist in the middle of an
@@ -675,8 +675,8 @@
 -->
 
 <ol>
-  <li>If <var title="">item</var> is not <a href=#editable>editable</a> or 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> is not
-  <a href=#editable>editable</a>, abort these steps.
+  <li>If <var title="">item</var> is not an <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code> or it is not <a href=#editable>editable</a> or
+  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> is not <a href=#editable>editable</a>, abort these steps.
 
   <li>Let <var title="">new item</var> be null.
 
@@ -2534,6 +2534,16 @@
     * Word/OO/Firefox/Opera: Different than doing both at once (often in
       exciting ways).
     * IE/Chrome: Same as doing both at once.
+* <p>foo</p><blockquote><p>bar</p><p>baz</p></blockquote>
+  * Select "foobar" and do "ol":
+    * Word: One-item list with sublist.
+    * OO/Firefox/Chrome/Opera: One two-item list, unindented.
+    * IE9: Two one-item lists.
+  * Select "foo", do "ol", then select "bar" and do "ol":
+    * Word/OO/Chrome: One two-item list, unindented.
+    * IE9/Firefox: Two one-item lists.
+    * Opera: Two one-item lists, both unindented.
+  * Desired behavior: One-item list with sublist in both cases.
 * In an existing multi-line indented region equivalent to <blockquote>foo<br>bar<br>baz</blockquote>:
   * Select "bar", do "ol":
     * Word/OO/Firefox/Chrome: Increase indent, add "1".
@@ -2657,6 +2667,25 @@
   either <var title="">node</var> is an <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code> or <code class=external data-anolis-spec=html title="the ul element"><a href=http://www.whatwg.org/html/#the-ul-element>ul</a></code>, or 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> is an <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code>
   or <code class=external data-anolis-spec=html title="the ul element"><a href=http://www.whatwg.org/html/#the-ul-element>ul</a></code>, or it can 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 an <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code>; then append
   <var title="">node</var> to <var title="">node list</var>.
+  <!--
+  We exclude potential indentation elements so that selecting some random text
+  and doing indent followed by insertOrderedList will have the same result as
+  the reverse.  Specifically,
+
+    <blockquote>[foo]</blockquote> ->
+    <blockquote><ol><li>[foo]</li></ol></blockquote>
+
+  per spec and Firefox 4.0 and (more or less) Chrome 12 dev.  Opera 11.10
+  instead does <ol><li>foo</li></ol>, so the indentation vanishes.  IE9 does
+  <ol><ol><li>foo</li></ol></ol>, but that doesn't make semantic sense and is
+  different from how it would work if you reversed the commands.
+  OpenOffice.org 3.2.1 (Ubuntu) and Word 2007 both agree with the spec in this
+  case.
+  -->
+
+  <p class=XXX>Similar to a number of other places in the spec, "can be the
+  child" is not well-defined, and it's not clear what the right definition
+  should be.
 
   <li>While <var title="">node list</var> is not empty:
 
@@ -2745,20 +2774,6 @@
     <li>s. -->
 
     <ol>
-      <li>Let <var title="">extra indentation</var> equal 0.
-
-      <li>Let <var title="">ancestor</var> be the <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> of the first member of
-      <var title="">sublist</var>.
-
-      <li>While <var title="">ancestor</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code>:
-
-      <ol>
-        <li>If <var title="">ancestor</var> is a <a href=#potential-indentation-element>potential indentation
-        element</a>, increment <var title="">extra indentation</var>.
-
-        <li>Set <var title="">ancestor</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>.
-      </ol>
-
       <li>If the first member of <var title="">sublist</var> is a <code class=external data-anolis-spec=html title="the p element"><a href=http://www.whatwg.org/html/#the-p-element>p</a></code> or <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code> or
       <code class=external data-anolis-spec=html title="the div element"><a href=http://www.whatwg.org/html/#the-div-element>div</a></code>, <a href=#set-the-tag-name>set the tag name</a> of the first member of
       <var title="">sublist</var> to "li", and let <var title="">li</var> be the result.  Remove
@@ -2780,15 +2795,6 @@
         <code class=external data-anolis-spec=domcore title=dom-Node-ownerDocument><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-ownerdocument>ownerDocument</a></code> of the first member of <var title="">sublist</var>.
       </ol>
 
-      <li>Repeat the following a number of times equal to <var title="">extra
-      indentation</var>: for each <var title="">node</var> in <var title="">sublist</var>,
-      <a href=#outdent>outdent</a> <var title="">node</var>.
-
-      <!-- That might have created an extra <br> at some point. -->
-      <li>If the last member of <var title="">sublist</var> is not 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> but its
-      <code class=external data-anolis-spec=domcore title=dom-Node-nextSibling><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-nextsibling>nextSibling</a></code> is, append the <code class=external data-anolis-spec=domcore title=dom-Node-nextSibling><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-nextsibling>nextSibling</a></code> of the last member of
-      <var title="">sublist</var> to <var title="">sublist</var>.
-
       <li>If the <code class=external data-anolis-spec=domcore title=dom-Node-nextSibling><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-nextsibling>nextSibling</a></code> of the last member of <var title="">sublist</var> is an
       <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code>:
 
@@ -2811,12 +2817,33 @@
         <li>Let <var title="">ol</var> be the <code class=external data-anolis-spec=domcore title=dom-Node-previousSibling><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-previoussibling>previousSibling</a></code> of the first member of
         <var title="">sublist</var>.
 
-        <li>If <var title="">ol</var> is not an <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code>, let <var title="">ol</var> be the result
-        of calling <code class=external data-anolis-spec=domcore title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("ol")</a></code> on the
+        <li>Let <var title="">original parent</var> be the <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> of the first
+        member of <var title="">sublist</var>.
+
+        <li>If <var title="">ol</var> is null, and <var title="">original parent</var> is an
+        <a href=#editable>editable</a> <a href=#indentation-element>indentation element</a>, and the
+        <code class=external data-anolis-spec=domcore title=dom-Node-previousSibling><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-previoussibling>previousSibling</a></code> of <var title="">original parent</var> is an
+        <a href=#editable>editable</a> <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code>:
+
+        <ol>
+          <li>Let <var title="">ol</var> be the <code class=external data-anolis-spec=domcore title=dom-Node-previousSibling><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-previoussibling>previousSibling</a></code> of <var title="">original
+          parent</var>.
+
+          <li><a href=#normalize-sublists>Normalize sublists</a> of <var title="">ol</var>'s last <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>.
+
+          <li>If <var title="">ol</var>'s last <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 an <a href=#editable>editable</a>
+          <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code>, call <code class=external data-anolis-spec=domcore title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("ol")</a></code> on the
+          <code class=external data-anolis-spec=domcore title=dom-Node-ownerDocument><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-ownerdocument>ownerDocument</a></code> of <var title="">ol</var>, and append the result as the last
+          <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="">ol</var>.
+
+          <li>Set <var title="">ol</var> to its last <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>.
+        </ol>
+
+        <li>If <var title="">ol</var> is not an <a href=#editable>editable</a> <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code>, let
+        <var title="">ol</var> be the result of calling <code class=external data-anolis-spec=domcore title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("ol")</a></code> on the
         <code class=external data-anolis-spec=domcore title=dom-Node-ownerDocument><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-ownerdocument>ownerDocument</a></code> of the first member of <var title="">sublist</var>.  Insert
-        <var title="">ol</var> into the <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> of the first member of
-        <var title="">sublist</var> immediately before the first member of
-        <var title="">sublist</var>.
+        <var title="">ol</var> into <var title="">original parent</var> immediately before the
+        first member of <var title="">sublist</var>.
 
         <li>Append <var title="">li</var> as the last <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="">ol</var>,
         <a href=#preserving-ranges>preserving ranges</a>.
@@ -2827,16 +2854,17 @@
         <li>For each <var title="">node</var> in <var title="">sublist</var>, append
         <var title="">node</var> as the last <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="">li</var>,
         <a href=#preserving-ranges>preserving ranges</a>.
+
+        <li>If <var title="">original parent</var> has 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>, remove it from
+        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>.
+        <!-- This might happen if it's an indentation element whose previous
+        sibling is an ol, for instance. -->
       </ol>
     </ol>
 
     <li><a href=#remove-extraneous-line-breaks>Remove extraneous line breaks</a> from <var title="">ol</var>.
 
     <li><a href=#remove-extraneous-line-breaks>Remove extraneous line breaks</a> from <var title="">li</var>.
-
-    <li>Repeat the following a number of times equal to <var title="">extra
-    indentation</var>: <a href=#indent>indent</a> the one-<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> list containing
-    <var title="">li</var>.
   </ol>
 </ol>
 
--- a/implementation.js	Thu May 12 12:46:02 2011 -0600
+++ b/implementation.js	Thu May 12 13:38:40 2011 -0600
@@ -1170,9 +1170,11 @@
 }
 
 function normalizeSublists(item) {
-	// "If item is not editable or its parent is not editable, abort these
-	// steps."
-	if (!isEditable(item) || !isEditable(item.parentNode)) {
+	// "If item is not an li or it is not editable or its parent is not
+	// editable, abort these steps."
+	if (!isHtmlElement(item, "LI")
+	|| !isEditable(item)
+	|| !isEditable(item.parentNode)) {
 		return;
 	}
 
@@ -2627,27 +2629,6 @@
 				}
 			// "Otherwise:"
 			} else {
-				// "Let extra indentation equal 0."
-				var extraIndentation = 0;
-
-				// "Let ancestor be the parent of the first member of
-				// sublist."
-				var ancestor = sublist[0].parentNode;
-
-				// "While ancestor is an editable Element:"
-				while (ancestor
-				&& isEditable(ancestor)
-				&& ancestor.nodeType == Node.ELEMENT_NODE) {
-					// "If ancestor is a potential indentation element,
-					// increment extra indentation."
-					if (isPotentialIndentationElement(ancestor)) {
-						extraIndentation++;
-					}
-
-					// "Set ancestor to its parent."
-					var ancestor = ancestor.parentNode;
-				}
-
 				// "If the first member of sublist is a p or li or div, set the
 				// tag name of the first member of sublist to "li", and let li
 				// be the result.  Remove the first member of sublist, and
@@ -2680,22 +2661,6 @@
 					var li = sublist[0].ownerDocument.createElement("li");
 				}
 
-				// "Repeat the following a number of times equal to extra
-				// indentation: for each node in sublist, outdent node."
-				for (var i = 0; i < extraIndentation; i++) {
-					for (var j = 0; j < sublist.length; j++) {
-						outdentNode(sublist[j]);
-					}
-				}
-
-				// "If the last member of sublist is not a br but its
-				// nextSibling is, append the nextSibling of the last member of
-				// sublist to sublist."
-				if (!isHtmlElement(sublist[sublist.length - 1], "BR")
-				&& isHtmlElement(sublist[sublist.length - 1].nextSibling, "BR")) {
-					sublist.push(sublist[sublist.length - 1].nextSibling);
-				}
-
 				// "If the nextSibling of the last member of sublist is an ol:"
 				if (isHtmlElement(sublist[sublist.length - 1].nextSibling, "OL")) {
 					// "Insert li as the first child of the nextSibling of the
@@ -2719,14 +2684,44 @@
 					// sublist."
 					var ol = sublist[0].previousSibling;
 
-					// "If ol is not an ol, let ol be the result of calling
-					// createElement("ol") on the ownerDocument of the first
-					// member of sublist. Insert ol into the parent of the
-					// first member of sublist immediately before the first
-					// member of sublist."
-					if (!isHtmlElement(ol, "OL")) {
+					// "Let original parent be the parent of the first member
+					// of sublist."
+					var originalParent = sublist[0].parentNode;
+
+					// "If ol is null, and original parent is an editable
+					// indentation element, and the previousSibling of original
+					// parent is an editable ol:"
+					if (!ol
+					&& isEditable(originalParent)
+					&& isIndentationElement(originalParent)
+					&& isEditable(originalParent.previousSibling)
+					&& isHtmlElement(originalParent.previousSibling, "OL")) {
+						// "Let ol be the previousSibling of original parent."
+						ol = originalParent.previousSibling;
+
+						// "Normalize sublists of ol's last child."
+						normalizeSublists(ol.lastChild);
+
+						// "If ol's last child is not an editable ol, call
+						// createElement("ol") on the ownerDocument of ol, and
+						// append the result as the last child of ol."
+						if (!isEditable(ol.lastChild)
+						|| !isHtmlElement(ol.lastChild, "OL")) {
+							ol.appendChild(ol.ownerDocument.createElement("ol"));
+						}
+
+						// "Set ol to its last child."
+						ol = ol.lastChild;
+					}
+
+					// "If ol is not an editable ol, let ol be the result of
+					// calling createElement("ol") on the ownerDocument of the
+					// first member of sublist. Insert ol into original parent
+					// immediately before the first member of sublist."
+					if (!isEditable(ol)
+					|| !isHtmlElement(ol, "OL")) {
 						ol = sublist[0].ownerDocument.createElement("ol");
-						sublist[0].parentNode.insertBefore(ol, sublist[0]);
+						originalParent.insertBefore(ol, sublist[0]);
 					}
 
 					// "Append li as the last child of ol, preserving ranges."
@@ -2743,6 +2738,12 @@
 					for (var i = 0; i < sublist.length; i++) {
 						movePreservingRanges(sublist[i], li, li.childNodes.length);
 					}
+
+					// "If original parent has no children, remove it from its
+					// parent."
+					if (!originalParent.hasChildNodes()) {
+						originalParent.parentNode.removeChild(originalParent);
+					}
 				}
 			}
 
@@ -2751,12 +2752,6 @@
 
 			// "Remove extraneous line breaks from li."
 			removeExtraneousLineBreaks(li);
-
-			// "Repeat the following a number of times equal to extra
-			// indentation: indent the one-node list containing li."
-			for (var i = 0; i < extraIndentation; i++) {
-				indentNodes([li]);
-			}
 		}
 		break;
 
--- a/source.html	Thu May 12 12:46:02 2011 -0600
+++ b/source.html	Thu May 12 13:38:40 2011 -0600
@@ -647,7 +647,7 @@
 
 
 <h2>Normalizing sublists of a list item</h2>
-<p>When a user agent is to <dfn>normalize sublists</dfn> in an [[li]]
+<p>When a user agent is to <dfn>normalize sublists</dfn> in a [[node]]
 <var>item</var>, it must run the following steps:
 <!--
 This algorithm implies that we don't support a sublist in the middle of an
@@ -670,8 +670,8 @@
 -->
 
 <ol>
-  <li>If <var>item</var> is not <span>editable</span> or its [[parent]] is not
-  <span>editable</span>, abort these steps.
+  <li>If <var>item</var> is not an [[li]] or it is not <span>editable</span> or
+  its [[parent]] is not <span>editable</span>, abort these steps.
 
   <li>Let <var>new item</var> be null.
 
@@ -2577,6 +2577,16 @@
     * Word/OO/Firefox/Opera: Different than doing both at once (often in
       exciting ways).
     * IE/Chrome: Same as doing both at once.
+* <p>foo</p><blockquote><p>bar</p><p>baz</p></blockquote>
+  * Select "foobar" and do "ol":
+    * Word: One-item list with sublist.
+    * OO/Firefox/Chrome/Opera: One two-item list, unindented.
+    * IE9: Two one-item lists.
+  * Select "foo", do "ol", then select "bar" and do "ol":
+    * Word/OO/Chrome: One two-item list, unindented.
+    * IE9/Firefox: Two one-item lists.
+    * Opera: Two one-item lists, both unindented.
+  * Desired behavior: One-item list with sublist in both cases.
 * In an existing multi-line indented region equivalent to <blockquote>foo<br>bar<br>baz</blockquote>:
   * Select "bar", do "ol":
     * Word/OO/Firefox/Chrome: Increase indent, add "1".
@@ -2700,6 +2710,25 @@
   either <var>node</var> is an [[ol]] or [[ul]], or its [[parent]] is an [[ol]]
   or [[ul]], or it can be the [[child]] of an [[li]]; then append
   <var>node</var> to <var>node list</var>.
+  <!--
+  We exclude potential indentation elements so that selecting some random text
+  and doing indent followed by insertOrderedList will have the same result as
+  the reverse.  Specifically,
+
+    <blockquote>[foo]</blockquote> ->
+    <blockquote><ol><li>[foo]</li></ol></blockquote>
+
+  per spec and Firefox 4.0 and (more or less) Chrome 12 dev.  Opera 11.10
+  instead does <ol><li>foo</li></ol>, so the indentation vanishes.  IE9 does
+  <ol><ol><li>foo</li></ol></ol>, but that doesn't make semantic sense and is
+  different from how it would work if you reversed the commands.
+  OpenOffice.org 3.2.1 (Ubuntu) and Word 2007 both agree with the spec in this
+  case.
+  -->
+
+  <p class=XXX>Similar to a number of other places in the spec, "can be the
+  child" is not well-defined, and it's not clear what the right definition
+  should be.
 
   <li>While <var>node list</var> is not empty:
 
@@ -2790,20 +2819,6 @@
     <li>s. -->
 
     <ol>
-      <li>Let <var>extra indentation</var> equal 0.
-
-      <li>Let <var>ancestor</var> be the [[parent]] of the first member of
-      <var>sublist</var>.
-
-      <li>While <var>ancestor</var> is an <span>editable</span> [[element]]:
-
-      <ol>
-        <li>If <var>ancestor</var> is a <span>potential indentation
-        element</span>, increment <var>extra indentation</var>.
-
-        <li>Set <var>ancestor</var> to its [[parent]].
-      </ol>
-
       <li>If the first member of <var>sublist</var> is a [[p]] or [[li]] or
       [[div]], <span>set the tag name</span> of the first member of
       <var>sublist</var> to "li", and let <var>li</var> be the result.  Remove
@@ -2827,15 +2842,6 @@
         [[ownerdocument]] of the first member of <var>sublist</var>.
       </ol>
 
-      <li>Repeat the following a number of times equal to <var>extra
-      indentation</var>: for each <var>node</var> in <var>sublist</var>,
-      <span>outdent</span> <var>node</var>.
-
-      <!-- That might have created an extra <br> at some point. -->
-      <li>If the last member of <var>sublist</var> is not a [[br]] but its
-      [[nextsibling]] is, append the [[nextsibling]] of the last member of
-      <var>sublist</var> to <var>sublist</var>.
-
       <li>If the [[nextsibling]] of the last member of <var>sublist</var> is an
       [[ol]]:
 
@@ -2858,13 +2864,35 @@
         <li>Let <var>ol</var> be the [[previoussibling]] of the first member of
         <var>sublist</var>.
 
-        <li>If <var>ol</var> is not an [[ol]], let <var>ol</var> be the result
-        of calling <code data-anolis-spec=domcore
+        <li>Let <var>original parent</var> be the [[parent]] of the first
+        member of <var>sublist</var>.
+
+        <li>If <var>ol</var> is null, and <var>original parent</var> is an
+        <span>editable</span> <span>indentation element</span>, and the
+        [[previoussibling]] of <var>original parent</var> is an
+        <span>editable</span> [[ol]]:
+
+        <ol>
+          <li>Let <var>ol</var> be the [[previoussibling]] of <var>original
+          parent</var>.
+
+          <li><span>Normalize sublists</span> of <var>ol</var>'s last [[child]].
+
+          <li>If <var>ol</var>'s last [[child]] is not an <span>editable</span>
+          [[ol]], call <code data-anolis-spec=domcore
+          title=dom-Document-createElement>createElement("ol")</code> on the
+          [[ownerdocument]] of <var>ol</var>, and append the result as the last
+          [[child]] of <var>ol</var>.
+
+          <li>Set <var>ol</var> to its last [[child]].
+        </ol>
+
+        <li>If <var>ol</var> is not an <span>editable</span> [[ol]], let
+        <var>ol</var> be the result of calling <code data-anolis-spec=domcore
         title=dom-Document-createElement>createElement("ol")</code> on the
         [[ownerdocument]] of the first member of <var>sublist</var>.  Insert
-        <var>ol</var> into the [[parent]] of the first member of
-        <var>sublist</var> immediately before the first member of
-        <var>sublist</var>.
+        <var>ol</var> into <var>original parent</var> immediately before the
+        first member of <var>sublist</var>.
 
         <li>Append <var>li</var> as the last [[child]] of <var>ol</var>,
         <span>preserving ranges</span>.
@@ -2875,16 +2903,17 @@
         <li>For each <var>node</var> in <var>sublist</var>, append
         <var>node</var> as the last [[child]] of <var>li</var>,
         <span>preserving ranges</span>.
+
+        <li>If <var>original parent</var> has no [[children]], remove it from
+        its [[parent]].
+        <!-- This might happen if it's an indentation element whose previous
+        sibling is an ol, for instance. -->
       </ol>
     </ol>
 
     <li><span>Remove extraneous line breaks</span> from <var>ol</var>.
 
     <li><span>Remove extraneous line breaks</span> from <var>li</var>.
-
-    <li>Repeat the following a number of times equal to <var>extra
-    indentation</var>: <span>indent</span> the one-[[node]] list containing
-    <var>li</var>.
   </ol>
 </ol>