OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/editing/markers/SpellingMarkerList.h" |
| 6 |
| 7 #include <utility> |
| 8 #include "core/dom/Text.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 SpellingMarkerList::SpellingMarkerList( |
| 13 DocumentMarkerController* documentMarkerController) |
| 14 : EditingMarkerListThatMergesTouchingMarkers(documentMarkerController) {} |
| 15 |
| 16 DocumentMarker::MarkerType SpellingMarkerList::allowedMarkerType() const { |
| 17 return DocumentMarker::Spelling; |
| 18 } |
| 19 |
| 20 void SpellingMarkerList::removeMarkersForWords(const Text& textNode, |
| 21 const Vector<String>& words) { |
| 22 // Build a second vector and swap with m_markers to avoid O(n^2) performance |
| 23 HeapVector<Member<DocumentMarker>> newMarkerList; |
| 24 |
| 25 for (Member<DocumentMarker> marker : m_markers) { |
| 26 unsigned start = marker->startOffset(); |
| 27 unsigned length = marker->endOffset() - marker->startOffset(); |
| 28 |
| 29 String markerText = textNode.data().substring(start, length); |
| 30 if (!words.contains(markerText)) |
| 31 newMarkerList.push_back(marker); |
| 32 } |
| 33 |
| 34 std::swap(m_markers, newMarkerList); |
| 35 } |
| 36 |
| 37 } // namespace blink |
OLD | NEW |