Bug 1434969 - EditorDOMPointBase::RewindOffset() shouldn't treat it as error if offset is same as length of the container r?m_kato
EditorDOMPointBase::RewindOffset() treats it as error when offset is
same as length of container. However, this is wrong because offset can
be same as length of its container since it means after the last child
or last character. So, if an instance points end of a container node,
Rewind() always fails unexpectedly.
MozReview-Commit-ID: A9bvsxETDoo
--- a/editor/libeditor/EditorDOMPoint.h
+++ b/editor/libeditor/EditorDOMPoint.h
@@ -492,18 +492,20 @@ public:
return false;
}
// If only mOffset is available, just compute the offset.
if ((mOffset.isSome() && !mIsChildInitialized) ||
!mParent->IsContainerNode()) {
MOZ_ASSERT(mOffset.isSome());
MOZ_ASSERT(!mChild);
if (NS_WARN_IF(!mOffset.value()) ||
- NS_WARN_IF(mOffset.value() >= mParent->Length())) {
- // We're already referring the start of the container.
+ NS_WARN_IF(mOffset.value() > mParent->Length())) {
+ // We're already referring the start of the container or
+ // the offset is invalid since perhaps, the offset was set before
+ // the last DOM tree change.
return false;
}
mOffset = mozilla::Some(mOffset.value() - 1);
return true;
}
MOZ_ASSERT(mIsChildInitialized);
MOZ_ASSERT(!mOffset.isSome() || mOffset.isSome());