<commit_before>import { TextField } from "Ember";
import Menu from "nwjs/Menu";
import {
	get as getClipboard,
	set as setClipboard
} from "nwjs/Clipboard";


export default TextField.extend({
	attributeBindings: [ "autoselect:data-selectable" ],

	autoselect: false,

	contextMenu( event ) {
		if ( this.attrs.noContextmenu ) { return; }

		var element = this.element;
		var start   = element.selectionStart;
		var end     = element.selectionEnd;

		var clip    = getClipboard();

		var menu = Menu.create();

		menu.items.pushObjects([
			{
				label  : "Copy",
				enabled: start !== end,
				click() {
					var selected = element.value.substr( start, end - start );
					setClipboard( selected );
				}
			},
			{
				label  : "Paste",
				enabled: !element.readOnly && !element.disabled && clip && clip.length,
				click() {
					var value  = element.value;
					var before = value.substr( 0, element.selectionStart );
					var after  = value.substr( element.selectionEnd );

					element.value = before + clip + after;
					element.selectionStart = element.selectionEnd = before.length + clip.length;
				}
			}
		]);

		menu.popup( event );
	},

	focusIn() {
		if ( !this.attrs.autofocus || !this.attrs.autoselect ) { return; }

		this.element.setSelectionRange( 0, this.element.value.length );
	}
});<commit_msg>Fix escape hotkey on text input elements<commit_after>import { TextField } from "Ember";
import Menu from "nwjs/Menu";
import {
	get as getClipboard,
	set as setClipboard
} from "nwjs/Clipboard";


export default TextField.extend({
	attributeBindings: [ "autoselect:data-selectable" ],

	autoselect: false,

	contextMenu( event ) {
		if ( this.attrs.noContextmenu ) { return; }

		var element = this.element;
		var start   = element.selectionStart;
		var end     = element.selectionEnd;

		var clip    = getClipboard();

		var menu = Menu.create();

		menu.items.pushObjects([
			{
				label  : "Copy",
				enabled: start !== end,
				click() {
					var selected = element.value.substr( start, end - start );
					setClipboard( selected );
				}
			},
			{
				label  : "Paste",
				enabled: !element.readOnly && !element.disabled && clip && clip.length,
				click() {
					var value  = element.value;
					var before = value.substr( 0, element.selectionStart );
					var after  = value.substr( element.selectionEnd );

					element.value = before + clip + after;
					element.selectionStart = element.selectionEnd = before.length + clip.length;
				}
			}
		]);

		menu.popup( event );
	},

	focusIn() {
		if ( !this.attrs.autofocus || !this.attrs.autoselect ) { return; }

		this.element.setSelectionRange( 0, this.element.value.length );
	},

	keyDown( event ) {
		if ( event.originalEvent.code === "Escape" ) {
			this.$().trigger( "blur" );
			return;
		}

		return this._super( ...arguments );
	}
});
{'fraction_non_alphanumeric': 0.14012738853503184, 'fraction_numerical': 0.0014154281670205238, 'mean_word_length': 3.015625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3861570', 'n_tokens_mistral': 1080, 'n_tokens_neox': 897, 'n_words': 211}