Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(907)

Unified Diff: Source/core/editing/VisibleSelection.cpp

Issue 315493004: reset VisibleSelection at the Undo command. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add the VisibleSelection::validateIfNeeded method Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/VisibleSelection.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/VisibleSelection.cpp
diff --git a/Source/core/editing/VisibleSelection.cpp b/Source/core/editing/VisibleSelection.cpp
index 02861aa623b198a65822b208a86936e18f8011d5..753da69b7a295ef9f428906cba7d331ca9ab5aee 100644
--- a/Source/core/editing/VisibleSelection.cpp
+++ b/Source/core/editing/VisibleSelection.cpp
@@ -771,6 +771,28 @@ void VisibleSelection::trace(Visitor* visitor)
visitor->trace(m_changeObserver);
}
+static bool isValidPosition(const Position& position)
+{
+ if (!position.inDocument())
+ return false;
+
+ if (position.anchorType() != Position::PositionIsOffsetInAnchor)
+ return true;
+
+ if (position.offsetInContainerNode() < 0)
+ return false;
+
+ const unsigned offset = static_cast<unsigned>(position.offsetInContainerNode());
+ const unsigned nodeLength = position.anchorNode()->lengthOfContents();
+ return offset <= nodeLength;
+}
+
+void VisibleSelection::validatePositionsIfNeeded()
+{
+ if (!isValidPosition(m_base) || !isValidPosition(m_extent) || !isValidPosition(m_start) || !isValidPosition(m_end))
+ validate();
+}
+
#ifndef NDEBUG
void VisibleSelection::debugPosition() const
« no previous file with comments | « Source/core/editing/VisibleSelection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698