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

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: add some comment 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..c8630caf54f642c69bcb1ae38354f93452b2ab69 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -472,6 +472,46 @@ void InputMethodController::extendSelectionAndDelete(int before, int after)
TypingCommand::deleteSelection(*frame().document());
}
+void InputMethodController::deleteSurroundingText(size_t before, size_t after)
yosin_UTC9 2016/04/26 08:18:54 Can you guarantee |before| is at end of grapheme a
+{
+ if (!editor().canEdit())
+ return;
+ PlainTextRange selectionOffsets(getSelectionOffsets());
+ if (selectionOffsets.isNull())
+ return;
+
+ size_t selectionStart = selectionOffsets.start();
+ size_t selectionEnd = selectionOffsets.end();
+
+ if (before > 0u) {
+ before = std::min(selectionStart, before);
aelias_OOO_until_Jul13 2016/04/26 07:29:32 What is this line for? I don't understand it.
yabinh 2016/04/26 08:05:15 It's for boundary checking. In case that "before"
yosin_UTC9 2016/04/27 08:21:16 When |selectionStart|=0 and |before|=2, |before| g
+
+ // Select the text to be deleted before selectionStart.
+ // For multi-code text, we can select it successfully if we only select
+ // the left half of it, but we can't select it if we only select the
+ // right half of it. For the latter case, we need to adjust the start
+ // of selection.
+ Position basePosition(frame().selection().start().anchorNode(), selectionStart - before + 1);
aelias_OOO_until_Jul13 2016/04/26 07:29:32 Why + 1?
yabinh 2016/04/26 08:05:16 Because previousPositionOf(basePosition, PositionM
+ Position adjustedPosition = previousPositionOf(basePosition, PositionMoveType::GraphemeCluster);
+ int adjustedStart = adjustedPosition.computeOffsetInContainerNode();
+
+ if (!setSelectionOffsets(PlainTextRange(adjustedStart, static_cast<int>(selectionStart))))
+ return;
+ TypingCommand::deleteSelection(*frame().document());
aelias_OOO_until_Jul13 2016/04/26 07:29:32 Hmm, I still don't like the two deletion calls too
yabinh 2016/04/26 08:05:16 I've verified that this patch doesn't trigger any
yosin_UTC9 2016/04/26 08:18:54 Better way is using Range::delteContent(). It disp
yosin_UTC9 2016/04/26 09:12:29 How did you check these events? Did you check with
+
+ selectionEnd = selectionEnd - (selectionStart - adjustedStart);
+ selectionStart = adjustedStart;
+ }
+
+ if (after > 0u) {
+ if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), static_cast<int>(selectionEnd + after))))
yosin_UTC9 2016/04/26 09:12:29 We may want to |selectionEnd + after| is at end of
+ 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