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

Unified Diff: third_party/WebKit/Source/core/editing/commands/DeleteSelectionCommand.cpp

Issue 2374743002: [InputEvent] Support |deleteByDrag|, |insertFromDrop| and fire in sequential order (Closed)
Patch Set: Yosin's review Created 4 years, 3 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
Index: third_party/WebKit/Source/core/editing/commands/DeleteSelectionCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/DeleteSelectionCommand.cpp b/third_party/WebKit/Source/core/editing/commands/DeleteSelectionCommand.cpp
index ff59f692da5e64999f8a10ff005688fa94c4e27b..8954d3ad619a9ef779fe4cb51a60c4cc83b31a72 100644
--- a/third_party/WebKit/Source/core/editing/commands/DeleteSelectionCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/DeleteSelectionCommand.cpp
@@ -33,6 +33,7 @@
#include "core/editing/EditingBoundary.h"
#include "core/editing/EditingUtilities.h"
#include "core/editing/Editor.h"
+#include "core/editing/RelocatablePosition.h"
#include "core/editing/VisibleUnits.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLBRElement.h"
@@ -63,7 +64,7 @@ static bool isTableRowEmpty(Node* row)
return true;
}
-DeleteSelectionCommand::DeleteSelectionCommand(Document& document, bool smartDelete, bool mergeBlocksAfterDelete, bool expandForSpecialElements, bool sanitizeMarkup, InputEvent::InputType inputType)
+DeleteSelectionCommand::DeleteSelectionCommand(Document& document, bool smartDelete, bool mergeBlocksAfterDelete, bool expandForSpecialElements, bool sanitizeMarkup, InputEvent::InputType inputType, const Position& referenceMovePosition)
: CompositeEditCommand(document)
, m_hasSelectionToDelete(false)
, m_smartDelete(smartDelete)
@@ -74,6 +75,7 @@ DeleteSelectionCommand::DeleteSelectionCommand(Document& document, bool smartDel
, m_startsAtEmptyLine(false)
, m_sanitizeMarkup(sanitizeMarkup)
, m_inputType(inputType)
+ , m_referenceMovePosition(referenceMovePosition)
, m_startBlock(nullptr)
, m_endBlock(nullptr)
, m_typingStyle(nullptr)
@@ -808,6 +810,7 @@ void DeleteSelectionCommand::clearTransientState()
m_endingPosition = Position();
m_leadingWhitespace = Position();
m_trailingWhitespace = Position();
+ m_referenceMovePosition = Position();
}
// This method removes div elements with no attributes that have only one child or no children at all.
@@ -841,6 +844,8 @@ void DeleteSelectionCommand::doApply(EditingState* editingState)
if (!m_selectionToDelete.isNonOrphanedRange() || !m_selectionToDelete.isContentEditable())
return;
+ RelocatablePosition relocatableReferencePosition(m_referenceMovePosition);
yosin_UTC9 2016/10/03 09:19:03 Good usage!
chongz 2016/10/04 02:18:39 Thanks!
+
// save this to later make the selection with
TextAffinity affinity = m_selectionToDelete.affinity();
@@ -931,6 +936,23 @@ void DeleteSelectionCommand::doApply(EditingState* editingState)
calculateTypingStyleAfterDelete();
setEndingSelection(VisibleSelection(m_endingPosition, affinity, endingSelection().isDirectional()));
+
+ // This deletion command is part or a move operation.
+ if (relocatableReferencePosition.position().isNotNull()) {
yosin_UTC9 2016/10/03 09:19:03 Could you use early-return style? if (relocatable
chongz 2016/10/04 02:18:39 Done.
+ m_referenceMovePosition = relocatableReferencePosition.position();
+ // If the node for the destination has been removed as a result of the deletion,
+ // set the destination to the ending point after the deletion.
+ // Fixes: <rdar://problem/3910425> REGRESSION (Mail): Crash in ReplaceSelectionCommand;
+ // selection is empty, leading to null deref
+ if (!m_referenceMovePosition.isConnected())
+ m_referenceMovePosition = endingSelection().start();
+
+ // Move selection shouldn't left empty <li> block.
+ cleanupAfterDeletion(editingState, createVisiblePositionDeprecated(m_referenceMovePosition));
+ if (editingState->isAborted())
+ return;
+ }
+
clearTransientState();
}
@@ -960,6 +982,7 @@ DEFINE_TRACE(DeleteSelectionCommand)
visitor->trace(m_endingPosition);
visitor->trace(m_leadingWhitespace);
visitor->trace(m_trailingWhitespace);
+ visitor->trace(m_referenceMovePosition);
visitor->trace(m_startBlock);
visitor->trace(m_endBlock);
visitor->trace(m_typingStyle);

Powered by Google App Engine
This is Rietveld 408576698