<commit_before>import {
	Input,
	AfterViewInit,
	ViewChild,
	ViewChildren,
	ElementRef,
	forwardRef,
	OnDestroy,
	QueryList
} from '@angular/core';
import {
	ASelectOptionFeeder,
	ISelectOptionFeeder,
	LuSelectOption,
} from '../../option';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { Subject } from 'rxjs/Subject';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import { ISelectScrollable } from './select-scroll-picker.model';

/**
 * Component that manage the possibility to search in the options of a select.
 */
// tslint:disable-next-line:component-class-suffix
export abstract class ASelectScrollPicker<T>
	extends ASelectOptionFeeder<T>
	implements
		ISelectScrollable<T>,
		AfterViewInit {

	// Inner references
	_loading = false;
	_options: T[];
	protected _noMoreResults = false;
	protected _requestSubscription: Subscription;

	/** The scroll element */
	@ViewChild('scrollElement') _scrollElement: ElementRef;
	/** The list of users (option) */
	@ViewChildren(LuSelectOption) _optionsList: QueryList<LuSelectOption<T>>;

	constructor(

		protected _elementRef: ElementRef) {
		super();
		this._options = [];
		this._populateList();
	}


	ngAfterViewInit(): void {
		this._optionsList.changes.subscribe(options => {
			if (this._callbackOptions) {
				this._callbackOptions(this._optionsList.toArray());
			}
		});
	}

	// Events
		_onScroll($event: Event) {
		const height = this._scrollElement.nativeElement.offsetHeight;
		const top = this._scrollElement.nativeElement.scrollTop;
		if (height - top < 50 && !this._loading && !this._noMoreResults) {
			this._populateList();
		}
	}


	protected _populateList(): void {
		this._loading = true;
		if (this._requestSubscription && !this._requestSubscription.closed) {
			this._requestSubscription.unsubscribe();
			this._requestSubscription = null;
		}

		this._requestSubscription = this.loadMoreOptions().subscribe((additionnalOptions) => {
			this._options = this._options.concat(additionnalOptions);<commit_msg>[NG] Fix scroll management<commit_after>import {
	Input,
	AfterViewInit,
	ViewChild,
	ViewChildren,
	ElementRef,
	forwardRef,
	OnDestroy,
	QueryList
} from '@angular/core';
import {
	ASelectOptionFeeder,
	ISelectOptionFeeder,
	LuSelectOption,
} from '../../option';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { Subject } from 'rxjs/Subject';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import { ISelectScrollable } from './select-scroll-picker.model';

/**
 * Component that manage the possibility to search in the options of a select.
 */
// tslint:disable-next-line:component-class-suffix
export abstract class ASelectScrollPicker<T>
	extends ASelectOptionFeeder<T>
	implements
		ISelectScrollable<T>,
		AfterViewInit {

	// Inner references
	_loading = false;
	_options: T[];
	protected _noMoreResults = false;
	protected _requestSubscription: Subscription;

	/** The scroll element */
	@ViewChild('scrollElement') _scrollElement: ElementRef;
	/** The list of users (option) */
	@ViewChildren(LuSelectOption) _optionsList: QueryList<LuSelectOption<T>>;

	constructor(

		protected _elementRef: ElementRef) {
		super();
		this._options = [];
		this._populateList();
	}


	ngAfterViewInit(): void {
		this._optionsList.changes.subscribe(options => {
			if (this._callbackOptions) {
				this._callbackOptions(this._optionsList.toArray());
			}
		});
	}

	// Events
		_onScroll($event: Event) {
		const scrollHeight = this._scrollElement.nativeElement.scrollHeight;
		const height = this._scrollElement.nativeElement.offsetHeight;
		const top = this._scrollElement.nativeElement.scrollTop;
		if (scrollHeight - height - top < 50 && !this._loading && !this._noMoreResults) {
			this._populateList();
		}
	}


	protected _populateList(): void {
		this._loading = true;
		if (this._requestSubscription && !this._requestSubscription.closed) {
			this._requestSubscription.unsubscribe();
			this._requestSubscription = null;
		}

		this._requestSubscription = this.loadMoreOptions().subscribe((additionnalOptions) => {
			this._options = this._options.concat(additionnalOptions);
{'fraction_non_alphanumeric': 0.12276092667781227, 'fraction_numerical': 0.0009553379508000956, 'mean_word_length': 4.882022471910112, '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': '1375416', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1258, 'n_words': 266}