Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/InsertIncrementalTextCommand.cpp

Issue 2782823002: Make InsertIncrementalTextCommand to handle surrogate pair (Closed)
Patch Set: 2017-03-29T16:13:30 Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/editing/commands/InsertIncrementalTextCommand.h" 5 #include "core/editing/commands/InsertIncrementalTextCommand.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/dom/Text.h" 9 #include "core/dom/Text.h"
10 #include "core/editing/EditingUtilities.h" 10 #include "core/editing/EditingUtilities.h"
11 #include "core/editing/Editor.h" 11 #include "core/editing/Editor.h"
12 #include "core/editing/PlainTextRange.h" 12 #include "core/editing/PlainTextRange.h"
13 #include "core/editing/VisibleUnits.h" 13 #include "core/editing/VisibleUnits.h"
14 #include "core/editing/iterators/CharacterIterator.h" 14 #include "core/editing/iterators/CharacterIterator.h"
15 #include "core/editing/state_machines/ForwardCodePointStateMachine.h"
15 #include "core/html/HTMLSpanElement.h" 16 #include "core/html/HTMLSpanElement.h"
16 17
17 namespace blink { 18 namespace blink {
18 19
19 namespace { 20 namespace {
20 21
21 size_t computeCommonPrefixLength(const String& str1, const String& str2) { 22 size_t computeCommonPrefixLength(const String& str1, const String& str2) {
22 const size_t maxCommonPrefixLength = std::min(str1.length(), str2.length()); 23 const size_t maxCommonPrefixLength = std::min(str1.length(), str2.length());
24 ForwardCodePointStateMachine codePointStateMachine;
25 int result = 0;
23 for (size_t index = 0; index < maxCommonPrefixLength; ++index) { 26 for (size_t index = 0; index < maxCommonPrefixLength; ++index) {
24 if (str1[index] != str2[index]) 27 if (str1[index] != str2[index])
25 return index; 28 return result;
29 codePointStateMachine.feedFollowingCodeUnit(str1[index]);
30 if (!codePointStateMachine.atCodePointBoundary())
31 continue;
32 result = index;
26 } 33 }
27 return maxCommonPrefixLength; 34 return maxCommonPrefixLength;
28 } 35 }
29 36
30 size_t computeCommonSuffixLength(const String& str1, const String& str2) { 37 size_t computeCommonSuffixLength(const String& str1, const String& str2) {
31 const size_t length1 = str1.length(); 38 const size_t length1 = str1.length();
32 const size_t length2 = str2.length(); 39 const size_t length2 = str2.length();
33 const size_t maxCommonSuffixLength = std::min(length1, length2); 40 const size_t maxCommonSuffixLength = std::min(length1, length2);
34 for (size_t index = 0; index < maxCommonSuffixLength; ++index) { 41 for (size_t index = 0; index < maxCommonSuffixLength; ++index) {
35 if (str1[length1 - index - 1] != str2[length2 - index - 1]) 42 if (str1[length1 - index - 1] != str2[length2 - index - 1])
Changwan Ryu 2017/03/29 15:36:57 Could you consider doing the same for this functio
yosin_UTC9 2017/04/03 05:27:28 I'll do in another patch.
36 return index; 43 return index;
37 } 44 }
38 return maxCommonSuffixLength; 45 return maxCommonSuffixLength;
39 } 46 }
40 47
41 // If current position is at grapheme boundary, return 0; otherwise, return the 48 // If current position is at grapheme boundary, return 0; otherwise, return the
42 // distance to its nearest left grapheme boundary. 49 // distance to its nearest left grapheme boundary.
43 size_t computeDistanceToLeftGraphemeBoundary(const Position& position) { 50 size_t computeDistanceToLeftGraphemeBoundary(const Position& position) {
44 const Position& adjustedPosition = previousPositionOf( 51 const Position& adjustedPosition = previousPositionOf(
45 nextPositionOf(position, PositionMoveType::GraphemeCluster), 52 nextPositionOf(position, PositionMoveType::GraphemeCluster),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 const VisibleSelection& selectionForInsertion = computeSelectionForInsertion( 183 const VisibleSelection& selectionForInsertion = computeSelectionForInsertion(
177 selectionRange, offset, length, endingSelection().isDirectional()); 184 selectionRange, offset, length, endingSelection().isDirectional());
178 185
179 setEndingSelectionWithoutValidation(selectionForInsertion.start(), 186 setEndingSelectionWithoutValidation(selectionForInsertion.start(),
180 selectionForInsertion.end()); 187 selectionForInsertion.end());
181 188
182 InsertTextCommand::doApply(editingState); 189 InsertTextCommand::doApply(editingState);
183 } 190 }
184 191
185 } // namespace blink 192 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698