Chromium Code Reviews| 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 d7391d43ef068e430a8f55a560419ab38eacdb42..14431c421a4003d2e37814638cc5ddc01ba3a0cd 100644 |
| --- a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp |
| +++ b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp |
| @@ -25,6 +25,7 @@ |
| #include "core/editing/commands/CompositeEditCommand.h" |
| +#include <algorithm> |
|
Xiaocheng
2017/02/22 01:49:23
No need to change include order.
rlanday
2017/02/22 02:01:10
git cl format did this, the linter will probably c
|
| #include "bindings/core/v8/ExceptionState.h" |
| #include "core/HTMLNames.h" |
| #include "core/dom/Document.h" |
| @@ -52,6 +53,7 @@ |
| #include "core/editing/commands/RemoveNodePreservingChildrenCommand.h" |
| #include "core/editing/commands/ReplaceNodeWithSpanCommand.h" |
| #include "core/editing/commands/ReplaceSelectionCommand.h" |
| +#include "core/editing/commands/SetCharacterDataCommand.h" |
| #include "core/editing/commands/SetNodeAttributeCommand.h" |
| #include "core/editing/commands/SplitElementCommand.h" |
| #include "core/editing/commands/SplitTextNodeCommand.h" |
| @@ -73,7 +75,6 @@ |
| #include "core/layout/LayoutListItem.h" |
| #include "core/layout/LayoutText.h" |
| #include "core/layout/line/InlineTextBox.h" |
| -#include <algorithm> |
| namespace blink { |
| @@ -531,15 +532,10 @@ void CompositeEditCommand::replaceTextInNode(Text* node, |
| unsigned offset, |
| unsigned count, |
| const String& replacementText) { |
| - // DeleteFromTextNodeCommand and InsertIntoTextNodeCommand are never |
| - // aborted. |
| + // SetCharacterDataCommand is never aborted. |
| applyCommandToComposite( |
| - DeleteFromTextNodeCommand::create(node, offset, count), |
| + SetCharacterDataCommand::create(node, offset, count, replacementText), |
| ASSERT_NO_EDITING_ABORT); |
| - if (!replacementText.isEmpty()) |
| - applyCommandToComposite( |
| - InsertIntoTextNodeCommand::create(node, offset, replacementText), |
| - ASSERT_NO_EDITING_ABORT); |
| } |
| Position CompositeEditCommand::replaceSelectedTextInNode(const String& text) { |
| @@ -558,50 +554,6 @@ Position CompositeEditCommand::replaceSelectedTextInNode(const String& text) { |
| return Position(textNode, start.offsetInContainerNode() + text.length()); |
| } |
| -static void copyMarkerTypesAndDescriptions( |
| - const DocumentMarkerVector& markerPointers, |
| - Vector<DocumentMarker::MarkerType>& types, |
| - Vector<String>& descriptions) { |
| - size_t arraySize = markerPointers.size(); |
| - types.reserveCapacity(arraySize); |
| - descriptions.reserveCapacity(arraySize); |
| - for (const auto& markerPointer : markerPointers) { |
| - types.push_back(markerPointer->type()); |
| - descriptions.push_back(markerPointer->description()); |
| - } |
| -} |
| - |
| -void CompositeEditCommand::replaceTextInNodePreservingMarkers( |
| - Text* node, |
| - unsigned offset, |
| - unsigned count, |
| - const String& replacementText) { |
| - DocumentMarkerController& markerController = document().markers(); |
| - Vector<DocumentMarker::MarkerType> types; |
| - Vector<String> descriptions; |
| - copyMarkerTypesAndDescriptions( |
| - markerController.markersInRange( |
| - EphemeralRange(Position(node, offset), |
| - Position(node, offset + count)), |
| - DocumentMarker::AllMarkers()), |
| - types, descriptions); |
| - |
| - replaceTextInNode(node, offset, count, replacementText); |
| - |
| - // Re-adding markers requires a clean tree. |
| - document().updateStyleAndLayout(); |
| - |
| - DocumentLifecycle::DisallowTransitionScope disallowTransition( |
| - document().lifecycle()); |
| - Position startPosition(node, offset); |
| - Position endPosition(node, offset + replacementText.length()); |
| - DCHECK_EQ(types.size(), descriptions.size()); |
| - |
| - for (size_t i = 0; i < types.size(); ++i) |
| - markerController.addMarker(startPosition, endPosition, types[i], |
| - descriptions[i]); |
| -} |
| - |
| Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos) { |
| if (!isTabHTMLSpanElementTextNode(pos.anchorNode())) |
| return pos; |
| @@ -774,8 +726,7 @@ void CompositeEditCommand::rebalanceWhitespaceOnTextSubstring(Text* textNode, |
| shouldEmitNBSPbeforeEnd); |
| if (string != rebalancedString) |
| - replaceTextInNodePreservingMarkers(textNode, upstream, length, |
| - rebalancedString); |
| + replaceTextInNode(textNode, upstream, length, rebalancedString); |
| } |
| void CompositeEditCommand::prepareWhitespaceAtPositionForSplit( |
| @@ -816,9 +767,8 @@ void CompositeEditCommand:: |
| Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| if (!pos.computeContainerNode() || !pos.computeContainerNode()->isTextNode()) |
| return; |
| - replaceTextInNodePreservingMarkers(toText(pos.computeContainerNode()), |
| - pos.offsetInContainerNode(), 1, |
| - nonBreakingSpaceString()); |
| + replaceTextInNode(toText(pos.computeContainerNode()), |
| + pos.offsetInContainerNode(), 1, nonBreakingSpaceString()); |
| } |
| void CompositeEditCommand::rebalanceWhitespace() { |