bug fixes to delete range, plus some debugging printf's

This commit is contained in:
buster%netscape.com 1999-01-21 02:29:52 +00:00
parent 084796f828
commit 1bf76fe187
6 changed files with 210 additions and 21 deletions

View File

@ -25,6 +25,10 @@
#include "TransactionFactory.h"
#include "nsISupportsArray.h"
#ifdef NS_DEBUG
#include "nsIDOMElement.h"
#endif
static NS_DEFINE_IID(kDeleteTextTxnIID, DELETE_TEXT_TXN_IID);
static NS_DEFINE_IID(kDeleteElementTxnIID, DELETE_ELEMENT_TXN_IID);
@ -115,10 +119,6 @@ nsresult DeleteRangeTxn::Do(void)
{
// delete the relevant content in the end node
result = CreateTxnsToDeleteContent(mEndParent, mEndOffset, nsIEditor::eRTL);
if (NS_SUCCEEDED(result))
{ // now we have all our child transactions, do them
result = EditAggregateTxn::Do();
}
}
}
}
@ -357,9 +357,33 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
}
// test if child is an ancestor of the other node. If it is, don't process this parent anymore
PRInt32 index;
index = ancestorList->IndexOf((nsISupports*)child);
nsISupports *childAsISupports;
child->QueryInterface(nsISupports::IID(), (void **)&childAsISupports);
index = ancestorList->IndexOf(childAsISupports);
if (-1!=index)
break;
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> childElement=child;
nsAutoString childElementTag="text node";
if (childElement)
childElement->GetTagName(childElementTag);
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *c, *p;
c = childElementTag.ToNewCString();
p = parentElementTag.ToNewCString();
if (c&&p)
{
printf("DeleteRangeTxn (1): building txn to delete child %s (pointer address %p) from parent %s\n",
c, childAsISupports, p);
delete [] c;
delete [] p;
}
// end debug output
#endif
DeleteElementTxn *txn;
result = TransactionFactory::GetNewTransaction(kDeleteElementTxnIID, (EditTxn **)&txn);
if (nsnull!=txn)
@ -387,6 +411,8 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
result = child->GetParentNode(getter_AddRefs(parent));
while ((NS_SUCCEEDED(result)) && parent)
{
if (parent==aCommonParent)
break; // notice that when we go up the aLastChild parent chain, we don't touch aCommonParent
while ((NS_SUCCEEDED(result)) && child)
{ // this loop starts with the first sibling of an ancestor of aFirstChild
nsCOMPtr<nsIDOMNode> temp = child;
@ -398,6 +424,27 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
index = ancestorList->IndexOf((nsISupports*)child);
if (-1!=index)
break;
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> childElement=child;
nsAutoString childElementTag="text node";
if (childElement)
childElement->GetTagName(childElementTag);
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *c, *p;
c = childElementTag.ToNewCString();
p = parentElementTag.ToNewCString();
if (c&&p)
{
printf("DeleteRangeTxn (2): building txn to delete child %s from parent %s\n", c, p);
delete [] c;
delete [] p;
}
// end debug output
#endif
DeleteElementTxn *txn;
result = TransactionFactory::GetNewTransaction(kDeleteElementTxnIID, (EditTxn **)&txn);
if (nsnull!=txn)
@ -409,8 +456,6 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
return NS_ERROR_NULL_POINTER;
}
}
if (parent==aCommonParent)
break;
child = parent;
nsCOMPtr<nsIDOMNode> temp=parent;
result = temp->GetParentNode(getter_AddRefs(parent));
@ -434,6 +479,21 @@ nsresult DeleteRangeTxn::BuildAncestorList(nsIDOMNode *aNode, nsISupportsArray *
nsISupports * parentAsISupports;
parent->QueryInterface(nsISupports::IID(), (void **)&parentAsISupports);
aList->AppendElement(parentAsISupports);
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *p;
p = parentElementTag.ToNewCString();
if (p)
{
printf("BuildAncestorList: adding parent %s (pointer address %p)\n", p, parentAsISupports);
delete [] p;
}
// end debug output
#endif
child = parent;
nsCOMPtr<nsIDOMNode> temp=parent;
result = temp->GetParentNode(getter_AddRefs(parent));

View File

@ -44,6 +44,7 @@ EditAggregateTxn::~EditAggregateTxn()
nsresult EditAggregateTxn::Do(void)
{
printf("aggregate txn %p Do\n", this);
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
if (nsnull!=mChildren)
{
@ -52,6 +53,7 @@ nsresult EditAggregateTxn::Do(void)
for (i=0; i<count; i++)
{
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
printf("aggregate txn %p: calling Do for txn %p, index %d\n", this, txn, i);
result = txn->Do();
if (NS_FAILED(result))
break;
@ -132,6 +134,7 @@ nsresult EditAggregateTxn::AppendChild(EditTxn *aTxn)
{
if ((nsnull!=mChildren) && (nsnull!=aTxn))
{
printf("aggregate txn %p: appending txn %p\n", this, aTxn);
mChildren->AppendElement(aTxn);
return NS_OK;
}

View File

@ -25,6 +25,10 @@
#include "TransactionFactory.h"
#include "nsISupportsArray.h"
#ifdef NS_DEBUG
#include "nsIDOMElement.h"
#endif
static NS_DEFINE_IID(kDeleteTextTxnIID, DELETE_TEXT_TXN_IID);
static NS_DEFINE_IID(kDeleteElementTxnIID, DELETE_ELEMENT_TXN_IID);
@ -115,10 +119,6 @@ nsresult DeleteRangeTxn::Do(void)
{
// delete the relevant content in the end node
result = CreateTxnsToDeleteContent(mEndParent, mEndOffset, nsIEditor::eRTL);
if (NS_SUCCEEDED(result))
{ // now we have all our child transactions, do them
result = EditAggregateTxn::Do();
}
}
}
}
@ -357,9 +357,33 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
}
// test if child is an ancestor of the other node. If it is, don't process this parent anymore
PRInt32 index;
index = ancestorList->IndexOf((nsISupports*)child);
nsISupports *childAsISupports;
child->QueryInterface(nsISupports::IID(), (void **)&childAsISupports);
index = ancestorList->IndexOf(childAsISupports);
if (-1!=index)
break;
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> childElement=child;
nsAutoString childElementTag="text node";
if (childElement)
childElement->GetTagName(childElementTag);
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *c, *p;
c = childElementTag.ToNewCString();
p = parentElementTag.ToNewCString();
if (c&&p)
{
printf("DeleteRangeTxn (1): building txn to delete child %s (pointer address %p) from parent %s\n",
c, childAsISupports, p);
delete [] c;
delete [] p;
}
// end debug output
#endif
DeleteElementTxn *txn;
result = TransactionFactory::GetNewTransaction(kDeleteElementTxnIID, (EditTxn **)&txn);
if (nsnull!=txn)
@ -387,6 +411,8 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
result = child->GetParentNode(getter_AddRefs(parent));
while ((NS_SUCCEEDED(result)) && parent)
{
if (parent==aCommonParent)
break; // notice that when we go up the aLastChild parent chain, we don't touch aCommonParent
while ((NS_SUCCEEDED(result)) && child)
{ // this loop starts with the first sibling of an ancestor of aFirstChild
nsCOMPtr<nsIDOMNode> temp = child;
@ -398,6 +424,27 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
index = ancestorList->IndexOf((nsISupports*)child);
if (-1!=index)
break;
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> childElement=child;
nsAutoString childElementTag="text node";
if (childElement)
childElement->GetTagName(childElementTag);
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *c, *p;
c = childElementTag.ToNewCString();
p = parentElementTag.ToNewCString();
if (c&&p)
{
printf("DeleteRangeTxn (2): building txn to delete child %s from parent %s\n", c, p);
delete [] c;
delete [] p;
}
// end debug output
#endif
DeleteElementTxn *txn;
result = TransactionFactory::GetNewTransaction(kDeleteElementTxnIID, (EditTxn **)&txn);
if (nsnull!=txn)
@ -409,8 +456,6 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
return NS_ERROR_NULL_POINTER;
}
}
if (parent==aCommonParent)
break;
child = parent;
nsCOMPtr<nsIDOMNode> temp=parent;
result = temp->GetParentNode(getter_AddRefs(parent));
@ -434,6 +479,21 @@ nsresult DeleteRangeTxn::BuildAncestorList(nsIDOMNode *aNode, nsISupportsArray *
nsISupports * parentAsISupports;
parent->QueryInterface(nsISupports::IID(), (void **)&parentAsISupports);
aList->AppendElement(parentAsISupports);
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *p;
p = parentElementTag.ToNewCString();
if (p)
{
printf("BuildAncestorList: adding parent %s (pointer address %p)\n", p, parentAsISupports);
delete [] p;
}
// end debug output
#endif
child = parent;
nsCOMPtr<nsIDOMNode> temp=parent;
result = temp->GetParentNode(getter_AddRefs(parent));

View File

@ -44,6 +44,7 @@ EditAggregateTxn::~EditAggregateTxn()
nsresult EditAggregateTxn::Do(void)
{
printf("aggregate txn %p Do\n", this);
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
if (nsnull!=mChildren)
{
@ -52,6 +53,7 @@ nsresult EditAggregateTxn::Do(void)
for (i=0; i<count; i++)
{
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
printf("aggregate txn %p: calling Do for txn %p, index %d\n", this, txn, i);
result = txn->Do();
if (NS_FAILED(result))
break;
@ -132,6 +134,7 @@ nsresult EditAggregateTxn::AppendChild(EditTxn *aTxn)
{
if ((nsnull!=mChildren) && (nsnull!=aTxn))
{
printf("aggregate txn %p: appending txn %p\n", this, aTxn);
mChildren->AppendElement(aTxn);
return NS_OK;
}

View File

@ -25,6 +25,10 @@
#include "TransactionFactory.h"
#include "nsISupportsArray.h"
#ifdef NS_DEBUG
#include "nsIDOMElement.h"
#endif
static NS_DEFINE_IID(kDeleteTextTxnIID, DELETE_TEXT_TXN_IID);
static NS_DEFINE_IID(kDeleteElementTxnIID, DELETE_ELEMENT_TXN_IID);
@ -115,10 +119,6 @@ nsresult DeleteRangeTxn::Do(void)
{
// delete the relevant content in the end node
result = CreateTxnsToDeleteContent(mEndParent, mEndOffset, nsIEditor::eRTL);
if (NS_SUCCEEDED(result))
{ // now we have all our child transactions, do them
result = EditAggregateTxn::Do();
}
}
}
}
@ -357,9 +357,33 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
}
// test if child is an ancestor of the other node. If it is, don't process this parent anymore
PRInt32 index;
index = ancestorList->IndexOf((nsISupports*)child);
nsISupports *childAsISupports;
child->QueryInterface(nsISupports::IID(), (void **)&childAsISupports);
index = ancestorList->IndexOf(childAsISupports);
if (-1!=index)
break;
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> childElement=child;
nsAutoString childElementTag="text node";
if (childElement)
childElement->GetTagName(childElementTag);
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *c, *p;
c = childElementTag.ToNewCString();
p = parentElementTag.ToNewCString();
if (c&&p)
{
printf("DeleteRangeTxn (1): building txn to delete child %s (pointer address %p) from parent %s\n",
c, childAsISupports, p);
delete [] c;
delete [] p;
}
// end debug output
#endif
DeleteElementTxn *txn;
result = TransactionFactory::GetNewTransaction(kDeleteElementTxnIID, (EditTxn **)&txn);
if (nsnull!=txn)
@ -387,6 +411,8 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
result = child->GetParentNode(getter_AddRefs(parent));
while ((NS_SUCCEEDED(result)) && parent)
{
if (parent==aCommonParent)
break; // notice that when we go up the aLastChild parent chain, we don't touch aCommonParent
while ((NS_SUCCEEDED(result)) && child)
{ // this loop starts with the first sibling of an ancestor of aFirstChild
nsCOMPtr<nsIDOMNode> temp = child;
@ -398,6 +424,27 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
index = ancestorList->IndexOf((nsISupports*)child);
if (-1!=index)
break;
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> childElement=child;
nsAutoString childElementTag="text node";
if (childElement)
childElement->GetTagName(childElementTag);
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *c, *p;
c = childElementTag.ToNewCString();
p = parentElementTag.ToNewCString();
if (c&&p)
{
printf("DeleteRangeTxn (2): building txn to delete child %s from parent %s\n", c, p);
delete [] c;
delete [] p;
}
// end debug output
#endif
DeleteElementTxn *txn;
result = TransactionFactory::GetNewTransaction(kDeleteElementTxnIID, (EditTxn **)&txn);
if (nsnull!=txn)
@ -409,8 +456,6 @@ nsresult DeleteRangeTxn::CreateTxnsToDeleteNodesBetween(nsIDOMNode *aCommonParen
return NS_ERROR_NULL_POINTER;
}
}
if (parent==aCommonParent)
break;
child = parent;
nsCOMPtr<nsIDOMNode> temp=parent;
result = temp->GetParentNode(getter_AddRefs(parent));
@ -434,6 +479,21 @@ nsresult DeleteRangeTxn::BuildAncestorList(nsIDOMNode *aNode, nsISupportsArray *
nsISupports * parentAsISupports;
parent->QueryInterface(nsISupports::IID(), (void **)&parentAsISupports);
aList->AppendElement(parentAsISupports);
#ifdef NS_DEBUG
// begin debug output
nsCOMPtr<nsIDOMElement> parentElement=parent;
nsAutoString parentElementTag="text node";
if (parentElement)
parentElement->GetTagName(parentElementTag);
char *p;
p = parentElementTag.ToNewCString();
if (p)
{
printf("BuildAncestorList: adding parent %s (pointer address %p)\n", p, parentAsISupports);
delete [] p;
}
// end debug output
#endif
child = parent;
nsCOMPtr<nsIDOMNode> temp=parent;
result = temp->GetParentNode(getter_AddRefs(parent));

View File

@ -44,6 +44,7 @@ EditAggregateTxn::~EditAggregateTxn()
nsresult EditAggregateTxn::Do(void)
{
printf("aggregate txn %p Do\n", this);
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
if (nsnull!=mChildren)
{
@ -52,6 +53,7 @@ nsresult EditAggregateTxn::Do(void)
for (i=0; i<count; i++)
{
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
printf("aggregate txn %p: calling Do for txn %p, index %d\n", this, txn, i);
result = txn->Do();
if (NS_FAILED(result))
break;
@ -132,6 +134,7 @@ nsresult EditAggregateTxn::AppendChild(EditTxn *aTxn)
{
if ((nsnull!=mChildren) && (nsnull!=aTxn))
{
printf("aggregate txn %p: appending txn %p\n", this, aTxn);
mChildren->AppendElement(aTxn);
return NS_OK;
}