Browse files

Ingest https://codereview.appspot.com/6814085/

git-svn-id: http://closure-library.googlecode.com/svn/trunk@2282 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
1 parent f0541c2 commit 9ba5670d1709a75a3f95d332814cc32dde3f04df nnaze@google.com committed Nov 8, 2012
View
19 closure/goog/editor/plugins/removeformatting.js
@@ -185,9 +185,16 @@ goog.editor.plugins.RemoveFormatting.prototype.removeFormatting_ = function() {
* @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 @@ goog.editor.plugins.RemoveFormatting.prototype.convertSelectedHtmlText_ =
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) {
View
20 closure/goog/editor/plugins/removeformatting_test.html
@@ -32,7 +32,17 @@
</head>
<body>
+<!--
+This wrapper table is outside the mock editor and only used ensure that it is
+ignored by the tests.
+-->
+<table>
+<tr>
+<td>
<div id="html"></div>
+</td>
+</tr>
+</table>
<div id="abcde">abcde</div>
@@ -851,16 +861,18 @@
div.innerHTML = "foo<table><tr><td>foo</td></tr></table>bar";
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]));
}
/**

0 comments on commit 9ba5670

Please sign in to comment.