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

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: Changed the type of some parameters, and added some comments. 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 e0bec0d04b7f7e5410c475b8e79a6102a73e6c87..8d9574a38b44c45808c041a80c4e99303cab7c3e 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -456,6 +456,49 @@ 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());
aelias_OOO_until_Jul13 2016/04/21 04:01:29 Why static_cast, is there a warning/error if you j
yabinh 2016/04/22 01:26:48 Since we use "std::min(selectionStart, before)", a
+ int selectionEnd = static_cast<int>(selectionOffsets.end());
+
+ // Some multi-code-texts take 2 positions, like "\xF0\x9F\x8F\x86"(U+1F3C6 ==
+ // "trophy"). We can select the whole multi-code-text successfully if we only
+ // select the left half of it, but sometimes we can't select it successfully if we
+ // only select the right half of it, so we need to select more. That's why we need
+ // to apply a while-loop to the beforeText and don't need to apply it to the afterText.
+ if (before > 0) {
+ int deleteLength, leftStart, leftEnd;
+ do {
+ deleteLength = std::min(selectionStart, before);
+ leftStart = selectionStart - deleteLength;
+ leftEnd = selectionStart;
+ if (!setSelectionOffsets(PlainTextRange(leftStart, leftEnd)))
+ return;
+ ++before;
+ } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start()));
+ 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