<commit_before>// -------------------------------------------------------------------------- \\
// File: ListView.js                                                          \\
// Module: View                                                               \\
// Requires: UnorderedCollectionView.js                                       \\
// Author: <NAME>                                                       \\
// License: © 2010–2012 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

/*global document */

"use strict";

( function ( NS ) {

var ListView = NS.Class({

    Extends: NS.UnorderedCollectionView,

    Mixin: NS.TrueVisibleRect,

    _batchSize: 10,
    _triggerInPx: 200,

    init: function ( options ) {
        this._renderRange = { start: 0, end: 0 };
        ListView.parent.init.call( this, options );
    },

    positioning: 'absolute',

    contentWasUpdated: function ( event ) {
        var scrollView = this.getParent( NS.ScrollView );
        if ( scrollView ) {
            // Update scroll view correctly.
            var itemHeight = this.get( 'itemHeight' ),
                // Index of first item rendered
                top = ~~( this.get( 'visibleRect' ).y / itemHeight ),
                removedIndexes = event.removedIndexes,
                addedIndexes = event.addedIndexes,
                change = 0,
                i, l;

            if ( top < 3 && addedIndexes[0] < 3 ) {
                change = -( top + 1 );
            }
            else {
                for ( i = 0, l = removedIndexes.length; i < l; i += 1 ) {
                    if ( removedIndexes[i] < top ) { change -= 1; }
                    // Guaranteed in ascending order.
                    else { break; }
                }
                top += change;
                for ( i = 0, l = addedIndexes.length; i < l; i += 1 ) {
                    if ( addedIndexes[i] <= top ) { change += 1; }
                    // Guaranteed in ascending order.
                    else { break; }
                }
            }
            if ( change ) {
                scrollView.scrollBy( 0, change * itemHeight );
            }
        }
    },

    _simulateScroll: function ( _, __, oldLength, length ) {
        // Convert null/undefined length to 0.
        if ( !length ) { length = 0; }
        // In IE or Opera, if the scrollTop of the containing overflowed div was
        // past the new maximum scrollTop, then although it correctly changes
        // to the new maximum scrollTop, no scroll event is fired. Therefore we
        // have to simulate this firing in the next event loop.
        if ( length < oldLength ) {
            NS.RunLoop.invokeInNextEventLoop(
                this.fire.bind( this, 'scroll', null, null )
            );
        }
    }.observes( 'contentLength' ),

    visibleRectDidChange: function () {
        // We only care about changes when we're visible.
        if ( this.get( 'isInDocument' ) ) {
            var visible = this.get( 'visibleRect' ),
                extension = this._triggerInPx,
                batchSize = this._batchSize,
                height = this.get( 'itemHeight' ) * batchSize,
                y = visible.y,
                // Index of first item we want rendered
                start = Math.max( 0,
                    ~~( ( y - extension ) / height ) * batchSize ),
                // Index of last item we want rendered
                end = ~~( ( y + visible.height + extension ) / height ) *
                    batchSize + batchSize,
                _renderRange = this._renderRange;

            if ( start !== _renderRange.start || end !== _renderRange.end ) {
                _renderRange.start = start;
                _renderRange.end = end;
                this._redraw();
            }
        }
    }.queue( 'after' ).observes( 'visibleRect', 'itemHeight' )
});

NS.ListView = ListView;

}( this.O ) );<commit_msg>Call ListView#visibleRectDidChange in middle phase<commit_after>// -------------------------------------------------------------------------- \\
// File: ListView.js                                                          \\
// Module: View                                                               \\
// Requires: UnorderedCollectionView.js                                       \\
// Author: <NAME>                                                       \\
// License: © 2010–2012 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

/*global document */

"use strict";

( function ( NS ) {

var ListView = NS.Class({

    Extends: NS.UnorderedCollectionView,

    Mixin: NS.TrueVisibleRect,

    _batchSize: 10,
    _triggerInPx: 200,

    init: function ( options ) {
        this._renderRange = { start: 0, end: 0 };
        ListView.parent.init.call( this, options );
    },

    positioning: 'absolute',

    contentWasUpdated: function ( event ) {
        var scrollView = this.getParent( NS.ScrollView );
        if ( scrollView ) {
            // Update scroll view correctly.
            var itemHeight = this.get( 'itemHeight' ),
                // Index of first item rendered
                top = ~~( this.get( 'visibleRect' ).y / itemHeight ),
                removedIndexes = event.removedIndexes,
                addedIndexes = event.addedIndexes,
                change = 0,
                i, l;

            if ( top < 3 && addedIndexes[0] < 3 ) {
                change = -( top + 1 );
            }
            else {
                for ( i = 0, l = removedIndexes.length; i < l; i += 1 ) {
                    if ( removedIndexes[i] < top ) { change -= 1; }
                    // Guaranteed in ascending order.
                    else { break; }
                }
                top += change;
                for ( i = 0, l = addedIndexes.length; i < l; i += 1 ) {
                    if ( addedIndexes[i] <= top ) { change += 1; }
                    // Guaranteed in ascending order.
                    else { break; }
                }
            }
            if ( change ) {
                scrollView.scrollBy( 0, change * itemHeight );
            }
        }
    },

    _simulateScroll: function ( _, __, oldLength, length ) {
        // Convert null/undefined length to 0.
        if ( !length ) { length = 0; }
        // In IE or Opera, if the scrollTop of the containing overflowed div was
        // past the new maximum scrollTop, then although it correctly changes
        // to the new maximum scrollTop, no scroll event is fired. Therefore we
        // have to simulate this firing in the next event loop.
        if ( length < oldLength ) {
            NS.RunLoop.invokeInNextEventLoop(
                this.fire.bind( this, 'scroll', null, null )
            );
        }
    }.observes( 'contentLength' ),

    visibleRectDidChange: function () {
        // We only care about changes when we're visible.
        if ( this.get( 'isInDocument' ) ) {
            var visible = this.get( 'visibleRect' ),
                extension = this._triggerInPx,
                batchSize = this._batchSize,
                height = this.get( 'itemHeight' ) * batchSize,
                y = visible.y,
                // Index of first item we want rendered
                start = Math.max( 0,
                    ~~( ( y - extension ) / height ) * batchSize ),
                // Index of last item we want rendered
                end = ~~( ( y + visible.height + extension ) / height ) *
                    batchSize + batchSize,
                _renderRange = this._renderRange;

            if ( start !== _renderRange.start || end !== _renderRange.end ) {
                _renderRange.start = start;
                _renderRange.end = end;
                this._redraw();
            }
        }
    }.queue( 'middle' ).observes( 'visibleRect', 'itemHeight' )
});

NS.ListView = ListView;

}( this.O ) );
{'fraction_non_alphanumeric': 0.14109895574341125, 'fraction_numerical': 0.007458975634012929, 'mean_word_length': 1.1424766977363516, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1779439', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1930, 'n_words': 572}