Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| index a5748f859505025388e33c7a977601d7afb6f13f..e16d918d051fd6b06c8e7acdd6c64746ef9ccc81 100644 |
| --- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| +++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| @@ -32,6 +32,7 @@ |
| #include "core/dom/Range.h" |
| #include "core/dom/Text.h" |
| #include "core/dom/shadow/ShadowRoot.h" |
| +#include "core/editing/BackspaceStateMachine.h" |
| #include "core/editing/EditingStrategy.h" |
| #include "core/editing/Editor.h" |
| #include "core/editing/PlainTextRange.h" |
| @@ -556,9 +557,21 @@ int uncheckedPreviousOffset(const Node* node, int current) |
| return result == TextBreakDone ? current - 1 : result; |
| } |
| -static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current) |
| +static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int current) |
| { |
|
yosin_UTC9
2016/03/28 05:05:47
Could you add DCHECK_GE(current, 0)?
Seigo Nonaka
2016/03/28 07:28:12
Done.
|
| - return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDeletion(current) : current - 1; |
| + if (current <= 1) |
| + return 0; |
| + if (!node->isTextNode()) |
| + return current - 1; |
| + |
| + const String& text = toText(node)->data(); |
| + CHECK(static_cast<unsigned>(current - 1) < text.length()); |
| + BackspaceStateMachine machine; |
| + for (int i = current - 1; i >= 0; --i) { |
| + if (machine.updateState(text[i])) |
| + break; |
| + } |
| + return current - machine.finalizeAndGetCodeUnitCountToBeDeleted(); |
|
yosin_UTC9
2016/03/28 05:05:47
Could you check |current| >= 0?
e.g.
int amount =
Seigo Nonaka
2016/03/28 07:28:11
Done.
|
| } |
| int uncheckedNextOffset(const Node* node, int current) |