Merge "highlighter: Ensure items in .ranges and .$element are in the same order"

This commit is contained in:
jenkins-bot 2022-04-21 23:55:17 +00:00 committed by Gerrit Code Review
commit 90018a5b55

View file

@ -10,10 +10,9 @@ var
* @param {CommentItem|CommentItem[]} comments Comment item(s) to highlight
*/
function Highlight( comments ) {
var highlight = this;
var highlightNodes = [];
var ranges = [];
this.ranges = [];
this.$element = $( [] );
this.topmostElement = null;
comments = Array.isArray( comments ) ? comments : [ comments ];
@ -30,10 +29,13 @@ function Highlight( comments ) {
// before, otherwise Node#getBoundingClientRect() returns wrong results.
range.insertNode( $highlight[ 0 ] );
highlight.ranges.push( range );
highlight.$element = highlight.$element.add( $highlight );
ranges.push( range );
highlightNodes.push( $highlight[ 0 ] );
} );
this.ranges = ranges;
this.$element = $( highlightNodes );
// Events
this.updateDebounced = OO.ui.debounce( this.update.bind( this ), 500 );
window.addEventListener( 'resize', this.updateDebounced );