<commit_before>define(["dojo/_base/declare", "dojo/on", "./List", "xstyle/put"], function(declare, listen, List, put){
return declare([List], {
	// summary:
	// 		Add selection capabilities to a grid. The grid will have a selection property and
	//		fire "select" and "deselect" events.
	
	create: function(){
		this.selection = {};
		return this.inherited(arguments);
	},
	postCreate: function(){
		this.inherited(arguments);
		var lastRow, mode = this.selectionMode;
		var grid = this;		
		if(this.selectionMode != "none"){
			// listen for actions that should cause selections
			listen(this.contentNode, "mousedown,cellfocusin", function(event){
				if(event.type == "mousedown" || !event.ctrlKey || event.keyCode == 32){
					var row = event.target;
					if(mode == "single" && lastRow && event.ctrlKey){
						grid.deselect(lastRow);
						if(lastRow == row){
							return;
						}
					}
					if(!event.ctrlKey){
						if(mode != "multiple"){
							grid.clearSelection();
						}
						grid.select(row);
					}else{
						grid.select(row, null, null);
					}
					if(event.shiftKey && mode != "single"){
						grid.select(lastRow, row);
					}else{
						lastRow = row;
					}
					if(event.type == "mousedown" && (event.shiftKey || event.ctrlKey)){
						// prevent selection in firefox
						event.preventDefault();
					}
				}
				
			});
		}
	},
	// selection:
	// 		An object where the property names correspond to 
	// 		object ids and values are true or false depending on whether an item is selected
	selection: {},
	// selectionMode: String
	// 		The selection mode to use, can be "multiple", "single", or "extended".
	selectionMode: "extended",
	select: function(row, toRow, value){
		if(value === undefined){
			// default to true
			value = true;
		} 
		if(!row.element){
			row = this.row(row);
		}
		var selection = this.selection;
		var previousValue = selection[row.id];
		if(value === null){
			// indicates a toggle
			value = !previousValue;
		}
		var element = row.element;
		if(value != previousValue &&
			(!element || listen.emit(element, value ? "select" : "deselect", {
			cancelable: true,
			bubbles: true,
			row: row
		}))){
			selection[row.id] = value;
			if(!value && !this.allSelected){
				delete this.selection[row.id];
			}
		}
		if(element){
			if(value){
				put(element, ".dgrid-selected.ui-state-active");
			}else{
				put(element, "!dgrid-selected!ui-state-active");
			}
		}
		if(toRow){
			if(!toRow.element){
				toRow = this.row(toRow);
			}
			var toElement = toRow.element;
			var fromElement = row.element;
			// find if it is earlier or later in the DOM
			var traverser = (toElement && (toElement.compareDocumentPosition ? 
				toElement.compareDocumentPosition(fromElement) == 2 :
				toElement.sourceIndex > fromElement.sourceIndex)) ? "nextSibling" : "previousSibling";
			var nextNode;
			while(nextNode = row.element[traverser]){
				// loop through and set everything
				row = this.row(nextNode);
				this.select(row);
				if(nextNode == toElement){
					break;
				}
			}
		}
	},
	deselect: function(row, toRow){
		this.select(row, toRow, false);
	},
	clearSelection: function(){
		this.allSelected = false;
		for(var id in this.selection){
			this.deselect(id);
		}
	},
	selectAll: function(){
		this.allSelected = true;
		this.selection = {}; // we do this to clear out pages from previous sorts
		for(var i in this._rowIdToObject){
			var row = this.row(this._rowIdToObject[i]);
			this.select(row.id);
		}
	},
	renderArray: function(){
		var rows = this.inherited(arguments);
		var selection = this.selection;
		for(var i = 0; i < rows.length; i++){
			var row = this.row(rows[i]);
			var selected = row.id in selection ? selection[row.id] : this.allSelected;
			if(selected){
				this.select(row, null, selected);
			}
		}
		return rows;
	}
});

});<commit_msg>Use more robust up/down traversal method from Grid to do selection<commit_after>define(["dojo/_base/declare", "dojo/on", "./List", "xstyle/put"], function(declare, listen, List, put){
return declare([List], {
	// summary:
	// 		Add selection capabilities to a grid. The grid will have a selection property and
	//		fire "select" and "deselect" events.
	
	create: function(){
		this.selection = {};
		return this.inherited(arguments);
	},
	postCreate: function(){
		this.inherited(arguments);
		var lastRow, mode = this.selectionMode;
		var grid = this;		
		if(this.selectionMode != "none"){
			// listen for actions that should cause selections
			listen(this.contentNode, "mousedown,cellfocusin", function(event){
				if(event.type == "mousedown" || !event.ctrlKey || event.keyCode == 32){
					var row = event.target;
					if(mode == "single" && lastRow && event.ctrlKey){
						grid.deselect(lastRow);
						if(lastRow == row){
							return;
						}
					}
					if(!event.ctrlKey){
						if(mode != "multiple"){
							grid.clearSelection();
						}
						grid.select(row);
					}else{
						grid.select(row, null, null);
					}
					if(event.shiftKey && mode != "single"){
						grid.select(lastRow, row);
					}else{
						lastRow = row;
					}
					if(event.type == "mousedown" && (event.shiftKey || event.ctrlKey)){
						// prevent selection in firefox
						event.preventDefault();
					}
				}
				
			});
		}
	},
	// selection:
	// 		An object where the property names correspond to 
	// 		object ids and values are true or false depending on whether an item is selected
	selection: {},
	// selectionMode: String
	// 		The selection mode to use, can be "multiple", "single", or "extended".
	selectionMode: "extended",
	select: function(row, toRow, value){
		if(value === undefined){
			// default to true
			value = true;
		} 
		if(!row.element){
			row = this.row(row);
		}
		var selection = this.selection;
		var previousValue = selection[row.id];
		if(value === null){
			// indicates a toggle
			value = !previousValue;
		}
		var element = row.element;
		if(value != previousValue &&
			(!element || listen.emit(element, value ? "select" : "deselect", {
			cancelable: true,
			bubbles: true,
			row: row
		}))){
			selection[row.id] = value;
			if(!value && !this.allSelected){
				delete this.selection[row.id];
			}
		}
		if(element){
			if(value){
				put(element, ".dgrid-selected.ui-state-active");
			}else{
				put(element, "!dgrid-selected!ui-state-active");
			}
		}
		if(toRow){
			if(!toRow.element){
				toRow = this.row(toRow);
			}
			var toElement = toRow.element;
			var fromElement = row.element;
			// find if it is earlier or later in the DOM
			var traverser = (toElement && (toElement.compareDocumentPosition ? 
				toElement.compareDocumentPosition(fromElement) == 2 :
				toElement.sourceIndex > fromElement.sourceIndex)) ? "down" : "up";
			while(row = this[traverser](row)){
				this.select(row);
				if(row.element == toElement){
					break;
				}
			}
		}
	},
	deselect: function(row, toRow){
		this.select(row, toRow, false);
	},
	clearSelection: function(){
		this.allSelected = false;
		for(var id in this.selection){
			this.deselect(id);
		}
	},
	selectAll: function(){
		this.allSelected = true;
		this.selection = {}; // we do this to clear out pages from previous sorts
		for(var i in this._rowIdToObject){
			var row = this.row(this._rowIdToObject[i]);
			this.select(row.id);
		}
	},
	renderArray: function(){
		var rows = this.inherited(arguments);
		var selection = this.selection;
		for(var i = 0; i < rows.length; i++){
			var row = this.row(rows[i]);
			var selected = row.id in selection ? selection[row.id] : this.allSelected;
			if(selected){
				this.select(row, null, selected);
			}
		}
		return rows;
	}
});

});
{'fraction_non_alphanumeric': 0.1525022986995928, 'fraction_numerical': 0.0010508340995665309, 'mean_word_length': 3.047846889952153, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3769971', 'n_tokens_mistral': 3056, 'n_tokens_neox': 2485, 'n_words': 617}