| 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 3fe2471ade436bcc32bb056d46e8063e953f0e89..66b0fc31defe7dd0c0b8bb6fb73b455160e08039 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"
|
| @@ -543,6 +544,35 @@ PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat
|
| return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeStrategy>(position, highestRoot);
|
| }
|
|
|
| +template<typename StateMachine>
|
| +int findNextBoundaryOffset(const String& str, int current)
|
| +{
|
| + constexpr typename StateMachine::State NeedMoreCodeUnit = StateMachine::State::NeedMoreCodeUnit;
|
| + constexpr typename StateMachine::State Finished = StateMachine::State::Finished;
|
| + constexpr typename StateMachine::State Unknown = StateMachine::State::Unknown;
|
| +
|
| + StateMachine machine;
|
| + typename StateMachine::State state = Unknown;
|
| +
|
| + for (int i = current - 1; i >= 0; --i) {
|
| + state = machine.feedPrecedingCodeUnit(str[i]);
|
| + DCHECK(state != Unknown);
|
| + if (state != NeedMoreCodeUnit)
|
| + break;
|
| + }
|
| + if (state == Finished)
|
| + return current + machine.finalizeAndGetBoundaryOffset();
|
| + const int length = str.length();
|
| + for (int i = current; i < length; ++i) {
|
| + state = machine.feedFollowingCodeUnit(str[i]);
|
| + DCHECK(state != Unknown);
|
| + if (state != NeedMoreCodeUnit)
|
| + break;
|
| + }
|
| + DCHECK(state != StateMachine::State::NeedFollowingCodeUnit);
|
| + return current + machine.finalizeAndGetBoundaryOffset();
|
| +}
|
| +
|
| int uncheckedPreviousOffset(const Node* node, int current)
|
| {
|
| if (!node->isTextNode())
|
| @@ -567,11 +597,7 @@ static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr
|
|
|
| const String& text = toText(node)->data();
|
| DCHECK(static_cast<unsigned>(current - 1) < text.length());
|
| - if (U16_IS_TRAIL(text[--current]))
|
| - --current;
|
| - if (current < 0)
|
| - current = 0;
|
| - return current;
|
| + return findNextBoundaryOffset<BackspaceStateMachine>(text, current);
|
| }
|
|
|
| int uncheckedNextOffset(const Node* node, int current)
|
|
|