Index: third_party/WebKit/Source/core/editing/InputMethodController.cpp |
diff --git a/third_party/WebKit/Source/core/editing/InputMethodController.cpp b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
index 0bd3b86d91b2380d6a7380e89bc63feae01cc7e0..d52dfd8e4d401e0e0ab59b7d555b3ca7e8171d11 100644 |
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
@@ -548,6 +548,63 @@ void InputMethodController::extendSelectionAndDelete(int before, int after) |
TypingCommand::deleteSelection(*frame().document()); |
} |
+void InputMethodController::deleteSurroundingText(size_t before, size_t after) |
Changwan Ryu
2016/06/20 10:03:24
Could you add a TODO to reduce the number of selec
yabinh
2016/06/20 10:22:23
Acknowledged.
|
+{ |
+ if (!editor().canEdit()) |
+ return; |
+ PlainTextRange selectionOffsets(getSelectionOffsets()); |
+ if (selectionOffsets.isNull()) |
+ return; |
+ |
+ size_t selectionStart = selectionOffsets.start(); |
+ size_t selectionEnd = selectionOffsets.end(); |
+ |
+ if (before > 0u && selectionStart > 0u) { |
+ // In case of exceeding the left boundary. |
+ before = std::min(selectionStart, before); |
+ |
+ // Select the text to be deleted before selectionStart. |
+ // For multi-code text, we can't select it successfully if we only |
+ // select the right half of it. So we need to adjust the start of |
+ // selection. |
+ Position position(frame().selection().start().anchorNode(), selectionStart - before + 1); |
+ Position adjustedPosition = previousPositionOf(position, PositionMoveType::GraphemeCluster); |
+ int adjustedStart = adjustedPosition.computeOffsetInContainerNode(); |
+ |
+ if (!setSelectionOffsets(PlainTextRange(adjustedStart, static_cast<int>(selectionStart)))) |
+ return; |
+ TypingCommand::deleteSelection(*frame().document()); |
+ |
+ selectionEnd = selectionEnd - (selectionStart - adjustedStart); |
+ selectionStart = adjustedStart; |
+ } |
+ |
+ if (after > 0u) { |
+ // Adjust the deleted range in case of exceeding the right boundary. |
+ PlainTextRange range(static_cast<int>(selectionEnd), static_cast<int>(selectionEnd + after)); |
+ if (range.isNull()) |
+ return; |
+ Element* rootEditableElement = frame().selection().rootEditableElement(); |
+ if (!rootEditableElement) |
+ return; |
+ const EphemeralRange adjustedRange = range.createRange(*rootEditableElement); |
+ if (adjustedRange.isNull()) |
+ return; |
+ |
+ // Select the text to be deleted after selectionEnd. |
+ // We also need to adjust the end of selection for multi-code text. |
+ Position position(frame().selection().start().anchorNode(), adjustedRange.endPosition().computeOffsetInContainerNode() - 1); |
+ Position adjustedPosition = nextPositionOf(position, PositionMoveType::GraphemeCluster); |
+ int adjustedEnd = adjustedPosition.computeOffsetInContainerNode(); |
+ |
+ if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), adjustedEnd))) |
+ return; |
+ TypingCommand::deleteSelection(*frame().document()); |
+ } |
+ |
+ setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); |
+} |
+ |
DEFINE_TRACE(InputMethodController) |
{ |
visitor->trace(m_frame); |