<commit_before>import {Component, PostConstruct, Utils} from "ag-grid/main";

export interface VirtualListModel {
    getRowCount(): number;
    getRow(index: number): any;
}

export class VirtualList extends Component {

    private static TEMPLATE =
        '<div class="ag-virtual-list-viewport">'+
        '<div class="ag-virtual-list-container">'+
        '</div>'+
        '</div>';

    private model: VirtualListModel;

    private eListContainer: HTMLElement;
    private rowsInBodyContainer: any = {};

    private componentCreator: (value:any)=>Component;

    private rowHeight = 20;

    constructor() {
        super(null);
    }

    @PostConstruct
    private init(): void {
        this.setTemplate(VirtualList.TEMPLATE);

        this.eListContainer = this.queryForHtmlElement(".ag-virtual-list-container");

        this.addScrollListener();
    }

    public ensureIndexVisible(index: number): void {
        let lastRow = this.model.getRowCount();
        if (typeof index !== 'number' || index < 0 || index >= lastRow) {
            console.warn('invalid row index for ensureIndexVisible: ' + index);
            return;
        }

        // let nodeAtIndex = this.rowModel.getRow(index);
        let rowTopPixel = index * this.rowHeight;
        let rowBottomPixel = rowTopPixel + this.rowHeight;

        let viewportTopPixel = this.getGui().scrollTop;
        let viewportHeight = this.getGui().offsetHeight;
        let viewportBottomPixel = viewportTopPixel + viewportHeight;

        let viewportScrolledPastRow = viewportTopPixel > rowTopPixel;
        let viewportScrolledBeforeRow = viewportBottomPixel < rowBottomPixel;

        if (viewportScrolledPastRow) {
            // if row is before, scroll up with row at top
            this.getGui().scrollTop = rowTopPixel;
        } else if (viewportScrolledBeforeRow) {
            // if row is below, scroll down with row at bottom
            let newScrollPosition = rowBottomPixel - viewportHeight;
            this.getGui().scrollTop = newScrollPosition;
        }<commit_msg>nasty hard-coded material size<commit_after>import {Environment, Autowired, Component, PostConstruct, Utils} from "ag-grid/main";

export interface VirtualListModel {
    getRowCount(): number;
    getRow(index: number): any;
}

export class VirtualList extends Component {

    private static TEMPLATE =
        '<div class="ag-virtual-list-viewport">'+
        '<div class="ag-virtual-list-container">'+
        '</div>'+
        '</div>';

    private model: VirtualListModel;

    private eListContainer: HTMLElement;
    private rowsInBodyContainer: any = {};

    private componentCreator: (value:any)=>Component;

    private rowHeight = 20;

    @Autowired('environment') private environment:  Environment;

    constructor() {
        super(null);
    }

    @PostConstruct
    private init(): void {
        this.setTemplate(VirtualList.TEMPLATE);

        this.eListContainer = this.queryForHtmlElement(".ag-virtual-list-container");

        this.addScrollListener();

        if (this.environment.getTheme() == "ag-material-next") {
            this.rowHeight = 32;
        }
    }

    public ensureIndexVisible(index: number): void {
        let lastRow = this.model.getRowCount();
        if (typeof index !== 'number' || index < 0 || index >= lastRow) {
            console.warn('invalid row index for ensureIndexVisible: ' + index);
            return;
        }

        // let nodeAtIndex = this.rowModel.getRow(index);
        let rowTopPixel = index * this.rowHeight;
        let rowBottomPixel = rowTopPixel + this.rowHeight;

        let viewportTopPixel = this.getGui().scrollTop;
        let viewportHeight = this.getGui().offsetHeight;
        let viewportBottomPixel = viewportTopPixel + viewportHeight;

        let viewportScrolledPastRow = viewportTopPixel > rowTopPixel;
        let viewportScrolledBeforeRow = viewportBottomPixel < rowBottomPixel;

        if (viewportScrolledPastRow) {
            // if row is before, scroll up with row at top
            this.getGui().scrollTop = rowTopPixel;
        } else if (viewportScrolledBeforeRow) {
            // if row is below, scroll down with row at bottom
            let newScrollPosition = rowBottomPixel - viewportHeight;
            this.getGui().scrollTop = newScrollPosition;
        }
{'fraction_non_alphanumeric': 0.10442600276625173, 'fraction_numerical': 0.0018441678192715537, 'mean_word_length': 2.70221843003413, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1527371', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1164, 'n_words': 288}