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

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

Issue 2634243002: Fix a bug when inputting text after grapheme cluster (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/commands/InsertIncrementalTextCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/InsertIncrementalTextCommand.cpp b/third_party/WebKit/Source/core/editing/commands/InsertIncrementalTextCommand.cpp
index 7bb2e1b91d5eb097233083827bfe15d77d6e7986..4759d76a93b4d40bd5da1fd2f4e0904419c9d984 100644
--- a/third_party/WebKit/Source/core/editing/commands/InsertIncrementalTextCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/InsertIncrementalTextCommand.cpp
@@ -52,6 +52,7 @@ size_t computeDistanceToLeftGraphemeBoundary(const Position& position) {
}
size_t computeCommonGraphemeClusterPrefixLength(
+ const int selectionStart,
const String& oldText,
const String& newText,
const Element* rootEditableElement) {
@@ -59,7 +60,8 @@ size_t computeCommonGraphemeClusterPrefixLength(
// For grapheme cluster, we should adjust it for grapheme boundary.
const EphemeralRange& range =
- PlainTextRange(0, commonPrefixLength).createRange(*rootEditableElement);
+ PlainTextRange(0, selectionStart + commonPrefixLength)
+ .createRange(*rootEditableElement);
if (range.isNull())
return 0;
const Position& position = range.endPosition();
@@ -82,6 +84,7 @@ size_t computeDistanceToRightGraphemeBoundary(const Position& position) {
}
size_t computeCommonGraphemeClusterSuffixLength(
+ const int selectionStart,
const String& oldText,
const String& newText,
const Element* rootEditableElement) {
@@ -89,7 +92,7 @@ size_t computeCommonGraphemeClusterSuffixLength(
// For grapheme cluster, we should adjust it for grapheme boundary.
const EphemeralRange& range =
- PlainTextRange(0, oldText.length() - commonSuffixLength)
+ PlainTextRange(0, selectionStart + oldText.length() - commonSuffixLength)
.createRange(*rootEditableElement);
if (range.isNull())
return 0;
@@ -150,13 +153,15 @@ void InsertIncrementalTextCommand::doApply(EditingState* editingState) {
const String oldText = plainText(selectionRange);
const String& newText = m_text;
+ const int selectionStart =
+ endingSelection().start().computeOffsetInContainerNode();
const size_t newTextLength = newText.length();
const size_t oldTextLength = oldText.length();
- const size_t commonPrefixLength =
- computeCommonGraphemeClusterPrefixLength(oldText, newText, element);
+ const size_t commonPrefixLength = computeCommonGraphemeClusterPrefixLength(
+ selectionStart, oldText, newText, element);
// We should ignore common prefix when finding common suffix.
const size_t commonSuffixLength = computeCommonGraphemeClusterSuffixLength(
- oldText.right(oldTextLength - commonPrefixLength),
+ selectionStart, oldText.right(oldTextLength - commonPrefixLength),
newText.right(newTextLength - commonPrefixLength), element);
DCHECK_GE(oldTextLength, commonPrefixLength + commonSuffixLength);
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698