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

Unified Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 1824143003: [All-In-One] Introduce BackspaceStateMachine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 9 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
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 fed03353f55ed4fa03b8f0b67ffc02d2b62934ef..ed9fffdebb792350ced2828ad2dc618055353b78 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"
@@ -547,9 +548,21 @@ int uncheckedPreviousOffset(const Node* n, int current)
return n->layoutObject() ? n->layoutObject()->previousOffset(current) : current - 1;
}
-static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current)
+static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int current)
{
- 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();
}
int uncheckedNextOffset(const Node* n, int current)

Powered by Google App Engine
This is Rietveld 408576698