import { __exports as state } from '../../../../_virtual/state.js';
import { __require as requireCommands } from './commands.js';

var hasRequiredState;

function requireState () {
	if (hasRequiredState) return state;
	hasRequiredState = 1;
	(function (exports$1) {
		Object.defineProperty(exports$1, "__esModule", { value: true });
		exports$1.State = exports$1.EAT_UP_KEY = void 0;
		var commands_1 = requireCommands();
		exports$1.EAT_UP_KEY = '==-==';
		var State = (function () {
		    function State() {
		        this._inargumentMode = false;
		        this._killRing = [];
		    }
		    State.prototype.updateAndGetKey = function (key) {
		        if (key === 'C-g' && (this._inargumentMode || this._prefixKey)) {
		            this.resetState();
		            return exports$1.EAT_UP_KEY;
		        }
		        if (this.updateCuMode(key)) {
		            return exports$1.EAT_UP_KEY;
		        }
		        if (!this._prefixKey) {
		            if (commands_1.prefixPreservingKeys[key]) {
		                this._prefixKey = key;
		                return exports$1.EAT_UP_KEY;
		            }
		            return key;
		        }
		        else {
		            return "".concat(this._prefixKey, " ").concat(key);
		        }
		    };
		    State.prototype.setLastCommandKey = function (lastCommandKey) {
		        this._lastCommandKey = lastCommandKey;
		    };
		    State.prototype.isLastCommandKey = function (lastCommandKey) {
		        return this._lastCommandKey == lastCommandKey;
		    };
		    State.prototype.resetState = function (setLastInput) {
		        if (setLastInput === void 0) { setLastInput = false; }
		        this._inargumentMode = setLastInput;
		        this._prefixKey = null;
		        if (setLastInput) {
		            this._lastInputBuffer = this._inputBuffer;
		        }
		        else {
		            this._lastInputBuffer = null;
		        }
		        this._inputBuffer = null;
		    };
		    State.prototype.updateCuMode = function (key) {
		        if (this._inargumentMode) {
		            if (typeof key === 'string' && (/^\d$/.test(key))) {
		                this._inputBuffer = (this._inputBuffer || '') + key;
		                return true;
		            }
		            else if (commands_1.prefixPreservingKeys[key]) {
		                this.resetState(true);
		                return false;
		            }
		        }
		        else if (!this._prefixKey && key === 'C-u') {
		            this._inargumentMode = true;
		            this._inputBuffer = null;
		            this._lastInputBuffer = null;
		            return true;
		        }
		    };
		    State.prototype.updateStateOnExecution = function (reset) {
		        if (reset === void 0) { reset = false; }
		        this.resetState(reset);
		    };
		    State.prototype.getInputBuffer = function () {
		        return this._lastInputBuffer || this._inputBuffer;
		    };
		    State.prototype.addToRing = function (str) {
		        this._killRing.push(str);
		        if (this._killRing.length > 50)
		            this._killRing.shift();
		    };
		    State.prototype.growRingTop = function (str) {
		        if (!this._killRing.length) {
		            this.addToRing(str);
		        }
		        this._killRing[this._killRing.length - 1] += str;
		    };
		    State.prototype.getFromRing = function (n) {
		        return this._killRing[this._killRing.length - (n ? Math.min(n, 1) : 1)] || '';
		    };
		    State.prototype.popFromRing = function () {
		        if (this._killRing.length > 1) {
		            return this._killRing.pop();
		        }
		        return this.getFromRing();
		    };
		    State.prototype.getReadableState = function () {
		        var str = '';
		        if (this._inargumentMode) {
		            str += 'C-u';
		            if (this._inputBuffer) {
		                str += " ".concat(this._inputBuffer);
		            }
		            else if (this._lastInputBuffer) {
		                str += " ".concat(this._lastInputBuffer);
		            }
		        }
		        if (this._prefixKey) {
		            str += " ".concat(this._prefixKey);
		        }
		        return str;
		    };
		    return State;
		}());
		exports$1.State = State; 
	} (state));
	return state;
}

export { requireState as __require };
