From 19e4169a0a6c4641fb5bad58d008042edac90524 Mon Sep 17 00:00:00 2001 From: "kin%netscape.com" Date: Wed, 25 Jul 2001 00:10:34 +0000 Subject: [PATCH] Fix for bug #91310 (Align Right splits table) and bug #91288 (Aligning blank table cell in show all tags mode splits table) Modified WillAlign to prevent unnecessary splitting: - Don't execute emptyDiv special case code when start container of the selection is a table cell element, but not a table cell or caption. - Prevent processing of whitespace between list/table structure nodes. - Prevent splitting when processing sub lists. r=brade@netscape.com sr=attinasi@netscape.com git-svn-id: svn://10.0.0.236/trunk@99847 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsHTMLEditRules.cpp | 35 ++++++++++++++++--- .../editor/libeditor/html/nsHTMLEditRules.cpp | 35 ++++++++++++++++--- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/mozilla/editor/base/nsHTMLEditRules.cpp b/mozilla/editor/base/nsHTMLEditRules.cpp index 2282275359d..d7c6233a6b5 100644 --- a/mozilla/editor/base/nsHTMLEditRules.cpp +++ b/mozilla/editor/base/nsHTMLEditRules.cpp @@ -3134,7 +3134,25 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, nsCOMPtr theNode( do_QueryInterface(isupports ) ); if (nsTextEditUtils::IsBreak(theNode)) { - emptyDiv = PR_TRUE; + // The special case emptyDiv code (below) that consumes BRs can + // cause tables to split if the start node of the selection is + // not in a table cell or caption, for example parent is a . + // Avoid this unnecessary splitting if possible by leaving emptyDiv + // FALSE so that we fall through to the normal case alignment code. + // + // XXX: It seems a little error prone for the emptyDiv special + // case code to assume that the start node of the selection + // is the parent of the single node in the arrayOfNodes, as + // the paragraph above points out. Do we rely on the selection + // start node because of the fact that arrayOfNodes can be empty? + // We should probably revisit this issue. - kin + + nsCOMPtr parent; + PRInt32 offset; + res = mHTMLEditor->GetStartNodeAndOffset(aSelection, address_of(parent), &offset); + + if (!nsHTMLEditUtils::IsTableElement(parent) || nsHTMLEditUtils::IsTableCellOrCaption(parent)) + emptyDiv = PR_TRUE; } } if (emptyDiv) @@ -3215,10 +3233,19 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, continue; } - // if it's a table element (but not a table) or a list item, forget any "current" div, and - // instead put divs inside the appropriate block (td, li, etc) + // Skip insignificant formatting text nodes to prevent + // unnecessary structure splitting! + if (nsEditor::IsTextNode(curNode) && + ((nsHTMLEditUtils::IsTableElement(curParent) && !nsHTMLEditUtils::IsTableCellOrCaption(curParent)) || + nsHTMLEditUtils::IsList(curParent))) + continue; + + // if it's a table element (but not a table) or a list item, or a list + // inside a list, forget any "current" div, and instead put divs inside + // the appropriate block (td, li, etc) if ( (nsHTMLEditUtils::IsTableElement(curNode) && !nsHTMLEditUtils::IsTable(curNode)) - || nsHTMLEditUtils::IsListItem(curNode) ) + || nsHTMLEditUtils::IsListItem(curNode) + || (nsHTMLEditUtils::IsList(curNode) && nsHTMLEditUtils::IsList(curParent))) { res = AlignInnerBlocks(curNode, alignType); if (NS_FAILED(res)) return res; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp index 2282275359d..d7c6233a6b5 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp @@ -3134,7 +3134,25 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, nsCOMPtr theNode( do_QueryInterface(isupports ) ); if (nsTextEditUtils::IsBreak(theNode)) { - emptyDiv = PR_TRUE; + // The special case emptyDiv code (below) that consumes BRs can + // cause tables to split if the start node of the selection is + // not in a table cell or caption, for example parent is a . + // Avoid this unnecessary splitting if possible by leaving emptyDiv + // FALSE so that we fall through to the normal case alignment code. + // + // XXX: It seems a little error prone for the emptyDiv special + // case code to assume that the start node of the selection + // is the parent of the single node in the arrayOfNodes, as + // the paragraph above points out. Do we rely on the selection + // start node because of the fact that arrayOfNodes can be empty? + // We should probably revisit this issue. - kin + + nsCOMPtr parent; + PRInt32 offset; + res = mHTMLEditor->GetStartNodeAndOffset(aSelection, address_of(parent), &offset); + + if (!nsHTMLEditUtils::IsTableElement(parent) || nsHTMLEditUtils::IsTableCellOrCaption(parent)) + emptyDiv = PR_TRUE; } } if (emptyDiv) @@ -3215,10 +3233,19 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, continue; } - // if it's a table element (but not a table) or a list item, forget any "current" div, and - // instead put divs inside the appropriate block (td, li, etc) + // Skip insignificant formatting text nodes to prevent + // unnecessary structure splitting! + if (nsEditor::IsTextNode(curNode) && + ((nsHTMLEditUtils::IsTableElement(curParent) && !nsHTMLEditUtils::IsTableCellOrCaption(curParent)) || + nsHTMLEditUtils::IsList(curParent))) + continue; + + // if it's a table element (but not a table) or a list item, or a list + // inside a list, forget any "current" div, and instead put divs inside + // the appropriate block (td, li, etc) if ( (nsHTMLEditUtils::IsTableElement(curNode) && !nsHTMLEditUtils::IsTable(curNode)) - || nsHTMLEditUtils::IsListItem(curNode) ) + || nsHTMLEditUtils::IsListItem(curNode) + || (nsHTMLEditUtils::IsList(curNode) && nsHTMLEditUtils::IsList(curParent))) { res = AlignInnerBlocks(curNode, alignType); if (NS_FAILED(res)) return res;