Chromium Code Reviews| 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..cdb1c6350620d3f52066950612f1da360b2d3f7e 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| @@ -472,6 +472,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()); |
| + 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 we can't select it if we only select |
| + // the right half of it. For the latter case, we need to select more. |
| + if (before > 0) { |
| + int deleteLength, leftStart, leftEnd; |
| + int adjustedBefore = before; |
| + do { |
| + deleteLength = std::min(selectionStart, adjustedBefore); |
| + leftStart = selectionStart - deleteLength; |
| + leftEnd = selectionStart; |
| + if (!setSelectionOffsets(PlainTextRange(leftStart, leftEnd))) |
| + return; |
| + ++adjustedBefore; |
| + } while (frame().selection().start().computeOffsetInContainerNode() + before > frame().selection().end().computeOffsetInContainerNode() && before <= static_cast<int>(selectionOffsets.start())); |
|
Changwan Ryu
2016/04/22 02:16:09
1) while condition is too long, and the latter con
yabinh
2016/04/22 02:51:53
You are right. It'll be more simple.
|
| + 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); |