зеркало из https://github.com/mozilla/pjs.git
Bug 357509: Don't throw if new start is after end (or the other way around) but rather collapse. Patch by Alex Vincent <ajvincent@gmail.com>. r/sr=sicking
This commit is contained in:
Родитель
8bef119833
Коммит
f4a830b6b5
|
@ -713,19 +713,16 @@ nsresult nsRange::SetStart(nsIDOMNode* aParent, PRInt32 aOffset)
|
|||
if (aOffset < 0 || aOffset > len)
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
|
||||
// Collapse if not positioned yet, or if positioned in another doc.
|
||||
if (!mIsPositioned || !InSameDoc(parent, mEndParent)) {
|
||||
// Collapse if not positioned yet, if positioned in another doc or
|
||||
// if the new start is after end.
|
||||
if (!mIsPositioned || !InSameDoc(parent, mEndParent) ||
|
||||
nsContentUtils::ComparePoints(parent, aOffset,
|
||||
mEndParent, mEndOffset) == 1) {
|
||||
DoSetRange(parent, aOffset, parent, aOffset);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// the start must be before the end
|
||||
if (nsContentUtils::ComparePoints(parent, aOffset,
|
||||
mEndParent, mEndOffset) == 1) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
DoSetRange(parent, aOffset, mEndParent, mEndOffset);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -770,20 +767,17 @@ nsresult nsRange::SetEnd(nsIDOMNode* aParent, PRInt32 aOffset)
|
|||
if (aOffset < 0 || aOffset > len) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
// Collapse if not positioned yet, or if positioned in another doc.
|
||||
if (!mIsPositioned || !InSameDoc(parent, mStartParent)) {
|
||||
|
||||
// Collapse if not positioned yet, if positioned in another doc or
|
||||
// if the new end is before start.
|
||||
if (!mIsPositioned || !InSameDoc(parent, mStartParent) ||
|
||||
nsContentUtils::ComparePoints(mStartParent, mStartOffset,
|
||||
parent, aOffset) == 1) {
|
||||
DoSetRange(parent, aOffset, parent, aOffset);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// the start must be before the end
|
||||
if (nsContentUtils::ComparePoints(mStartParent, mStartOffset,
|
||||
parent, aOffset) == 1) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
DoSetRange(mStartParent, mStartOffset, parent, aOffset);
|
||||
|
||||
return NS_OK;
|
||||
|
|
Загрузка…
Ссылка в новой задаче