diff --git a/mozilla/editor/base/CreateElementTxn.cpp b/mozilla/editor/base/CreateElementTxn.cpp index a59786179b2..247218fd198 100644 --- a/mozilla/editor/base/CreateElementTxn.cpp +++ b/mozilla/editor/base/CreateElementTxn.cpp @@ -108,6 +108,8 @@ NS_IMETHODIMP CreateElementTxn::Do(void) if (NS_FAILED(result)) return result; if (!newElement) return NS_ERROR_NULL_POINTER; mNewNode = do_QueryInterface(newElement); + // Try to insert formatting whitespace for the new node: + mEditor->MarkNodeDirty(mNewNode); } NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewNode)), "could not create element."); if (!mNewNode) return NS_ERROR_NULL_POINTER; @@ -135,9 +137,6 @@ NS_IMETHODIMP CreateElementTxn::Do(void) result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode)); if (NS_FAILED(result)) return result; - // Try to insert formatting whitespace for the new node: - mEditor->InsertFormattingForNode(mNewNode); - // only set selection to insertion point if editor gives permission PRBool bAdjustSelection; mEditor->ShouldTxnSetSelection(&bAdjustSelection); diff --git a/mozilla/editor/base/InsertElementTxn.cpp b/mozilla/editor/base/InsertElementTxn.cpp index fbe7cdc6fad..155faf273db 100644 --- a/mozilla/editor/base/InsertElementTxn.cpp +++ b/mozilla/editor/base/InsertElementTxn.cpp @@ -23,6 +23,7 @@ #include "InsertElementTxn.h" #include "nsIDOMSelection.h" #include "nsIContent.h" +#include "nsIDOMNodeList.h" #ifdef NS_DEBUG static PRBool gNoisy = PR_FALSE; @@ -78,37 +79,27 @@ NS_IMETHODIMP InsertElementTxn::Do(void) if (!mNode || !mParent) return NS_ERROR_NOT_INITIALIZED; - nsresult result; + nsCOMPtr childNodes; nsCOMPtrrefNode; - //if (0!=mOffset) - { // get a ref node - PRInt32 i=0; - result = mParent->GetFirstChild(getter_AddRefs(refNode)); - if (NS_SUCCEEDED(result) && refNode) - { - for (; inextSib; - result = refNode->GetNextSibling(getter_AddRefs(nextSib)); - if (NS_FAILED(result)) { - break; // couldn't get a next sibling, so make aNode the first child - } - refNode = do_QueryInterface(nextSib); - if (!refNode) { - break; // couldn't get a next sibling, so make aNode the first child - } - } - } + nsresult result = mParent->GetChildNodes(getter_AddRefs(childNodes)); + if (NS_FAILED(result)) return result; + if (childNodes) + { + PRUint32 count; + childNodes->GetLength(&count); + if (mOffset>count) mOffset = count; + result = childNodes->Item(mOffset, getter_AddRefs(refNode)); + if (NS_FAILED(result)) return result; + // note, it's ok for mRefNode to be null. that means append } + mEditor->MarkNodeDirty(mNode); + nsCOMPtr resultNode; result = mParent->InsertBefore(mNode, refNode, getter_AddRefs(resultNode)); if (NS_FAILED(result)) return result; if (!resultNode) return NS_ERROR_NULL_POINTER; - // Try to insert formatting whitespace for the new node: - mEditor->InsertFormattingForNode(resultNode); - // only set selection to insertion point if editor gives permission PRBool bAdjustSelection; mEditor->ShouldTxnSetSelection(&bAdjustSelection); diff --git a/mozilla/editor/libeditor/base/CreateElementTxn.cpp b/mozilla/editor/libeditor/base/CreateElementTxn.cpp index a59786179b2..247218fd198 100644 --- a/mozilla/editor/libeditor/base/CreateElementTxn.cpp +++ b/mozilla/editor/libeditor/base/CreateElementTxn.cpp @@ -108,6 +108,8 @@ NS_IMETHODIMP CreateElementTxn::Do(void) if (NS_FAILED(result)) return result; if (!newElement) return NS_ERROR_NULL_POINTER; mNewNode = do_QueryInterface(newElement); + // Try to insert formatting whitespace for the new node: + mEditor->MarkNodeDirty(mNewNode); } NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewNode)), "could not create element."); if (!mNewNode) return NS_ERROR_NULL_POINTER; @@ -135,9 +137,6 @@ NS_IMETHODIMP CreateElementTxn::Do(void) result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode)); if (NS_FAILED(result)) return result; - // Try to insert formatting whitespace for the new node: - mEditor->InsertFormattingForNode(mNewNode); - // only set selection to insertion point if editor gives permission PRBool bAdjustSelection; mEditor->ShouldTxnSetSelection(&bAdjustSelection); diff --git a/mozilla/editor/libeditor/base/InsertElementTxn.cpp b/mozilla/editor/libeditor/base/InsertElementTxn.cpp index fbe7cdc6fad..155faf273db 100644 --- a/mozilla/editor/libeditor/base/InsertElementTxn.cpp +++ b/mozilla/editor/libeditor/base/InsertElementTxn.cpp @@ -23,6 +23,7 @@ #include "InsertElementTxn.h" #include "nsIDOMSelection.h" #include "nsIContent.h" +#include "nsIDOMNodeList.h" #ifdef NS_DEBUG static PRBool gNoisy = PR_FALSE; @@ -78,37 +79,27 @@ NS_IMETHODIMP InsertElementTxn::Do(void) if (!mNode || !mParent) return NS_ERROR_NOT_INITIALIZED; - nsresult result; + nsCOMPtr childNodes; nsCOMPtrrefNode; - //if (0!=mOffset) - { // get a ref node - PRInt32 i=0; - result = mParent->GetFirstChild(getter_AddRefs(refNode)); - if (NS_SUCCEEDED(result) && refNode) - { - for (; inextSib; - result = refNode->GetNextSibling(getter_AddRefs(nextSib)); - if (NS_FAILED(result)) { - break; // couldn't get a next sibling, so make aNode the first child - } - refNode = do_QueryInterface(nextSib); - if (!refNode) { - break; // couldn't get a next sibling, so make aNode the first child - } - } - } + nsresult result = mParent->GetChildNodes(getter_AddRefs(childNodes)); + if (NS_FAILED(result)) return result; + if (childNodes) + { + PRUint32 count; + childNodes->GetLength(&count); + if (mOffset>count) mOffset = count; + result = childNodes->Item(mOffset, getter_AddRefs(refNode)); + if (NS_FAILED(result)) return result; + // note, it's ok for mRefNode to be null. that means append } + mEditor->MarkNodeDirty(mNode); + nsCOMPtr resultNode; result = mParent->InsertBefore(mNode, refNode, getter_AddRefs(resultNode)); if (NS_FAILED(result)) return result; if (!resultNode) return NS_ERROR_NULL_POINTER; - // Try to insert formatting whitespace for the new node: - mEditor->InsertFormattingForNode(resultNode); - // only set selection to insertion point if editor gives permission PRBool bAdjustSelection; mEditor->ShouldTxnSetSelection(&bAdjustSelection); diff --git a/mozilla/editor/public/nsIEditor.h b/mozilla/editor/public/nsIEditor.h index f8e70c9eb33..ef725829e65 100644 --- a/mozilla/editor/public/nsIEditor.h +++ b/mozilla/editor/public/nsIEditor.h @@ -393,11 +393,11 @@ public: NS_IMETHOD InsertNoneditableTextNode(nsIDOMNode* aParent, PRInt32 aOffset, nsString& aStr) = 0; /** - * InsertFormattingForNode() inserts formatting before and/or after a node. + * InsertFormattingForNode() sets a special dirty attribute on the node. * Usually this will be called immediately after creating a new node. * @param aNode The node for which to insert formatting. */ - NS_IMETHOD InsertFormattingForNode(nsIDOMNode* aNode) = 0; + NS_IMETHOD MarkNodeDirty(nsIDOMNode* aNode) = 0; /* ------------ Output methods -------------- */