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

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

Issue 2127503002: Use RelocatablePosition in CompositeEditCommand::moveParagraphs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | 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/CompositeEditCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
index c0d9030727ba5011dc26aa0840f4266a819d1eea..67d34185a4e3ec38b8c529daa7ff10fe30a8f1ef 100644
--- a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
@@ -1282,8 +1282,12 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
}
}
- VisiblePosition beforeParagraph = previousPositionOf(startOfParagraphToMove, CannotCrossEditingBoundary);
- VisiblePosition afterParagraph = nextPositionOf(endOfParagraphToMove, CannotCrossEditingBoundary);
+ // Create a temporary Range to keep track of the "hole" left by moving away the paragraph.
+ Position beforeParagraphPos = previousPositionOf(startOfParagraphToMove, CannotCrossEditingBoundary).deepEquivalent();
+ Range* beforeParagraphTempRange = beforeParagraphPos.isNull() ? nullptr : Range::create(document(), beforeParagraphPos, beforeParagraphPos);
yosin_UTC9 2016/07/06 01:52:25 The rule is when we use temporary range, it should
+
+ Position afterParagraphPos = nextPositionOf(endOfParagraphToMove, CannotCrossEditingBoundary).deepEquivalent();
+ Range* afterParagraphTempRange = afterParagraphPos.isNull() ? nullptr : Range::create(document(), afterParagraphPos, afterParagraphPos);
// We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move.
// When we paste a fragment, spaces after the end and before the start are treated as though they were rendered.
@@ -1327,8 +1331,8 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
// Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That would
// cause 'baz' to collapse onto the line with 'foobar' unless we insert a br.
// Must recononicalize these two VisiblePositions after the pruning above.
- beforeParagraph = createVisiblePosition(beforeParagraph.deepEquivalent());
- afterParagraph = createVisiblePosition(afterParagraph.deepEquivalent());
+ VisiblePosition beforeParagraph = beforeParagraphTempRange ? createVisiblePosition(beforeParagraphTempRange->startPosition()) : VisiblePosition();
+ VisiblePosition afterParagraph = afterParagraphTempRange ? createVisiblePosition(afterParagraphTempRange->startPosition()) : VisiblePosition();
if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || beforeParagraph.deepEquivalent() == afterParagraph.deepEquivalent())) {
// FIXME: Trim text between beforeParagraph and afterParagraph if they aren't equal.
insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEquivalent(), editingState);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698