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

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

Issue 315493004: reset VisibleSelection at the Undo command. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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
« Source/core/dom/Range.cpp ('K') | « Source/core/dom/Range.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/Editor.cpp
diff --git a/Source/core/editing/Editor.cpp b/Source/core/editing/Editor.cpp
index e2b1faa4d1c1eab468eb37be8e8b268ae69f51ec..c40754f96ce3206ad7e3dcb1e48c8a70f26843ec 100644
--- a/Source/core/editing/Editor.cpp
+++ b/Source/core/editing/Editor.cpp
@@ -710,6 +710,22 @@ void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd)
respondToChangedContents(newSelection);
}
+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 = Range::lengthOfContentsInNode(position.anchorNode());
+ return offset <= nodeLength;
+}
+
void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd)
{
EventQueueScope scope;
@@ -718,6 +734,8 @@ void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd
dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd->endingRootEditableElement());
VisibleSelection newSelection(cmd->startingSelection());
+ if (!isValidPosition(newSelection.base()) || !isValidPosition(newSelection.extent()) || !isValidPosition(newSelection.start()) || !isValidPosition(newSelection.end()))
+ newSelection = VisibleSelection(newSelection.base(), newSelection.extent(), newSelection.affinity(), newSelection.isDirectional());
yosin_UTC9 2014/06/04 01:17:30 Q: Why do we create |VisibleSelection| from invali
yoichio 2014/06/04 02:01:46 It's OK to create null VisibleSelection if there a
yosin_UTC9 2014/06/04 02:20:57 I think it is better to reset rather than set unex
Yuta Kitamura 2014/06/05 08:37:55 First of all, in my view this line is very hard to
yoichio 2014/06/06 04:49:21 VisibleSelection is a DISALLOW_ALLOCATION class. I
changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle);
m_lastEditCommand = nullptr;
« Source/core/dom/Range.cpp ('K') | « Source/core/dom/Range.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698