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

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: handle multi-code text with BackspaceStateMachine::previousPositionOf Created 4 years, 8 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 ca051a0c662ea21fe8e1dd82ca3db819b1c1d4e9..1edbc2c0fbc8ea335473ab90a585deda277ae298 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -472,6 +472,43 @@ void InputMethodController::extendSelectionAndDelete(int before, int after)
TypingCommand::deleteSelection(*frame().document());
}
+void InputMethodController::deleteSurroundingText(size_t before, size_t after)
+{
+ if (!editor().canEdit())
+ return;
+ PlainTextRange selectionOffsets(getSelectionOffsets());
+ if (selectionOffsets.isNull())
+ return;
+
+ size_t selectionStart = selectionOffsets.start();
+ size_t selectionEnd = selectionOffsets.end();
+
+ if (before != 0) {
Changwan Ryu 2016/04/26 05:36:30 before > 0u
+ before = std::min(selectionStart, before);
+
+ // Select the text to be deleted before selectionStart,
+ // and adjust the start of selection in case of multi-code text.
+ Position basePosition(frame().selection().start().anchorNode(), selectionStart - before + 1);
+ Position adjustedPosition = previousPositionOf(basePosition, 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 != 0) {
Changwan Ryu 2016/04/26 05:36:30 after > 0u Comment still missing: why do you need
+ if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), static_cast<int>(selectionEnd + after))))
+ 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