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

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

Issue 2405223002: Ensure valid input for CompositeEditCommand::moveParagraph[s] (Closed)
Patch Set: Remove the dirty hacks Created 4 years, 2 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 | « third_party/WebKit/Source/core/editing/commands/InsertListCommand.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp b/third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp
index 987600fc3f5103261d7ce00bfab464b8fdecdc58..86192a88b7806e46b8f4531d66e1db198bde97b8 100644
--- a/third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp
@@ -1525,9 +1525,15 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
if (shouldMergeStart(selectionStartWasStartOfParagraph,
fragment.hasInterchangeNewlineAtStart(),
startIsInsideMailBlockquote)) {
- // TODO(xiaochengh): Stop storing VisiblePositions through mutations.
VisiblePosition startOfParagraphToMove = positionAtStartOfInsertedContent();
VisiblePosition destination = previousPositionOf(startOfParagraphToMove);
+
+ // Helpers for making the VisiblePositions valid again after DOM changes.
+ PositionWithAffinity startOfParagraphToMovePosition =
+ startOfParagraphToMove.toPositionWithAffinity();
+ PositionWithAffinity destinationPosition =
+ destination.toPositionWithAffinity();
+
// We need to handle the case where we need to merge the end
// but our destination node is inside an inline that is the last in the
// block.
@@ -1553,26 +1559,30 @@ void ReplaceSelectionCommand::doApply(EditingState* editingState) {
// what comes after and prevent that from happening.
VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent();
if (startOfParagraph(endOfInsertedContent).deepEquivalent() ==
- startOfParagraphToMove.deepEquivalent()) {
+ startOfParagraphToMovePosition.position()) {
insertNodeAt(HTMLBRElement::create(document()),
endOfInsertedContent.deepEquivalent(), editingState);
if (editingState->isAborted())
return;
// Mutation events (bug 22634) triggered by inserting the <br> might have
// removed the content we're about to move
- if (!startOfParagraphToMove.deepEquivalent().isConnected())
+ if (!startOfParagraphToMovePosition.position().isConnected())
return;
}
document().updateStyleAndLayoutIgnorePendingStylesheets();
+ // Making the two VisiblePositions valid again.
+ startOfParagraphToMove =
+ createVisiblePosition(startOfParagraphToMovePosition);
+ destination = createVisiblePosition(destinationPosition);
+
// FIXME: Maintain positions for the start and end of inserted content
// instead of keeping nodes. The nodes are only ever used to create
// positions where inserted content starts/ends.
moveParagraph(startOfParagraphToMove,
- endOfParagraph(createVisiblePosition(
- startOfParagraphToMove.toPositionWithAffinity())),
- destination, editingState);
+ endOfParagraph(startOfParagraphToMove), destination,
+ editingState);
if (editingState->isAborted())
return;
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/InsertListCommand.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698