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 fe67f4e254b58e21a8d5a4409f27a832f5d7ab6d..555da03489b482c6016ee4999c32384fadbf4e3c 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> |
#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 { |
@@ -529,15 +530,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) { |
@@ -556,50 +552,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; |
@@ -776,8 +728,7 @@ void CompositeEditCommand::rebalanceWhitespaceOnTextSubstring(Text* textNode, |
shouldEmitNBSPbeforeEnd); |
if (string != rebalancedString) |
- replaceTextInNodePreservingMarkers(textNode, upstream, length, |
- rebalancedString); |
+ replaceTextInNode(textNode, upstream, length, rebalancedString); |
} |
void CompositeEditCommand::prepareWhitespaceAtPositionForSplit( |
@@ -818,9 +769,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() { |