<commit_before>/**
 * Handsontable is a simple jQuery plugin for editable tables with basic copy-paste compatibility with Excel and Google Docs
 *
 * Copyright 2011, <NAME>
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://warpech.github.com/jquery-handsontable/
 */
/*jslint white: true, browser: true, plusplus: true, indent: 4, maxerr: 50 */
(function ($) {
	"use strict";

	function Handsontable(container, settings) {
		var UNDEFINED = (function () {}()), priv, grid, selection, keyboard, editproxy, highlight, interaction;

		priv = {
			isMouseOverTable: false,
			isMouseDown: false,
			isCellEdited: false,
			selStart: null,
			selEnd: null,
			editProxy: false,
			table: null
		};

		grid = {
			/**
			 * Creates row at the bottom
			 */
			createRow: function () {
				var tr, td, c;
				tr = $('<tr>');
				for (c = 0; c < settings.cols; c++) {
					td = $('<td>');
					tr.append(td);
					td.bind('mousedown', interaction.onMouseDown);
					td.bind('mouseover', interaction.onMouseOver);
				}
				priv.table.append(tr);
			},

			/**
			 * Makes sure there are empty rows at the bottom of the table
			 */
			keepEmptyRows: function () {
				if (!settings.keepSpareRows) {
					return;
				}
				var trs, tds, r, c, clen, emptyRows = 0, trslen;
				trs = priv.table.find('tr');
				trslen = trs.length;
					rows : for (r = trslen - 1; r >= 0; r--) {
						tds = $(trs[r]).find('td');
							cols : for (c = 0, clen = tds.length; c < clen; c++) {
								if (tds[c].innerHTML !== '') {
									break rows;
								}
							}
						emptyRows++;
					}
				if (emptyRows < settings.keepSpareRows) {
					for (; emptyRows < settings.keepSpareRows; emptyRows++) {
						grid.createRow();
					}
				} else if (emptyRows > settings.keepSpareRows) {
					r = Math.min(emptyRows - settings.keepSpareRows, trslen - settings.rows);
					if (r > 0) {
						trs.slice(-r).remove(); //slices last n rows from table and removes them
						//if selection is outside, move selection to last row
						if (priv.selStart.row > trslen - r - 1) {
							priv.selStart.row = trslen - r - 1;
							if (priv.selEnd.row > priv.selStart.row) {
								priv.selEnd.row = priv.selStart.row;
							}
							highlight.on();
						} else if (priv.selEnd.row > trslen - r - 1) {
							priv.selEnd.row = trslen - r - 1;
							if (priv.selStart.row > priv.selEnd.row) {
								priv.selStart.row = priv.selEnd.row;
							}
							highlight.on();
						}
					}
				}
			},<commit_msg>only change selection if it really exists<commit_after>/**
 * Handsontable is a simple jQuery plugin for editable tables with basic copy-paste compatibility with Excel and Google Docs
 *
 * Copyright 2011, <NAME>
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://warpech.github.com/jquery-handsontable/
 */
/*jslint white: true, browser: true, plusplus: true, indent: 4, maxerr: 50 */
(function ($) {
	"use strict";

	function Handsontable(container, settings) {
		var UNDEFINED = (function () {}()), priv, grid, selection, keyboard, editproxy, highlight, interaction;

		priv = {
			isMouseOverTable: false,
			isMouseDown: false,
			isCellEdited: false,
			selStart: null,
			selEnd: null,
			editProxy: false,
			table: null
		};

		grid = {
			/**
			 * Creates row at the bottom
			 */
			createRow: function () {
				var tr, td, c;
				tr = $('<tr>');
				for (c = 0; c < settings.cols; c++) {
					td = $('<td>');
					tr.append(td);
					td.bind('mousedown', interaction.onMouseDown);
					td.bind('mouseover', interaction.onMouseOver);
				}
				priv.table.append(tr);
			},

			/**
			 * Makes sure there are empty rows at the bottom of the table
			 */
			keepEmptyRows: function () {
				if (!settings.keepSpareRows) {
					return;
				}
				var trs, tds, r, c, clen, emptyRows = 0, trslen;
				trs = priv.table.find('tr');
				trslen = trs.length;
					rows : for (r = trslen - 1; r >= 0; r--) {
						tds = $(trs[r]).find('td');
							cols : for (c = 0, clen = tds.length; c < clen; c++) {
								if (tds[c].innerHTML !== '') {
									break rows;
								}
							}
						emptyRows++;
					}
				if (emptyRows < settings.keepSpareRows) {
					for (; emptyRows < settings.keepSpareRows; emptyRows++) {
						grid.createRow();
					}
				} else if (emptyRows > settings.keepSpareRows) {
					r = Math.min(emptyRows - settings.keepSpareRows, trslen - settings.rows);
					if (r > 0) {
						trs.slice(-r).remove(); //slices last n rows from table and removes them
						if(priv.selStart) {
							//if selection is outside, move selection to last row
							if (priv.selStart.row > trslen - r - 1) {
								priv.selStart.row = trslen - r - 1;
								if (priv.selEnd.row > priv.selStart.row) {
									priv.selEnd.row = priv.selStart.row;
								}
								highlight.on();
							} else if (priv.selEnd.row > trslen - r - 1) {
								priv.selEnd.row = trslen - r - 1;
								if (priv.selStart.row > priv.selEnd.row) {
									priv.selStart.row = priv.selEnd.row;
								}
								highlight.on();
							}	
						}
					}
				}
			},
{'fraction_non_alphanumeric': 0.14748272458045408, 'fraction_numerical': 0.007107601184600198, 'mean_word_length': 2.272609819121447, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '199568', 'n_tokens_mistral': 2321, 'n_tokens_neox': 1696, 'n_words': 461}