Merge "Work around invalid ranges in #getNativeRange"

This commit is contained in:
jenkins-bot 2020-06-01 14:59:01 +00:00 committed by Gerrit Code Review
commit 7898eb4757

View file

@ -7,11 +7,20 @@
* @return {Range}
*/
function getNativeRange( comment ) {
var
var endContainer, endOffset,
doc = comment.range.startContainer.ownerDocument,
nativeRange = doc.createRange();
nativeRange.setStart( comment.range.startContainer, comment.range.startOffset );
nativeRange.setEnd( comment.range.endContainer, comment.range.endOffset );
// HACK: When the offset is outside the container, assume this is because of
// the 'mw:Entity' hack in parser#findTimestamps and adjust accordingly.
// TODO: The parser should produce valid ranges!
endContainer = comment.range.endContainer;
endOffset = comment.range.endOffset;
while ( endOffset > ( endContainer.length || endContainer.childNodes.length ) ) {
endOffset -= ( endContainer.length || endContainer.childNodes.length );
endContainer = endContainer.nextSibling;
}
nativeRange.setEnd( endContainer, endOffset );
return nativeRange;
}