<commit_before>import Directive from './directive';
import {AUTOFOCUS_NAME, GRID_NAME} from '@grid/view/definition';

class Autofocus extends Directive(AUTOFOCUS_NAME, {root: `${GRID_NAME}`}) {
	constructor($scope, $element, $timeout) {
		super();

		this.$scope = $scope;
		this.$element = $element;
		this.$timeout = $timeout;
	}

	onInit() {
		this.model.dataChanged.on(e => {
			if (e.hasChanges('rows') && e.state.rows.length > 0) {
				this.$timeout(() => {
					const table = this.$element.find('table')[0];
					table.focus();
					this.model.focus({
						rowIndex: 0,
						columnIndex: 0
					});
				}, 200);
			}
		});
	}

	get model() {
		return this.root.model;
	}
}

Autofocus.$inject = ['$scope', '$element', '$timeout'];

export default {
	restrict: 'A',
	bindToController: true,<commit_msg>use grid table inside autofocus<commit_after>import Directive from './directive';
import {AUTOFOCUS_NAME, GRID_NAME} from '@grid/view/definition';
import {noop, isUndefined} from '@grid/core/utility';

class Autofocus extends Directive(AUTOFOCUS_NAME, {root: `${GRID_NAME}`}) {
	constructor($scope, $element, $timeout) {
		super();

		this.$scope = $scope;
		this.$element = $element;
		this.$timeout = $timeout;

		this.dataChangedOff = noop;
	}

	onInit() {
		this.dataChangedOff = this.model.viewChanged.watch(e => {
			if (e.hasChanges('rows') && e.state.rows.length > 0
				|| e.hasChanges('nodes') && e.state.nodes.length > 0) {
				this.$timeout(() => {
					if (this.table.body.rowCount === 0) {
						return;
					}

					const table = Object.keys(this.table.markup).find(p => p.startsWith('table'));
					if (isUndefined(table)) {
						return;
					}

					this.table.markup[table].focus();
					this.model.focus({
						rowIndex: 0,
						columnIndex: 0
					});
				}, 200);

				this.dataChangedOff();
			}
		});
	}

	get model() {
		return this.root.model;
	}

	get table() {
		return this.root.table;
	}

	onDestroy() {
		this.dataChangedOff();
	}
}

Autofocus.$inject = ['$scope', '$element', '$timeout'];

export default {
	restrict: 'A',
	bindToController: true,
{'fraction_non_alphanumeric': 0.18277511961722487, 'fraction_numerical': 0.007177033492822967, 'mean_word_length': 3.392857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2625804', 'n_tokens_mistral': 880, 'n_tokens_neox': 736, 'n_words': 141}