Simplify a bit
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Thu, 05 May 2011 14:16:28 -0600
changeset 89 7bcd2fc49ec1
parent 88 381a4d2e48ad
child 90 e4c38155e8b4
Simplify a bit
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Thu May 05 13:51:33 2011 -0600
+++ b/editcommands.html	Thu May 05 14:16:28 2011 -0600
@@ -59,7 +59,7 @@
  <li><a href=#issues><span class=secno>2 </span>Issues</a></li>
  <li><a href=#definitions><span class=secno>3 </span>Definitions</a></li>
  <li><a href=#decomposing-a-range-into-nodes><span class=secno>4 </span>Decomposing a range into nodes</a></li>
- <li><a href=#normalizing-sublists-in-a-range><span class=secno>5 </span>Normalizing sublists in a range</a></li>
+ <li><a href=#normalizing-sublists-of-a-list-item><span class=secno>5 </span>Normalizing sublists of a list item</a></li>
  <li><a href=#block-extending-a-range><span class=secno>6 </span>Block-extending a range</a></li>
  <li><a href="#clearing-an-element's-value"><span class=secno>7 </span>Clearing an element's value</a></li>
  <li><a href=#pushing-down-values><span class=secno>8 </span>Pushing down values</a></li>
@@ -600,55 +600,44 @@
 </ol>
 
 
-<h2 id=normalizing-sublists-in-a-range><span class=secno>5 </span>Normalizing sublists in a range</h2>
-<p>When a user agent is to <dfn id=normalize-sublists>normalize sublists</dfn> in a <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a>
-<var title="">range</var>, it must run the following steps:
+<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>
+<var title="">item</var>, it must run the following steps:
 
 <ol>
-  <li>Let <var title="">items</var> be a list of <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>nodes</a>, initially empty.
-
-  <li>If there is some <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code> element that is an <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#ancestor-container>ancestor container</a> of <var title="">range</var>'s
-  <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> 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> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>nodes</a>, append the last such element in
-  <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#tree-order>tree order</a> to <var title="">items</var>.
-  <!-- We don't want to add more than that, because it would disturb upper
-  parts of the DOM that we don't actually need to change. -->
-
-  <li>Append to <var title="">items</var> every <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code> element that is <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#contained>contained</a> or
-  <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#partially-contained>partially contained</a> in <var title="">range</var>.
-
-  <li>For each <var title="">item</var> in <var title="">items</var>:
+  <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>Let <var title="">new item</var> be null.
+
+  <li>While <var title="">item</var> has 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> <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>Let <var title="">new item</var> be null.
-
-    <li>While <var title="">item</var> has 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> <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>Let <var title="">child</var> be 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="">item</var>.
+
+    <li>If <var title="">child</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 <var title="">new item</var> is
+    null and <var title="">child</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node whose <code class=external data-anolis-spec=domcore title=dom-CharacterData-data><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-data>data</a></code>
+    consists of zero of more <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#space-character title="space
+    character">space characters</a>:
 
     <ol>
-      <li>Let <var title="">child</var> be 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="">item</var>.
-
-      <li>If <var title="">child</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 <var title="">new item</var> is
-      null and <var title="">child</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node whose <code class=external data-anolis-spec=domcore title=dom-CharacterData-data><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-data>data</a></code>
-      consists of zero of more <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#space-character title="space
-      character">space characters</a>:
-
-      <ol>
-        <li>Set <var title="">new item</var> to null.
-
-        <li>Insert <var title="">child</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 <var title="">item</var>
-        immediately following <var title="">item</var>, <a href=#preserving-ranges>preserving ranges</a>.
-      </ol>
-
-      <li>Otherwise:
-
-      <ol>
-        <li>If <var title="">new item</var> is null, let <var title="">new item</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("li")</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="">item</var>, then insert <var title="">new item</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 <var title="">item</var> immediately after
-        <var title="">item</var>.
-
-        <li>Insert <var title="">child</var> into <var title="">new item</var> as its first
-        <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>, <a href=#preserving-ranges>preserving ranges</a>.
+      <li>Set <var title="">new item</var> to null.
+
+      <li>Insert <var title="">child</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 <var title="">item</var>
+      immediately following <var title="">item</var>, <a href=#preserving-ranges>preserving ranges</a>.
+    </ol>
+
+    <li>Otherwise:
+
+    <ol>
+      <li>If <var title="">new item</var> is null, let <var title="">new item</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("li")</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="">item</var>, then insert <var title="">new item</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 <var title="">item</var> immediately after
+      <var title="">item</var>.
+
+      <li>Insert <var title="">child</var> into <var title="">new item</var> as its first
+      <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>, <a href=#preserving-ranges>preserving ranges</a>.
     </ol>
   </ol>
 </ol>
