Improve removeFormat a bit more
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Wed, 13 Apr 2011 08:29:31 -0600
changeset 61 7dee1a3d81fd
parent 60 9c1dd060cb0c
child 62 e6d9b757544c
Improve removeFormat a bit more
autoimplementation.html
editcommands.html
implementation.js
source.html
--- a/autoimplementation.html	Wed Apr 13 08:26:19 2011 -0600
+++ b/autoimplementation.html	Wed Apr 13 08:29:31 2011 -0600
@@ -552,6 +552,7 @@
 		'[foo<nonexistentelement style="display: block">bar</nonexistentelement>baz]',
 		'foo<nonexistentelement style="display: block">b[a]r</nonexistentelement>baz',
 
+		// Random stuff
 		'[foo<span id=foo>bar</span>baz]',
 		'foo<span id=foo>b[a]r</span>baz',
 		'[foo<span class=foo>bar</span>baz]',
@@ -563,7 +564,9 @@
 		'<p style="font-weight: bold">foo[bar]baz</p>',
 		'<b><p style="font-weight: bold">foo[bar]baz</p></b>',
 		'<p style="font-variant: small-caps">foo[bar]baz</p>',
+		'{<p style="font-variant: small-caps">foobarbaz</p>}',
 		'<p style="text-indent: 2em">foo[bar]baz</p>',
