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

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: 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 e1d2f0fe18572803afa15c40bfe7af59a60e36ee..a5c08174873a4bac26db07ebf95a96528d0f4743 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -456,6 +456,40 @@ void InputMethodController::extendSelectionAndDelete(int before, int after)
TypingCommand::deleteSelection(*frame().document());
}
+void InputMethodController::deleteSurroundingText(int before, int after)
+{
+ if (!editor().canEdit())
+ return;
+ PlainTextRange selectionOffsets(getSelectionOffsets());
+ if (selectionOffsets.isNull())
+ return;
+
+ int selectionStart = static_cast<int>(selectionOffsets.start());
+ int selectionEnd = static_cast<int>(selectionOffsets.end());
+
+ if (before > 0) {
+ int deleteLength = std::min(selectionStart, before);
+ int leftStart = selectionStart - deleteLength;
+ int leftEnd = selectionStart;
+ if (!setSelectionOffsets(PlainTextRange(leftStart, leftEnd)))
+ return;
+ TypingCommand::deleteSelection(*frame().document());
+
+ selectionStart = leftStart;
+ selectionEnd = selectionEnd - deleteLength;
+ }
+
+ if (after > 0) {
+ int rightStart = selectionEnd;
+ int rightEnd = selectionEnd + after;
+ if (!setSelectionOffsets(PlainTextRange(rightStart, rightEnd)))
+ 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