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 e0bec0d04b7f7e5410c475b8e79a6102a73e6c87..994c178c9dd8a18c5337c65684363d2e8bd84292 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| @@ -456,6 +456,50 @@ 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()); |
| + |
| + // A common call of before=1 and after=0 will fail if the last character |
| + // is multi-code-word UTF-16, including both multi-16bit code-points and |
| + // Unicode combining character sequences of multiple single-16bit code- |
| + // points (officially called "compositions"). Try more until success. |
| + // It's similar to InputMethodController#extendSelectionAndDelete. |
| + // http://crbug.com/355995 |
| + 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) { |
|
Changwan Ryu
2016/04/21 01:07:06
shouldn't we apply the same logic to afterText? do
Changwan Ryu
2016/04/21 01:19:26
talked to yabinh@ offline. It's already covered by
yabinh
2016/04/21 01:24:16
We don't need that.
Some multi-code-texts take 2
aelias_OOO_until_Jul13
2016/04/21 04:01:29
OK, but can we call a generic method to snap to th
aelias_OOO_until_Jul13
2016/04/22 08:18:29
I suggest looking in http://icu-project.org/apiref
|
| + 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); |