| 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..7465262ac7324e34a6102a1154e37cefc431b5c4 100644 | 
| --- a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp | 
| +++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp | 
| @@ -166,6 +166,53 @@ 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 | 
| + | 
| +  // Deviation from the concept-cd-replace algorithm: second condition in the | 
| +  // next line (don't include text inserted immediately before a marker in the | 
| +  // marked range, but do include the new text if it's replacing text in the | 
| +  // marked range) | 
| +  if (startOffset() > offset || (startOffset() == offset && oldLength == 0)) { | 
| +    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; | 
|  |