OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/markers/DocumentMarkerListEditor.h" | 5 #include "core/editing/markers/DocumentMarkerListEditor.h" |
6 | 6 |
7 #include "core/editing/markers/RenderedDocumentMarker.h" | 7 #include "core/editing/markers/RenderedDocumentMarker.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 if (marker.StartOffset() >= end_offset) | 81 if (marker.StartOffset() >= end_offset) |
82 break; | 82 break; |
83 | 83 |
84 list->erase(i - list->begin()); | 84 list->erase(i - list->begin()); |
85 doc_dirty = true; | 85 doc_dirty = true; |
86 } | 86 } |
87 | 87 |
88 return doc_dirty; | 88 return doc_dirty; |
89 } | 89 } |
90 | 90 |
| 91 bool DocumentMarkerListEditor::RemoveMarkersUnderWords( |
| 92 MarkerList* list, |
| 93 const String& node_text, |
| 94 const Vector<String>& words) { |
| 95 bool removed_markers = false; |
| 96 for (size_t j = list->size(); j > 0; --j) { |
| 97 const DocumentMarker& marker = *(*list)[j - 1]; |
| 98 const unsigned start = marker.StartOffset(); |
| 99 const unsigned length = marker.EndOffset() - marker.StartOffset(); |
| 100 const String& marker_text = node_text.Substring(start, length); |
| 101 if (words.Contains(marker_text)) { |
| 102 list->erase(j - 1); |
| 103 removed_markers = true; |
| 104 } |
| 105 } |
| 106 |
| 107 return removed_markers; |
| 108 } |
| 109 |
91 bool DocumentMarkerListEditor::ShiftMarkers(MarkerList* list, | 110 bool DocumentMarkerListEditor::ShiftMarkers(MarkerList* list, |
92 unsigned offset, | 111 unsigned offset, |
93 unsigned old_length, | 112 unsigned old_length, |
94 unsigned new_length) { | 113 unsigned new_length) { |
95 bool did_shift_marker = false; | 114 bool did_shift_marker = false; |
96 for (MarkerList::iterator it = list->begin(); it != list->end(); ++it) { | 115 for (MarkerList::iterator it = list->begin(); it != list->end(); ++it) { |
97 RenderedDocumentMarker& marker = **it; | 116 RenderedDocumentMarker& marker = **it; |
98 Optional<DocumentMarker::MarkerOffsets> result = | 117 Optional<DocumentMarker::MarkerOffsets> result = |
99 marker.ComputeOffsetsAfterShift(offset, old_length, new_length); | 118 marker.ComputeOffsetsAfterShift(offset, old_length, new_length); |
100 if (result == WTF::kNullopt) { | 119 if (result == WTF::kNullopt) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 i != list->end() && (*i)->StartOffset() <= (*inserted)->EndOffset();) { | 151 i != list->end() && (*i)->StartOffset() <= (*inserted)->EndOffset();) { |
133 (*inserted)->SetStartOffset( | 152 (*inserted)->SetStartOffset( |
134 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); | 153 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); |
135 (*inserted)->SetEndOffset( | 154 (*inserted)->SetEndOffset( |
136 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); | 155 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); |
137 list->erase(i - list->begin()); | 156 list->erase(i - list->begin()); |
138 } | 157 } |
139 } | 158 } |
140 | 159 |
141 } // namespace blink | 160 } // namespace blink |
OLD | NEW |