mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
Merge "Work around invalid ranges in #getNativeRange"
This commit is contained in:
commit
7898eb4757
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue