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

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: 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..43648cbcf2ba3994b7679df882eb2710ae4a4f5d 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"
@@ -549,7 +550,20 @@ int uncheckedPreviousOffset(const Node* n, int current)
static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current)
yosin_UTC9 2016/03/25 04:37:23 Please avoid to use one letter variable name.
Seigo Nonaka 2016/03/25 06:59:06 Done.
{
- return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDeletion(current) : current - 1;
+ if (current <= 1)
+ return 0;
+ if (!n->isTextNode())
+ return current - 1;
+
+ const String& text = toText(n)->data();
+ CHECK(static_cast<unsigned>(current - 1) < text.length());
+ BackspaceStateMachine machine;
+ for (int i = current - 1; i >= 0; --i) {
+ if (machine.ComputeNextState(text[i])) {
yosin_UTC9 2016/03/25 04:37:23 nit: no need to have braces for single line statem
Seigo Nonaka 2016/03/25 06:59:06 Done.
+ break;
+ }
+ }
+ return current - machine.FinalizeAndGetCodeUnitCountToBeDeleted();
}
int uncheckedNextOffset(const Node* n, int current)

Powered by Google App Engine
This is Rietveld 408576698