Index: closure/goog/editor/plugins/removeformatting_test.html
===================================================================
--- closure/goog/editor/plugins/removeformatting_test.html (revision 2267)
+++ closure/goog/editor/plugins/removeformatting_test.html (working copy)
@@ -32,7 +32,17 @@
+
+
abcde
@@ -851,16 +861,18 @@
div.innerHTML = "foobar";
assertTrue('Full table is in table',
- !!goog.editor.plugins.RemoveFormatting.getTableAncestor_(
- div.childNodes[1]));
+ !!FORMATTER.getTableAncestor_(div.childNodes[1]));
assertFalse('Outside of table',
- !!goog.editor.plugins.RemoveFormatting.getTableAncestor_(div.firstChild));
+ !!FORMATTER.getTableAncestor_(div.firstChild));
assertTrue('Table cell is in table',
- !!goog.editor.plugins.RemoveFormatting.getTableAncestor_(
+ !!FORMATTER.getTableAncestor_(
div.childNodes[1].firstChild.firstChild.firstChild));
+ div.innerHTML = "foo";
+ assertNull('No table inside field.',
+ FORMATTER.getTableAncestor_(div.childNodes[0]));
}
/**
Index: closure/goog/editor/plugins/removeformatting.js
===================================================================
--- closure/goog/editor/plugins/removeformatting.js (revision 2267)
+++ closure/goog/editor/plugins/removeformatting.js (working copy)
@@ -185,9 +185,16 @@
* @return {Node} The table, or null if one was not found.
* @private
*/
-goog.editor.plugins.RemoveFormatting.getTableAncestor_ = function(nodeToCheck) {
- return goog.dom.getAncestor(nodeToCheck,
- function(node) { return node.tagName == goog.dom.TagName.TABLE; }, true);
+goog.editor.plugins.RemoveFormatting.prototype.getTableAncestor_ = function(
+ nodeToCheck) {
+ var fieldElement = this.getFieldObject().getElement();
+ while (nodeToCheck && nodeToCheck != fieldElement) {
+ if (nodeToCheck.tagName == goog.dom.TagName.TABLE) {
+ return nodeToCheck;
+ }
+ nodeToCheck = nodeToCheck.parentNode;
+ }
+ return null;
};
@@ -495,10 +502,8 @@
var expandedRange = goog.editor.range.expand(range,
this.getFieldObject().getElement());
- var startInTable = goog.editor.plugins.RemoveFormatting.getTableAncestor_(
- expandedRange.getStartNode());
- var endInTable = goog.editor.plugins.RemoveFormatting.getTableAncestor_(
- expandedRange.getEndNode());
+ var startInTable = this.getTableAncestor_(expandedRange.getStartNode());
+ var endInTable = this.getTableAncestor_(expandedRange.getEndNode());
if (startInTable || endInTable) {
if (startInTable == endInTable) {