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 1a7dc9d74831dcea9f16d3e7d42fa0ccdb41cffe..7b5fcebb0db61ab4c6b644714373bff78ae9248b 100644 |
| --- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| +++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| @@ -42,6 +42,8 @@ |
| #include "core/editing/iterators/TextIterator.h" |
| #include "core/editing/serializers/HTMLInterchange.h" |
| #include "core/editing/state_machines/BackspaceStateMachine.h" |
| +#include "core/editing/state_machines/BackwardGraphemeBoundaryStateMachine.h" |
| +#include "core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/frame/UseCounter.h" |
| #include "core/html/HTMLBRElement.h" |
| @@ -555,7 +557,7 @@ int findNextBoundaryOffset(const String& str, int current) |
| if (state != TextSegmentationMachineState::NeedMoreCodeUnit) |
| break; |
| } |
| - if (state == TextSegmentationMachineState::NeedMoreCodeUnit) |
| + if (current == 0 || state == TextSegmentationMachineState::NeedMoreCodeUnit) |
| state = machine.tellEndOfPrecedingText(); |
| if (state == TextSegmentationMachineState::Finished) |
| return current + machine.finalizeAndGetBoundaryOffset(); |
| @@ -571,16 +573,12 @@ int findNextBoundaryOffset(const String& str, int current) |
| int uncheckedPreviousOffset(const Node* node, int current) |
|
yosin_UTC9
2016/04/06 07:33:43
It seems make |uncheckedPreviousOffset()| and |unc
|
| { |
| - if (!node->isTextNode()) |
| + DCHECK_GE(current, 0); |
| + if (current <= 1 || !node->isTextNode()) |
| return current - 1; |
| const String& text = toText(node)->data(); |
| - if (text.is8Bit()) |
| - return current - 1; // TODO(nona): Good to support CR x LF. |
| - TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), text.length()); |
| - if (!iterator) |
| - return current - 1; |
| - const int result = iterator->preceding(current); |
| - return result == TextBreakDone ? current - 1 : result; |
| + return findNextBoundaryOffset<BackwardGraphemeBoundaryStateMachine>( |
| + text, current); |
| } |
| static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int current) |
| @@ -601,13 +599,12 @@ int uncheckedNextOffset(const Node* node, int current) |
| if (!node->isTextNode()) |
| return current + 1; |
| const String& text = toText(node)->data(); |
| - if (text.is8Bit()) |
| - return current + 1; // TODO(nona): Good to support CR x LF. |
| - TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), text.length()); |
| - if (!iterator) |
| + const int length = text.length(); |
| + DCHECK_LE(current, length); |
| + if (current >= (length - 1)) |
| return current + 1; |
| - const int result = iterator->following(current); |
| - return result == TextBreakDone ? current + 1 : result; |
| + return findNextBoundaryOffset<ForwardGraphemeBoundaryStateMachine>( |
| + text, current); |
| } |
| template <typename Strategy> |