Bug 359121: Fix regression in editor from previous range checkins. nSDetach wasn't the same as Detach after all. r/sr=jst

This commit is contained in:
cvshook%sicking.cc 2006-11-02 02:14:57 +00:00
parent 1d20f5a6b6
commit 8da53b5fb1
4 changed files with 41 additions and 12 deletions

View File

@ -40,7 +40,6 @@
#include "nsISupports.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsINode.h"
// IID for the nsIRange interface
@ -90,19 +89,16 @@ public:
return mIsDetached;
}
nsINode* GetCommonAncestor()
{
return mIsPositioned ?
nsContentUtils::GetCommonAncestor(mStartParent, mEndParent) :
nsnull;
}
PRBool Collapsed()
{
return mIsPositioned && mStartParent == mEndParent &&
mStartOffset == mEndOffset;
}
virtual nsINode* GetCommonAncestor() = 0;
virtual void Reset() = 0;
protected:
nsCOMPtr<nsINode> mStartParent;
nsCOMPtr<nsINode> mEndParent;

View File

@ -426,6 +426,24 @@ ContentOwnsRange(nsIRange* aRange, nsINode* aNode)
return NS_OK;
}
/******************************************************
* nsIRange implementation
******************************************************/
nsINode*
nsRange::GetCommonAncestor()
{
return mIsPositioned ?
nsContentUtils::GetCommonAncestor(mStartParent, mEndParent) :
nsnull;
}
void
nsRange::Reset()
{
DoSetRange(nsnull, 0, nsnull, 0);
}
/******************************************************
* public functionality
******************************************************/

View File

@ -91,6 +91,10 @@ public:
// nsIDOMNSRange interface
NS_DECL_NSIDOMNSRANGE
// nsIRange interface
virtual nsINode* GetCommonAncestor();
virtual void Reset();
// nsRange interface extensions
static NS_METHOD OwnerGone(nsIContent* aParentNode);

View File

@ -71,6 +71,7 @@
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIRange.h"
#include "nsEditorUtils.h"
#include "nsWSRunObject.h"
@ -340,13 +341,15 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
// clear out mDocChangeRange and mUtilRange
if(mDocChangeRange)
{
// Ignore failure code returned if the range is already detached
mDocChangeRange->Detach(); // clear out our accounting of what changed
// clear out our accounting of what changed
nsCOMPtr<nsIRange> range = do_QueryInterface(mDocChangeRange);
range->Reset();
}
if(mUtilRange)
{
// Ignore failure code returned if the range is already detached
mUtilRange->Detach(); // ditto for mUtilRange.
// ditto for mUtilRange.
nsCOMPtr<nsIRange> range = do_QueryInterface(mUtilRange);
range->Reset();
}
// remember current inline styles for deletion and normal insertion operations
@ -8077,6 +8080,14 @@ nsHTMLEditRules::UpdateDocChangeRange(nsIDOMRange *aRange)
// compare starts of ranges
res = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, aRange, &result);
if (res == NS_ERROR_NOT_INITIALIZED) {
// This will happen is mDocChangeRange is non-null, but the range is
// uninitialized. In this case we'll set the start to aRange start.
// The same test won't be needed further down since after we've set
// the start the range will be collapsed to that point.
result = 1;
res = NS_OK;
}
if (NS_FAILED(res)) return res;
if (result > 0) // positive result means mDocChangeRange start is after aRange start
{