--- a/editcommands.html Tue Jul 05 11:39:05 2011 -0600
+++ b/editcommands.html Tue Jul 05 12:06:30 2011 -0600
@@ -1763,8 +1763,7 @@
<li>If <var title="">new value</var> is null, abort this algorithm.
- <li>If <var title="">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>, <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code>, or <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#comment>Comment</a></code> node, and
- is an <a href=#allowed-child>allowed child</a> of "span":
+ <li>If <var title="">node</var> is an <a href=#allowed-child>allowed child</a> of "span":
<ol>
<!-- Even if the value matches, we stick it in a preceding sibling if
@@ -1814,10 +1813,6 @@
<li>Abort this algorithm.
</ol>
- <!-- At this point we have to make a new element as a wrapper. This isn't
- worth the effort for comments, so abort in that case. -->
- <li>If <var title="">node</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#comment>Comment</a></code>, abort this algorithm.
-
<li>If the <a href=#effective-value>effective value</a> of <var title="">command</var> is <var title="">new
value</var> on <var title="">node</var>, abort this algorithm.
@@ -3735,8 +3730,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>Needs nbsp magic.
-
<ol>
<li>If <var title="">range</var> is null, abort these steps and do nothing.
@@ -3923,7 +3916,8 @@
<li>If <var title="">start node</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#text>Text</a></code> node,
call <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData()</a></code> on it, with <var title="">start offset</var> as the first
argument and (<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> − <var title="">start
- offset</var>) as the second argument.
+ offset</var>) as the second argument. Then <a href=#canonicalize-whitespace>canonicalize
+ whitespace</a> at (<var title="">start node</var>, <var title="">start offset</var>).
<li>Let <var title="">node list</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.
@@ -3962,7 +3956,8 @@
</ol>
<li>If <var title="">end node</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#text>Text</a></code> node, call
- <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData(0, <var title="">end offset</var>)</a></code> on it.
+ <code class=external data-anolis-spec=domcore title=dom-CharacterData-deleteData><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-characterdata-deletedata>deleteData(0, <var title="">end offset</var>)</a></code> on it, then <a href=#canonicalize-whitespace>canonicalize
+ whitespace</a> at (<var title="">end node</var>, 0).
</ol>
<!--
--- a/implementation.js Tue Jul 05 11:39:05 2011 -0600
+++ b/implementation.js Tue Jul 05 12:06:30 2011 -0600
@@ -290,14 +290,29 @@
return ret;
}
+// "The length of a Node node is the following, depending on node:
+//
+// ProcessingInstruction
+// DocumentType
+// Always 0.
+// Text
+// Comment
+// node's length.
+// Any other node
+// node's childNodes's length."
function getNodeLength(node) {
- if (node.nodeType == Node.TEXT_NODE
- || node.nodeType == Node.COMMENT_NODE
- || node.nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
- return node.data.length;
- }
-
- return node.childNodes.length;
+ switch (node.nodeType) {
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ case Node.DOCUMENT_TYPE_NODE:
+ return 0;
+
+ case Node.TEXT_NODE:
+ case Node.COMMENT_NODE:
+ return node.length;
+
+ default:
+ return node.childNodes.length;
+ }
}
/**
@@ -2283,13 +2298,8 @@
return;
}
- // "If node is an Element, Text, or Comment node, and is an allowed child
- // of "span":"
- if ((node.nodeType == Node.ELEMENT_NODE
- || node.nodeType == Node.TEXT_NODE
- || node.nodeType == Node.COMMENT_NODE
- || node.nodeType == Node.PROCESSING_INSTRUCTION_NODE)
- && isAllowedChild(node, "span")) {
+ // "If node is an allowed child of "span":"
+ if (isAllowedChild(node, "span")) {
// "Reorder modifiable descendants of node's previousSibling."
reorderModifiableDescendants(node.previousSibling, command, newValue);
@@ -2344,12 +2354,6 @@
return;
}
- // "If node is a Comment or ProcessingInstruction, abort this algorithm."
- if (node.nodeType == Node.COMMENT_NODE
- || node.nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
- return;
- }
-
// "If the effective value of command is new value on node, abort this
// algorithm."
if (valuesEqual(command, getEffectiveValue(node, command), newValue)) {
@@ -4279,10 +4283,12 @@
} else {
// "If start node is an editable Text node, call deleteData() on it,
// with start offset as the first argument and (length of start node −
- // start offset) as the second argument."
+ // start offset) as the second argument. Then canonicalize whitespace
+ // at (start node, start offset)."
if (isEditable(startNode)
&& startNode.nodeType == Node.TEXT_NODE) {
startNode.deleteData(startOffset, getNodeLength(startNode) - startOffset);
+ canonicalizeWhitespace(startNode, startOffset);
}
// "Let node list be a list of nodes, initially empty."
@@ -4330,10 +4336,11 @@
}
// "If end node is an editable Text node, call deleteData(0, end
- // offset) on it."
+ // offset) on it, then canonicalize whitespace at (end node, 0)."
if (isEditable(endNode)
&& endNode.nodeType == Node.TEXT_NODE) {
endNode.deleteData(0, endOffset);
+ canonicalizeWhitespace(endNode, 0);
}
}
--- a/source.html Tue Jul 05 11:39:05 2011 -0600
+++ b/source.html Tue Jul 05 12:06:30 2011 -0600
@@ -1723,8 +1723,7 @@
<li>If <var>new value</var> is null, abort this algorithm.
- <li>If <var>node</var> is an [[element]], [[text]], or [[comment]] node, and
- is an <span>allowed child</span> of "span":
+ <li>If <var>node</var> is an <span>allowed child</span> of "span":
<ol>
<!-- Even if the value matches, we stick it in a preceding sibling if
@@ -1774,10 +1773,6 @@
<li>Abort this algorithm.
</ol>
- <!-- At this point we have to make a new element as a wrapper. This isn't
- worth the effort for comments, so abort in that case. -->
- <li>If <var>node</var> is a [[comment]], abort this algorithm.
-
<li>If the <span>effective value</span> of <var>command</var> is <var>new
value</var> on <var>node</var>, abort this algorithm.
@@ -3722,8 +3717,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>Needs nbsp magic.
-
<ol>
<li>If <var>range</var> is null, abort these steps and do nothing.
@@ -3911,7 +3904,8 @@
<li>If <var>start node</var> is an <span>editable</span> [[text]] node,
call [[deletedata|]] on it, with <var>start offset</var> as the first
argument and ([[nodelength]] of <var>start node</var> − <var>start
- offset</var>) as the second argument.
+ offset</var>) as the second argument. Then <span>canonicalize
+ whitespace</span> at (<var>start node</var>, <var>start offset</var>).
<li>Let <var>node list</var> be a list of [[nodes]], initially empty.
@@ -3950,7 +3944,8 @@
</ol>
<li>If <var>end node</var> is an <span>editable</span> [[text]] node, call
- [[deletedata|0, <var>end offset</var>]] on it.
+ [[deletedata|0, <var>end offset</var>]] on it, then <span>canonicalize
+ whitespace</span> at (<var>end node</var>, 0).
</ol>
<!--
--- a/tests.js Tue Jul 05 11:39:05 2011 -0600
+++ b/tests.js Tue Jul 05 12:06:30 2011 -0600
@@ -514,6 +514,8 @@
'<dl><dt>foo[<dd>]bar</dl>',
'<dl><dt>foo[<dt>]bar<dd>baz</dl>',
'<dl><dt>foo<dd>bar[<dd>]baz</dl>',
+
+ '<b>foo [ </b>bar]',
],
//@}
fontname: [