@@ -1949,7 +1938,13 @@
 fragments, html/body, head or things in head . . .
 
 <ol>
-  <li><a href=#normalize-sublists>Normalize sublists</a> in the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a>.
+  <li>If the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a>'s <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a> has 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>
+  <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#ancestor-container title="ancestor container">ancestor container</a>, <a href=#normalize-sublists>normalize sublists</a> of the last such
+  <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code> in <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#tree-order>tree order</a>.
+
+  <li>If the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a>'s <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-end title=concept-range-end>end</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a> has 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>
+  <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#ancestor-container title="ancestor container">ancestor container</a>, <a href=#normalize-sublists>normalize sublists</a> of the last such
+  <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code> in <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#tree-order>tree order</a>.
 
   <li><a href=#block-extend>Block-extend</a> the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a>, and let <var title="">new range</var> be
   the result.
@@ -1984,6 +1979,12 @@
   <code class=external data-anolis-spec=html title="the div element"><a href=http://www.whatwg.org/html/#the-div-element>div</a></code> or <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> and if no <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-ancestor title=concept-tree-ancestor>ancestor</a> of <var title="">node</var> is in
   <var title="">node list</var>, append <var title="">node</var> to <var title="">node list</var>.
 
+  <li>If the first member of <var title="">node list</var> is 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> whose <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>, and its <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> is 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> as well,
+  <a href=#normalize-sublists>normalize sublists</a> of its <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>.
+  <!-- Otherwise the last child of the previous sibling might be a list, which
+  the li wouldn't get appended to. -->
+
   <li><a href=#indent>Indent</a> each member of <var title="">node list</var>.
 </ol>
 
@@ -2001,23 +2002,11 @@
     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 its <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>, <a href=#preserving-ranges>preserving
     ranges</a>.  Then abort these steps.
 
-    <li>If 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="">node</var> is 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>, and 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 its <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> is an <a href=#html-element>HTML element</a>
-    with <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> <var title="">tag</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 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 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="">node</var>, <a href=#preserving-ranges>preserving ranges</a>.  Then abort these steps.
-
     <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 <var title="">node</var> is an <a href=#html-element>HTML
     element</a> with <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> <var title="">tag</var>, insert <var title="">node</var> as
     the first <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 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>, <a href=#preserving-ranges>preserving ranges</a>.
     Then abort these steps.
 
-    <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 <var title="">node</var> is 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>, and the first
-    <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 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 an <a href=#html-element>HTML element</a> with
-    <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> <var title="">tag</var>, insert <var title="">node</var> as the first <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 the first <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 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 <var title="">node</var>,
-    <a href=#preserving-ranges>preserving ranges</a>.  Then abort these steps.
-
     <li>Let <var title="">new parent</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(<var title="">tag</var>)</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="">node</var>.
 
@@ -2989,4 +2978,4 @@
 
 <script src=http://www.whatwg.org/specs/web-apps/current-work/dfn.js></script>
 <!-- vim: set expandtab shiftwidth=2 tabstop=2: -->
-</dl></ol>
\ No newline at end of file
+</dl>
\ No newline at end of file
--- a/implementation.js	Thu May 05 13:51:33 2011 -0600
+++ b/implementation.js	Thu May 05 14:16:28 2011 -0600
@@ -1111,79 +1111,46 @@
 	return ret;
 }
 