+		'{<p style="text-indent: 2em">foobarbaz</p>}',
 	],
 	strikethrough: [
 		'foo[bar]baz',
--- a/editcommands.html	Wed Apr 13 08:26:19 2011 -0600
+++ b/editcommands.html	Wed Apr 13 08:29:31 2011 -0600
@@ -27,7 +27,7 @@
 <body class=draft>
 <div class=head id=head>
 <h1>HTML Editing Commands</h1>
-<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-12-april-2011>Work in Progress &mdash; Last Update 12 April 2011</h2>
+<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-13-april-2011>Work in Progress &mdash; Last Update 13 April 2011</h2>
 <dl>
  <dt>Editor
  <dd>Aryeh Gregor &lt;ayg+spec@aryeh.name&gt;
@@ -1740,7 +1740,9 @@
 approach is probably to declare these elements modifiable; this would roughly
 match what browsers do.  I'm ignoring the issue for now, because such elements
 cannot actually be created by implementations of execCommand(), so they're not
-likely to be common.
+likely to be common.  Also, the way pushing down styles works right now is that
+the element is destroyed and the style is recreated, which isn't going to work
+for elements like <code> or <tt> or <mark> that we don't normally create.
 -->
 
 <dd><strong>Action</strong>:
@@ -1749,7 +1751,11 @@
   <li><a href=#decompose>Decompose</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="">node list</var> be the
   result.
 
-  <li>Let <var title="">affected elements</var> be a list of all <a href=#html-element title="HTML
+  <li>For each <var title="">node</var> in <var title="">node list</var>, unset the <code class=external data-anolis-spec=html title="the style attribute"><a href=http://www.whatwg.org/html/#the-style-attribute>style</a></code>
+  attribute of <var title="">node</var> (if it's 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>) and then all its
+  <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-descendant title=concept-tree-descendant>descendants</a>.
+
+  <li>Let <var title="">elements to remove</var> be a list of all <a href=#html-element title="HTML
   element">HTML elements</a> that are the same as or <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-descendant title=concept-tree-descendant>descendants</a> of some
   member of <var title="">node list</var> and have non-null <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>parents</a> and satisfy
   (insert conditions here).
@@ -1761,7 +1767,7 @@
   interactive".  Except this has weird corner-cases like ins and del that are
   sometimes phrasing and sometimes flow.
 
-  <li>For each <var title="">element</var> in <var title="">affected elements</var>:
+  <li>For each <var title="">element</var> in <var title="">elements to remove</var>:
 
   <ol>
     <li>While <var title="">element</var> has <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>, insert 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>
--- a/implementation.js	Wed Apr 13 08:26:19 2011 -0600
+++ b/implementation.js	Wed Apr 13 08:29:31 2011 -0600
@@ -1955,10 +1955,24 @@
 		// "Decompose the range, and let node list be the result."
 		var nodeList = decomposeRange(range);
 
-		// "Let affected elements be a list of all HTML elements that are the
+		// "For each node in node list, unset the style attribute of node (if
+		// it's an Element) and then all its Element descendants."
+		for (var i = 0; i < nodeList.length; i++) {
+			for (
+				var node = nodeList[i];
+				node != nextNodeDescendants(nodeList[i]);
+				node = nextNode(node)
+			) {
+				if (node.nodeType == Node.ELEMENT_NODE) {
+					node.removeAttribute("style");
+				}
+			}
+		}
+
+		// "Let elements to remove be a list of all HTML elements that are the
 		// same as or descendants of some member of node list and have non-null
 		// parents and satisfy (insert conditions here)."
-		var affectedElements = [];
+		var elementsToRemove = [];
 		for (var i = 0; i < nodeList.length; i++) {
 			for (
 				var node = nodeList[i];
@@ -1969,14 +1983,14 @@
 				&& node.parentNode
 				// FIXME: Extremely partial list for testing
 				&& ["A", "AUDIO", "BR", "DIV", "HR", "IMG", "P", "TD", "VIDEO", "WBR"].indexOf(node.tagName) == -1) {
-					affectedElements.push(node);
+					elementsToRemove.push(node);
 				}
 			}
 		}
 
-		// "For each element in affected elements:"
-		for (var i = 0; i < affectedElements.length; i++) {
-			var element = affectedElements[i];
+		// "For each element in elements to remove:"
+		for (var i = 0; i < elementsToRemove.length; i++) {
+			var element = elementsToRemove[i];
 
 			// "While element has children, insert the first child of element
 			// into the parent of element immediately before element,
--- a/source.html	Wed Apr 13 08:26:19 2011 -0600
+++ b/source.html	Wed Apr 13 08:29:31 2011 -0600
@@ -1770,7 +1770,9 @@
 approach is probably to declare these elements modifiable; this would roughly
 match what browsers do.  I'm ignoring the issue for now, because such elements
 cannot actually be created by implementations of execCommand(), so they're not
-likely to be common.
+likely to be common.  Also, the way pushing down styles works right now is that
+the element is destroyed and the style is recreated, which isn't going to work
+for elements like <code> or <tt> or <mark> that we don't normally create.
 -->
 
 <dd><strong>Action</strong>:
@@ -1779,7 +1781,11 @@
   <li><span>Decompose</span> the [[range]], and let <var>node list</var> be the
   result.
 
-  <li>Let <var>affected elements</var> be a list of all <span title="HTML
+  <li>For each <var>node</var> in <var>node list</var>, unset the [[style]]
+  attribute of <var>node</var> (if it's an [[element]]) and then all its
+  [[element]] [[descendants]].
+
+  <li>Let <var>elements to remove</var> be a list of all <span title="HTML
   element">HTML elements</span> that are the same as or [[descendants]] of some
   member of <var>node list</var> and have non-null [[parents]] and satisfy
   (insert conditions here).
@@ -1791,7 +1797,7 @@
   interactive".  Except this has weird corner-cases like ins and del that are
   sometimes phrasing and sometimes flow.
 
-  <li>For each <var>element</var> in <var>affected elements</var>:
+  <li>For each <var>element</var> in <var>elements to remove</var>:
 
   <ol>
     <li>While <var>element</var> has [[children]], insert the first [[child]]
@@ -1806,6 +1812,11 @@
   of the resulting [[nodes]], with <var>command</var> and <var>new value</var>
   as given.
 
+  <p class=XXX>This has no relationship to what browsers actually do, although
+  it mostly works okay.  If I don't throw it out and replace it with something
+  more like what browsers do, it still probably needs refinement to handle some
+  elements that it doesn't deal with yet.
+
   <table>
     <tr><th><var>command</var> <th><var>new value</var>
     <tr><td>subscript <td>"baseline"