Index: third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp |
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp |
index b18b3fd88304206850783d3ee5de7a20483edd5f..9cd36b618bcc1511e719c9a7a7ea06bb3cc28c1e 100644 |
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp |
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp |
@@ -30,6 +30,7 @@ |
#include "core/editing/markers/DocumentMarker.h" |
+#include "core/editing/markers/RenderedTextMatchMarker.h" |
Xiaocheng
2017/03/21 03:59:44
This seems redundant.
|
#include "wtf/StdLibExtras.h" |
namespace blink { |
@@ -166,11 +167,59 @@ DocumentMarker::DocumentMarker(const DocumentMarker& marker) |
m_endOffset(marker.endOffset()), |
m_details(marker.details()) {} |
+DocumentMarker::ShiftMarkerResult DocumentMarker::getShiftedMarkerPosition( |
+ unsigned offset, |
+ unsigned oldLength, |
+ unsigned newLength) { |
+ ShiftMarkerResult result; |
+ result.newStartOffset = startOffset(); |
+ result.newEndOffset = endOffset(); |
+ result.shouldRemoveMarker = false; |
+ |
+ // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace |
+ // but with some changes |
+ if (startOffset() > offset) { |
+ // Deviation from the concept-cd-replace algorithm: < instead of <= in |
+ // the next line |
+ if (startOffset() < offset + oldLength) { |
+ // Marker start was in the replaced text. Move to end of new text |
+ // (Deviation from the concept-cd-replace algorithm: that algorithm |
+ // would move to the beginning of the new text here) |
+ result.newStartOffset = offset + newLength; |
+ } else { |
+ // Marker start was after the replaced text. Shift by length |
+ // difference |
+ result.newStartOffset = startOffset() + newLength - oldLength; |
+ } |
+ } |
+ |
+ if (endOffset() > offset) { |
+ // Deviation from the concept-cd-replace algorithm: < instead of <= in |
+ // the next line |
+ if (endOffset() < offset + oldLength) { |
+ // Marker end was in the replaced text. Move to beginning of new text |
+ result.newEndOffset = offset; |
+ } else { |
+ // Marker end was after the replaced text. Shift by length difference |
+ result.newEndOffset = endOffset() + newLength - oldLength; |
+ } |
+ } |
+ |
+ if (result.newStartOffset >= result.newEndOffset) |
+ result.shouldRemoveMarker = true; |
+ |
+ return result; |
+} |
+ |
void DocumentMarker::shiftOffsets(int delta) { |
m_startOffset += delta; |
m_endOffset += delta; |
} |
+bool DocumentMarker::isRenderedTextMatch() const { |
+ return false; |
+} |
+ |
void DocumentMarker::setActiveMatch(bool active) { |
m_details = DocumentMarkerTextMatch::create(active); |
} |