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

Unified Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp

Issue 2895353003: Split DMLEditor::ShiftMarkers() into content-dependent and -independent versions (Closed)
Patch Set: Created 3 years, 7 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/markers/DocumentMarkerListEditor.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp
index ee00cee38dbca749b7843de1197d56e4427ca033..d9a181b6fb321fbcd874278381702650a71c16ef 100644
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp
@@ -81,10 +81,44 @@ bool DocumentMarkerListEditor::RemoveMarkers(MarkerList* list,
return doc_dirty;
}
-bool DocumentMarkerListEditor::ShiftMarkers(MarkerList* list,
- unsigned offset,
- unsigned old_length,
- unsigned new_length) {
+// TODO(rlanday): make this not take O(n^2) time when all the markers are
+// removed
+bool DocumentMarkerListEditor::ShiftMarkersContentDependent(
+ MarkerList* list,
+ unsigned offset,
+ unsigned old_length,
+ unsigned new_length) {
+ bool did_shift_marker = false;
+ for (MarkerList::iterator it = list->begin(); it != list->end(); ++it) {
+ DocumentMarker& marker = **it;
+
+ // marked text is neither changed nor shifted
+ if (marker.EndOffset() <= offset)
+ continue;
+
+ // marked text is (potentially) changed by edit, remove marker
+ if (marker.StartOffset() < offset + old_length) {
+ list->erase(it - list->begin());
+ --it;
+ did_shift_marker = true;
+ continue;
+ }
+
+ // marked text is shifted but not changed
+ marker.ShiftOffsets(new_length - old_length);
+ did_shift_marker = true;
+ }
+
+ return did_shift_marker;
+}
+
+// TODO(rlanday): make this not take O(n^2) time when all the markers are
+// removed
+bool DocumentMarkerListEditor::ShiftMarkersContentIndependent(
+ MarkerList* list,
+ unsigned offset,
+ unsigned old_length,
+ unsigned new_length) {
bool did_shift_marker = false;
for (MarkerList::iterator it = list->begin(); it != list->end(); ++it) {
DocumentMarker& marker = **it;

Powered by Google App Engine
This is Rietveld 408576698