<commit_before>/**
 * enyo.Spotlight.Accelerator definition
 * @author: <NAME>
 */

enyo.Spotlight.Accelerator = new function() {

	//* @protected
	/*************************************************************/

	var _nSkipped = 0,
		_nTime    = 0,
		_nKey     = 0;

	//* @public
	/*************************************************************/

	//* Firing configuration. At n-th second use every frequency[n] subsequent keydown event
	this.frequency = [3, 3, 3, 2, 2, 2, 1];

	//* Called from enyo.Spotlight, with current keydown event and Spotlight's callback
	//* Which will be called when an event is allowed through
	this.processKey = function(oEvent, fCallback, oContext) {
		switch (oEvent.type) {
			case 'keydown':
			case 'pagehold':
			case 'pageholdpulse':
				if (oEvent.keyCode != _nKey) {
					this.reset();
					_nTime = (new Date()).getTime();
					_nKey  = oEvent.keyCode;
					return fCallback.apply(oContext, [oEvent]);
				} else {
					var nElapsedTime = (new Date()).getTime() - _nTime,
						nSeconds     = Math.floor(nElapsedTime / 1000),
						nToSkip      = 0;

					nSeconds = nSeconds > this.frequency.length - 1
						? this.frequency.length - 1
						: nSeconds;

					nToSkip = this.frequency[nSeconds] - 1;
					if (nToSkip < 0) { nToSkip = 0; }

					if (_nSkipped >= nToSkip) {
						_nSkipped = 0;
						return fCallback.apply(oContext, [oEvent]);
					} else {
						_nSkipped ++;
						oEvent.preventDefault(); // Prevent skipped keydown events from bubbling
						return true;
					}
				}
				break;
			case 'keyup':
			case 'pagerelease':
				this.reset();
				return fCallback.apply(oContext, [oEvent]);
		}
	};

	this.reset = function() {
		_nSkipped = 0;
		_nTime    = 0;
		_nKey     = 0;
	};
};<commit_msg>GF-61059: Add cancel API, to cancel key acceleration until next keyup. DCO-1.1-Signed-Off-By: <NAME> <<EMAIL>><commit_after>/**
 * enyo.Spotlight.Accelerator definition
 * @author: <NAME>
 */

enyo.Spotlight.Accelerator = new function() {

	//* @protected
	/*************************************************************/

	var _nSkipped = 0,
		_nTime    = 0,
		_nKey     = 0,
		_bCanceled = false;

	//* @public
	/*************************************************************/

	//* Firing configuration. At n-th second use every frequency[n] subsequent keydown event
	this.frequency = [3, 3, 3, 2, 2, 2, 1];

	//* Called from enyo.Spotlight, with current keydown event and Spotlight's callback
	//* Which will be called when an event is allowed through
	this.processKey = function(oEvent, fCallback, oContext) {
		switch (oEvent.type) {
			case 'keydown':
			case 'pagehold':
			case 'pageholdpulse':
				if (oEvent.keyCode != _nKey) {
					this.reset();
					_nTime = (new Date()).getTime();
					_nKey  = oEvent.keyCode;
					return fCallback.apply(oContext, [oEvent]);
				} else if (_bCanceled) {
					oEvent.preventDefault(); // Prevent skipped keydown events from bubbling
					return true;
				} else {
					var nElapsedTime = (new Date()).getTime() - _nTime,
						nSeconds     = Math.floor(nElapsedTime / 1000),
						nToSkip      = 0;

					nSeconds = nSeconds > this.frequency.length - 1
						? this.frequency.length - 1
						: nSeconds;

					nToSkip = this.frequency[nSeconds] - 1;
					if (nToSkip < 0) { nToSkip = 0; }

					if (_nSkipped >= nToSkip) {
						_nSkipped = 0;
						return fCallback.apply(oContext, [oEvent]);
					} else {
						_nSkipped ++;
						oEvent.preventDefault(); // Prevent skipped keydown events from bubbling
						return true;
					}
				}
				break;
			case 'keyup':
			case 'pagerelease':
				this.reset();
				return fCallback.apply(oContext, [oEvent]);
		}
	};
	
	this.reset = function() {
		_nSkipped = 0;
		_nTime    = 0;
		_nKey     = 0;
		_bCanceled = false;
	};

	this.cancel = function() {
		_bCanceled = true;
	};
};
{'fraction_non_alphanumeric': 0.19127253723543244, 'fraction_numerical': 0.01437157042069506, 'mean_word_length': 2.812749003984064, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '1051290', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1272, 'n_words': 317}