Bug 1434969 - EditorDOMPointBase::RewindOffset() shouldn't treat it as error if offset is same as length of the container r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Sun, 04 Feb 2018 01:00:44 +0900
changeset 750972 c679c189482920330e6cea98470f763b599f4072
parent 750946 92b6195a9367dec27fbf3efbe7824cf163aa017a
push id97807
push usermasayuki@d-toybox.com
push dateSun, 04 Feb 2018 02:01:59 +0000
reviewersm_kato
bugs1434969
milestone60.0a1
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
editor/libeditor/EditorDOMPoint.h
--- 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());