| 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..15f816b39acf360f1af4e7e92c04efdd0a148e2f 100644
|
| --- a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp
|
| @@ -166,6 +166,50 @@ DocumentMarker::DocumentMarker(const DocumentMarker& marker)
|
| m_endOffset(marker.endOffset()),
|
| m_details(marker.details()) {}
|
|
|
| +DocumentMarker::ShiftMarkerResult DocumentMarker::getShiftedMarkerPosition(
|
| + unsigned offset,
|
| + unsigned oldLength,
|
| + unsigned newLength) const {
|
| + 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;
|
|
|