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

Unified Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 1889053003: Fix InputConnection.deleteSurroundingText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Same to patch set 13, except adding a test for multiple nodes. Created 4 years, 6 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
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);

Powered by Google App Engine
This is Rietveld 408576698