-function normalizeSublists(range) {
-	// "Let items be a list of nodes, initially empty."
-	var items = [];
-
-	// "If there is some li element that is an ancestor container of range's
-	// start and end nodes, append the last such element in tree order to
-	// items."
-	for (
-		var node = range.commonAncestorContainer;
-		node;
-		node = node.parentNode
-	) {
-		if (isHtmlElement(node, "LI")) {
-			items.push(node);
-			break;
-		}
-	}
-
-	// "Append to items every li element that is contained or partially
-	// contained in range."
-	for (
-		var node = range.commonAncestorContainer;
-		isDescendant(node, range.commonAncestorContainer);
-		node = nextNode(node)
-	) {
-		if (!isHtmlElement(node, "LI")) {
-			continue;
-		}
-
-		if (isContained(node, range) || isPartiallyContained(node, range)) {
-			items.push(node);
-		}
+function normalizeSublists(item) {
+	// "If item is not editable or its parent is not editable, abort these
+	// steps."
+	if (!isEditable(item) || !isEditable(item.parentNode)) {
+		return;
 	}
 
-	// "For each item in items:"
-	for (var i = 0; i < items.length; i++) {
-		var item = items[i];
-
-		// "Let new item be null."
-		var newItem = null;
-
-		// "While item has an ol or ul child:"
-		while ([].some.call(item.childNodes, function (node) { return isHtmlElement(node, "OL") || isHtmlElement(node, "UL") })) {
-			// "Let child be the last child of item."
-			var child = item.lastChild;
-
-			// "If child is an ol or ul, or new item is null and child is a
-			// Text node whose data consists of zero of more space characters:"
-			if (isHtmlElement(child, "OL")
-			|| isHtmlElement(child, "UL")
-			|| (!newItem && child.nodeType == Node.TEXT_NODE && /^[ \t\n\f\r]*$/.test(child.data))) {
-				// "Set new item to null."
-				newItem = null;
-
-				// "Insert child into the parent of item immediately following
-				// item, preserving ranges."
-				movePreservingRanges(child, item.parentNode, 1 + getNodeIndex(item));
-
-			// "Otherwise:"
-			} else {
-				// "If new item is null, let new item be the result of calling
-				// createElement("li") on the ownerDocument of item, then
-				// insert new item into the parent of item immediately after
-				// item."
-				if (!newItem) {
-					newItem = item.ownerDocument.createElement("li");
-					item.parentNode.insertBefore(newItem, item.nextSibling);
-				}
-
-				// "Insert child into new item as its first child, preserving
-				// ranges."
-				movePreservingRanges(child, newItem, 0);
+	// "Let new item be null."
+	var newItem = null;
+
+	// "While item has an ol or ul child:"
+	while ([].some.call(item.childNodes, function (node) { return isHtmlElement(node, "OL") || isHtmlElement(node, "UL") })) {
+		// "Let child be the last child of item."
+		var child = item.lastChild;
+
+		// "If child is an ol or ul, or new item is null and child is a Text
+		// node whose data consists of zero of more space characters:"
+		if (isHtmlElement(child, "OL")
+		|| isHtmlElement(child, "UL")
+		|| (!newItem && child.nodeType == Node.TEXT_NODE && /^[ \t\n\f\r]*$/.test(child.data))) {
+			// "Set new item to null."
+			newItem = null;
+
+			// "Insert child into the parent of item immediately following
+			// item, preserving ranges."
+			movePreservingRanges(child, item.parentNode, 1 + getNodeIndex(item));
+
+		// "Otherwise:"
+		} else {
+			// "If new item is null, let new item be the result of calling
+			// createElement("li") on the ownerDocument of item, then insert
+			// new item into the parent of item immediately after item."
+			if (!newItem) {
+				newItem = item.ownerDocument.createElement("li");
+				item.parentNode.insertBefore(newItem, item.nextSibling);
 			}
+
+			// "Insert child into new item as its first child, preserving
+			// ranges."
+			movePreservingRanges(child, newItem, 0);
 		}
 	}
 }
@@ -2224,8 +2191,31 @@
 		break;
 
 		case "indent":
-		// "Normalize sublists in the range."
-		normalizeSublists(range);
+		// "If the range's start node has an li ancestor container, normalize
+		// sublists of the last such li in tree order."
+		for (
+			var ancestorContainer = range.startContainer;
+			ancestorContainer;
+			ancestorContainer = ancestorContainer.parentNode
+		) {
+			if (isHtmlElement(ancestorContainer, "LI")) {
+				normalizeSublists(ancestorContainer);
+				break;
+			}
+		}
+
+		// "If the range's end node has an li ancestor container, normalize
+		// sublists of the last such li in tree order."
+		for (
+			var ancestorContainer = range.endContainer;
+			ancestorContainer;
+			ancestorContainer = ancestorContainer.parentNode
+		) {
+			if (isHtmlElement(ancestorContainer, "LI")) {
+				normalizeSublists(ancestorContainer);
+				break;
+			}
+		}
 
 		// "Block-extend the range, and let new range be the result."
 		var newRange = blockExtendRange(range);
--- a/source.html	Thu May 05 13:51:33 2011 -0600
+++ b/source.html	Thu May 05 14:16:28 2011 -0600
@@ -594,58 +594,46 @@
 </ol>
 
 
-<h2>Normalizing sublists in a range</h2>
-<p>When a user agent is to <dfn>normalize sublists</dfn> in a [[range]]
-<var>range</var>, it must run the following steps:
+<h2>Normalizing sublists of a list item</h2>
+<p>When a user agent is to <dfn>normalize sublists</dfn> in an [[li]]
+<var>item</var>, it must run the following steps:
 
 <ol>
-  <li>Let <var>items</var> be a list of [[nodes]], initially empty.
-
-  <li>If there is some [[li]] element that is an <span
-  data-anolis-spec=domrange>ancestor container</span> of <var>range</var>'s
-  [[rangestart]] and [[rangeend]] [[bpnodes]], append the last such element in
-  [[treeorder]] to <var>items</var>.
-  <!-- We don't want to add more than that, because it would disturb upper
-  parts of the DOM that we don't actually need to change. -->
-
-  <li>Append to <var>items</var> every [[li]] element that is [[contained]] or
-  [[partiallycontained]] in <var>range</var>.
-
-  <li>For each <var>item</var> in <var>items</var>:
+  <li>If <var>item</var> is not <span>editable</span> or its [[parent]] is not
+  <span>editable</span>, abort these steps.
+
+  <li>Let <var>new item</var> be null.
+
+  <li>While <var>item</var> has an [[ol]] or [[ul]] [[child]]:
 
   <ol>
-    <li>Let <var>new item</var> be null.
-
-    <li>While <var>item</var> has an [[ol]] or [[ul]] [[child]]:
+    <li>Let <var>child</var> be the last [[child]] of <var>item</var>.
+
+    <li>If <var>child</var> is an [[ol]] or [[ul]], or <var>new item</var> is
+    null and <var>child</var> is a [[text]] node whose <code
+    data-anolis-spec=domcore title=dom-CharacterData-data>data</code>
+    consists of zero of more <span data-anolis-spec=domcore title="space
+    character">space characters</span>:
 
     <ol>
-      <li>Let <var>child</var> be the last [[child]] of <var>item</var>.
-
-      <li>If <var>child</var> is an [[ol]] or [[ul]], or <var>new item</var> is
-      null and <var>child</var> is a [[text]] node whose <code
-      data-anolis-spec=domcore title=dom-CharacterData-data>data</code>
-      consists of zero of more <span data-anolis-spec=domcore title="space
-      character">space characters</span>:
-
-      <ol>
-        <li>Set <var>new item</var> to null.
-
-        <li>Insert <var>child</var> into the [[parent]] of <var>item</var>
-        immediately following <var>item</var>, <span>preserving ranges</span>.
-      </ol>
-
-      <li>Otherwise:
-
-      <ol>
-        <li>If <var>new item</var> is null, let <var>new item</var> be the
-        result of calling <code data-anolis-spec=domcore
-        title=dom-Document-createElement>createElement("li")</code> on the
-        [[ownerdocument]] of <var>item</var>, then insert <var>new item</var>
-        into the [[parent]] of <var>item</var> immediately after
-        <var>item</var>.
-
-        <li>Insert <var>child</var> into <var>new item</var> as its first
-        [[child]], <span>preserving ranges</span>.
+      <li>Set <var>new item</var> to null.
+
+      <li>Insert <var>child</var> into the [[parent]] of <var>item</var>
+      immediately following <var>item</var>, <span>preserving ranges</span>.
+    </ol>
+
+    <li>Otherwise:
+
+    <ol>
+      <li>If <var>new item</var> is null, let <var>new item</var> be the
+      result of calling <code data-anolis-spec=domcore
+      title=dom-Document-createElement>createElement("li")</code> on the
+      [[ownerdocument]] of <var>item</var>, then insert <var>new item</var>
+      into the [[parent]] of <var>item</var> immediately after
+      <var>item</var>.
+
+      <li>Insert <var>child</var> into <var>new item</var> as its first
+      [[child]], <span>preserving ranges</span>.
     </ol>
   </ol>
 </ol>
@@ -1969,7 +1957,13 @@
 fragments, html/body, head or things in head . . .
 
 <ol>
-  <li><span>Normalize sublists</span> in the [[range]].
+  <li>If the [[range]]'s [[rangestart]] [[bpnode]] has an [[li]]
+  [[ancestorcontainer]], <span>normalize sublists</span> of the last such
+  [[li]] in [[treeorder]].
+
+  <li>If the [[range]]'s [[rangeend]] [[bpnode]] has an [[li]]
+  [[ancestorcontainer]], <span>normalize sublists</span> of the last such
+  [[li]] in [[treeorder]].
 
   <li><span>Block-extend</span> the [[range]], and let <var>new range</var> be
   the result.
@@ -2004,6 +1998,12 @@
   [[div]] or [[ol]] or [[ul]] and if no [[ancestor]] of <var>node</var> is in
   <var>node list</var>, append <var>node</var> to <var>node list</var>.
 
+  <li>If the first member of <var>node list</var> is an [[li]] whose [[parent]]
+  is an [[ol]] or [[ul]], and its [[previoussibling]] is an [[li]] as well,
+  <span>normalize sublists</span> of its [[previoussibling]].
+  <!-- Otherwise the last child of the previous sibling might be a list, which
+  the li wouldn't get appended to. -->
+
   <li><span>Indent</span> each member of <var>node list</var>.
 </ol>
 
@@ -2021,23 +2021,11 @@
     the last [[child]] of its [[previoussibling]], <span>preserving
     ranges</span>.  Then abort these steps.
 
-    <li>If the [[previoussibling]] of <var>node</var> is an [[li]], and the
-    last [[child]] of its [[previoussibling]] is an <span>HTML element</span>
-    with [[localname]] <var>tag</var>, append <var>node</var> as the last
-    [[child]] of the last [[child]] of the [[previoussibling]] of
-    <var>node</var>, <span>preserving ranges</span>.  Then abort these steps.
-
     <li>If the [[nextsibling]] of <var>node</var> is an <span>HTML
     element</span> with [[localname]] <var>tag</var>, insert <var>node</var> as
     the first [[child]] of its [[nextsibling]], <span>preserving ranges</span>.
     Then abort these steps.
 
-    <li>If the [[nextsibling]] of <var>node</var> is an [[li]], and the first
-    [[child]] of its [[nextsibling]] is an <span>HTML element</span> with
-    [[localname]] <var>tag</var>, insert <var>node</var> as the first [[child]]
-    of the first [[child]] of the [[nextsibling]] of <var>node</var>,
-    <span>preserving ranges</span>.  Then abort these steps.
-
     <li>Let <var>new parent</var> be the result of calling <code
     data-anolis-spec=domcore
     title=dom-Document-createElement>createElement(<var>tag</var>)</code> on