<commit_before>
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'

import Track from './Track'
import ContextMenuTrigger from './ContextMenuTrigger'

import * as helpers from '../helpers'
import * as mopidyActions from '../services/mopidy/actions'
import * as uiActions from '../services/ui/actions'

class TrackList extends React.Component{

	constructor(props) {
		super(props)

		this.touch_dragging_tracks_keys = false

		this.handleKeyUp = this.handleKeyUp.bind(this)
		this.handleTouchMove = this.handleTouchMove.bind(this)
		this.handleTouchEnd = this.handleTouchEnd.bind(this)
	}

	componentWillMount(){
		window.addEventListener("keyup", this.handleKeyUp, false)
		window.addEventListener("touchmove", this.handleTouchMove, false)
		window.addEventListener("touchend", this.handleTouchEnd, false)
	}

	componentWillUnmount(){
		window.removeEventListener("keyup", this.handleKeyUp, false)
		window.removeEventListener("touchmove", this.handleTouchMove, false)
		window.removeEventListener("touchend", this.handleTouchEnd, false)
	}

	handleKeyUp(e){

		// When we're focussed on certian elements (like form input fields), don't fire any shortcuts
		var ignoreNodes = ['INPUT', 'TEXTAREA']
		if (ignoreNodes.indexOf(e.target.nodeName) > -1){
			return false
		}

		// No tracks selected - no action required
		if (!this.digestTracksKeys() || this.digestTracksKeys().length <= 0){
			return
		}

		switch(e.keyCode){			
			case 13: // enter
				 this.playTracks();
				break;
			
			case 46: // delete
				 this.removeTracks();
				break;
		}
	}

	handleDrag(e,track_key){

		let selected_tracks = []

		// Dragging a non-selected track. We need to deselect everything
		// else and select only this track
		if (!this.props.selected_tracks.includes(track_key)){
			this.props.uiActions.setSelectedTracks([track_key])
			selected_tracks = this.digestTracksKeys([track_key])
		} else {
			selected_tracks = this.digestTracksKeys()
		}

		let selected_tracks_indexes = helpers.arrayOf('index',selected_tracks)
<commit_msg>Selecting tracks ctrl + a; tracklist shortcuts now keydown vs keyup; addresses #168<commit_after>
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'

import Track from './Track'
import ContextMenuTrigger from './ContextMenuTrigger'

import * as helpers from '../helpers'
import * as mopidyActions from '../services/mopidy/actions'
import * as uiActions from '../services/ui/actions'

class TrackList extends React.Component{

	constructor(props) {
		super(props)

		this.touch_dragging_tracks_keys = false

		this.handleKeyDown = this.handleKeyDown.bind(this)
		this.handleTouchMove = this.handleTouchMove.bind(this)
		this.handleTouchEnd = this.handleTouchEnd.bind(this)
	}

	componentWillMount(){
		window.addEventListener("keydown", this.handleKeyDown, false)
		window.addEventListener("touchmove", this.handleTouchMove, false)
		window.addEventListener("touchend", this.handleTouchEnd, false)
	}

	componentWillUnmount(){
		window.removeEventListener("keydown", this.handleKeyDown, false)
		window.removeEventListener("touchmove", this.handleTouchMove, false)
		window.removeEventListener("touchend", this.handleTouchEnd, false)
	}

	handleKeyDown(e){

		// When we're focussed on certian elements (like form input fields), don't fire any shortcuts
		var ignoreNodes = ['INPUT', 'TEXTAREA']
		if (ignoreNodes.indexOf(e.target.nodeName) > -1){
			return false
		}

		var tracks_keys = this.digestTracksKeys()

		switch(e.keyCode){			
			case 13: // enter
				if (tracks_keys && tracks_keys.length > 0){
					this.playTracks();
				}
				break;
			
			case 46: // delete
				if (tracks_keys && tracks_keys.length > 0){
					this.removeTracks();
				}
				break;
			
			case 65: // a
				if (e.ctrlKey){

					e.preventDefault();

					// Select all our tracks
					var all_tracks = []
					for (var i = 0; i < this.props.tracks.length; i++){
						all_tracks.push(this.buildTrackKey(this.props.tracks[i], i))
					}
					this.props.uiActions.setSelectedTracks(all_tracks)

					return false
				}
				break;
		}
	}

	handleDrag(e,track_key){

		let selected_tracks = []

		// Dragging a non-selected track. We need to deselect everything
		// else and select only this track
		if (!this.props.selected_tracks.includes(track_key)){
			this.props.uiActions.setSelectedTracks([track_key])
			selected_tracks = this.digestTracksKeys([track_key])
		} else {
			selected_tracks = this.digestTracksKeys()
		}

		let selected_tracks_indexes = helpers.arrayOf('index',selected_tracks)

{'fraction_non_alphanumeric': 0.11784582893347413, 'fraction_numerical': 0.004012671594508976, 'mean_word_length': 4.175956284153005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2622223', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1451, 'n_words': 336}