import { commonjsGlobal } from '../../../../_virtual/_commonjsHelpers.js';
import { __exports as actions } from '../../../../_virtual/actions.js';
import require$$0 from '../../../../_virtual/_monaco-editor.js';

(function (exports) {
	var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
	    var extendStatics = function (d, b) {
	        extendStatics = Object.setPrototypeOf ||
	            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
	            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
	        return extendStatics(d, b);
	    };
	    return function (d, b) {
	        if (typeof b !== "function" && b !== null)
	            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
	        extendStatics(d, b);
	        function __() { this.constructor = d; }
	        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
	    };
	})();
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.DeleteLines = exports.SearchReplace = exports.Search = exports.InvertSelection = exports.GotoLine = exports.RotateCursorOnScreen = exports.InsertTabs = exports.RevealToBottomAction = exports.RevealToCenterAction = exports.RevealToTopAction = exports.RevealEditorAction = exports.YankRotate = exports.YankSelectionToRing = exports.Yank = exports.RedoAction = exports.UndoAction = exports.KeyBoardQuit = exports.MoveCursorTop = exports.MoveCursorBottom = exports.MoveCursorWordLeft = exports.MoveCursorWordRight = exports.MoveCursorToLineStart = exports.MoveCursorToLineEnd = exports.MoveCursorRight = exports.MoveCursorLeft = exports.MoveCursorDown = exports.MoveCursorUp = exports.SetMark = exports.InsertLineAfter = exports.InsertLineBelow = exports.KillLines = exports.KillSelection = exports.BaseAction = exports.SOURCE = void 0;
	var monaco = require$$0;
	exports.SOURCE = 'extension.emacs';
	function moveCursor(editor, hasSelection, direction, unit, repeat) {
	    if (repeat === void 0) { repeat = 1; }
	    var action = "cursor".concat(unit === 'word' ? 'Word' : '').concat(direction).concat(hasSelection ? 'Select' : '');
	    for (var i = 0; i < repeat; i++) {
	        editor.trigger(exports.SOURCE, action, null);
	    }
	}
	var BaseAction = (function () {
	    function BaseAction() {
	        this.description = '';
	    }
	    return BaseAction;
	}());
	exports.BaseAction = BaseAction;
	var TriggerAction = (function (_super) {
	    __extends(TriggerAction, _super);
	    function TriggerAction(trigger) {
	        var _this = _super.call(this) || this;
	        _this.trigger = trigger;
	        return _this;
	    }
	    TriggerAction.prototype.run = function (editor) {
	        editor.trigger(exports.SOURCE, this.trigger, {});
	    };
	    return TriggerAction;
	}(BaseAction));
	var KillSelection = (function (_super) {
	    __extends(KillSelection, _super);
	    function KillSelection() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    KillSelection.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var selections = editor.getSelections();
	        if (!selections.length) {
	            return;
	        }
	        selections.forEach(function (sel) {
	            var text = editor.getModel().getValueInRange(sel);
	            ext.state.addToRing(text);
	            editor.executeEdits(exports.SOURCE, [{
	                    range: sel,
	                    text: '',
	                }]);
	        });
	    };
	    return KillSelection;
	}(BaseAction));
	exports.KillSelection = KillSelection;
	var KillLines = (function (_super) {
	    __extends(KillLines, _super);
	    function KillLines() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    KillLines.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        ext.selectionMode = false;
	        var model = editor.getModel();
	        var pos = ext.getCursorAnchor();
	        var endPos;
	        if (repeat === 1) {
	            var lineLength = model.getLineLength(pos.lineNumber);
	            var isAtEnd = pos.column === lineLength + 1;
	            if (!lineLength || isAtEnd) {
	                if (repeatedTrigger) {
	                    ext.state.growRingTop(model.getEOL());
	                }
	                else {
	                    ext.state.addToRing(model.getEOL());
	                }
	                editor.trigger(exports.SOURCE, 'deleteAllRight', null);
	                return;
	            }
	            else {
	                endPos = new monaco.Position(pos.lineNumber, model.getLineLength(pos.lineNumber) + 1);
	            }
	        }
	        else {
	            var totalLines = model.getLineCount();
	            var endLine = (pos.lineNumber + repeat) > totalLines ? totalLines : (pos.lineNumber + repeat);
	            endPos = new monaco.Position(endLine, model.getLineLength(endLine) + 1);
	        }
	        var range = monaco.Range.fromPositions(pos, endPos);
	        if (repeatedTrigger) {
	            ext.state.growRingTop(model.getValueInRange(range));
	        }
	        else {
	            ext.state.addToRing(model.getValueInRange(range));
	        }
	        editor.executeEdits(exports.SOURCE, [{
	                range: range,
	                text: '',
	            }]);
	        editor.setSelection(monaco.Selection.fromPositions(pos, pos));
	    };
	    return KillLines;
	}(BaseAction));
	exports.KillLines = KillLines;
	var InsertLineBelow = (function (_super) {
	    __extends(InsertLineBelow, _super);
	    function InsertLineBelow() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    InsertLineBelow.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var pos = editor.getPosition();
	        editor.trigger(exports.SOURCE, 'editor.action.insertLineAfter', null);
	        editor.setPosition(pos);
	    };
	    return InsertLineBelow;
	}(BaseAction));
	exports.InsertLineBelow = InsertLineBelow;
	var InsertLineAfter = (function (_super) {
	    __extends(InsertLineAfter, _super);
	    function InsertLineAfter() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    InsertLineAfter.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var text = '';
	        for (var i = 0; i < repeat; i++) {
	            text += editor.getModel().getEOL();
	        }
	        ext.selectionMode = false;
	        var pos = ext.getCursorAnchor();
	        editor.executeEdits(exports.SOURCE, [{
	                range: monaco.Range.fromPositions(pos),
	                text: text,
	                forceMoveMarkers: true,
	            }]);
	    };
	    return InsertLineAfter;
	}(BaseAction));
	exports.InsertLineAfter = InsertLineAfter;
	var SetMark = (function (_super) {
	    __extends(SetMark, _super);
	    function SetMark() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    SetMark.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        ext.selectionMode;
	        var sel = editor.getSelection();
	        var selEmpty = sel.isEmpty();
	        if (!selEmpty) {
	            var dir = sel.getDirection();
	            if (dir === monaco.SelectionDirection.LTR) {
	                editor.setSelection(monaco.Selection.fromPositions(sel.getEndPosition(), sel.getEndPosition()));
	            }
	            else {
	                editor.setSelection(monaco.Selection.fromPositions(sel.getStartPosition(), sel.getStartPosition()));
	            }
	        }
	        if (selEmpty && ext.selectionMode) {
	            ext.selectionMode = false;
	        }
	        else {
	            ext.selectionMode = true;
	        }
	    };
	    return SetMark;
	}(BaseAction));
	exports.SetMark = SetMark;
	var MoveCursorAction = (function (_super) {
	    __extends(MoveCursorAction, _super);
	    function MoveCursorAction() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.unit = 'char';
	        return _this;
	    }
	    MoveCursorAction.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        moveCursor(editor, ext.selectionMode, this.direction, this.unit, repeat);
	    };
	    return MoveCursorAction;
	}(BaseAction));
	var MoveCursorUp = (function (_super) {
	    __extends(MoveCursorUp, _super);
	    function MoveCursorUp() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.direction = 'Up';
	        return _this;
	    }
	    return MoveCursorUp;
	}(MoveCursorAction));
	exports.MoveCursorUp = MoveCursorUp;
	var MoveCursorDown = (function (_super) {
	    __extends(MoveCursorDown, _super);
	    function MoveCursorDown() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.direction = 'Down';
	        return _this;
	    }
	    return MoveCursorDown;
	}(MoveCursorAction));
	exports.MoveCursorDown = MoveCursorDown;
	var MoveCursorLeft = (function (_super) {
	    __extends(MoveCursorLeft, _super);
	    function MoveCursorLeft() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.direction = 'Left';
	        return _this;
	    }
	    return MoveCursorLeft;
	}(MoveCursorAction));
	exports.MoveCursorLeft = MoveCursorLeft;
	var MoveCursorRight = (function (_super) {
	    __extends(MoveCursorRight, _super);
	    function MoveCursorRight() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.direction = 'Right';
	        return _this;
	    }
	    return MoveCursorRight;
	}(MoveCursorAction));
	exports.MoveCursorRight = MoveCursorRight;
	var MoveCursorToLineEnd = (function (_super) {
	    __extends(MoveCursorToLineEnd, _super);
	    function MoveCursorToLineEnd() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.direction = 'End';
	        return _this;
	    }
	    return MoveCursorToLineEnd;
	}(MoveCursorAction));
	exports.MoveCursorToLineEnd = MoveCursorToLineEnd;
	var MoveCursorToLineStart = (function (_super) {
	    __extends(MoveCursorToLineStart, _super);
	    function MoveCursorToLineStart() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.direction = 'Home';
	        return _this;
	    }
	    return MoveCursorToLineStart;
	}(MoveCursorAction));
	exports.MoveCursorToLineStart = MoveCursorToLineStart;
	var MoveCursorWordRight = (function (_super) {
	    __extends(MoveCursorWordRight, _super);
	    function MoveCursorWordRight() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.unit = 'word';
	        return _this;
	    }
	    return MoveCursorWordRight;
	}(MoveCursorRight));
	exports.MoveCursorWordRight = MoveCursorWordRight;
	var MoveCursorWordLeft = (function (_super) {
	    __extends(MoveCursorWordLeft, _super);
	    function MoveCursorWordLeft() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.unit = 'word';
	        return _this;
	    }
	    return MoveCursorWordLeft;
	}(MoveCursorLeft));
	exports.MoveCursorWordLeft = MoveCursorWordLeft;
	var MoveCursorBottom = (function (_super) {
	    __extends(MoveCursorBottom, _super);
	    function MoveCursorBottom() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.direction = 'Bottom';
	        return _this;
	    }
	    return MoveCursorBottom;
	}(MoveCursorAction));
	exports.MoveCursorBottom = MoveCursorBottom;
	var MoveCursorTop = (function (_super) {
	    __extends(MoveCursorTop, _super);
	    function MoveCursorTop() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.direction = 'Top';
	        return _this;
	    }
	    return MoveCursorTop;
	}(MoveCursorAction));
	exports.MoveCursorTop = MoveCursorTop;
	var KeyBoardQuit = (function (_super) {
	    __extends(KeyBoardQuit, _super);
	    function KeyBoardQuit() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    KeyBoardQuit.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        ext.selectionMode = false;
	        ext.clearState();
	        editor.setPosition(editor.getPosition());
	    };
	    return KeyBoardQuit;
	}(BaseAction));
	exports.KeyBoardQuit = KeyBoardQuit;
	var HistoryAction = (function (_super) {
	    __extends(HistoryAction, _super);
	    function HistoryAction() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    HistoryAction.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        for (var i = 0; i < repeat; i++) {
	            editor.trigger(exports.SOURCE, this.action, null);
	        }
	    };
	    return HistoryAction;
	}(BaseAction));
	var UndoAction = (function (_super) {
	    __extends(UndoAction, _super);
	    function UndoAction() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.action = 'undo';
	        return _this;
	    }
	    return UndoAction;
	}(HistoryAction));
	exports.UndoAction = UndoAction;
	var RedoAction = (function (_super) {
	    __extends(RedoAction, _super);
	    function RedoAction() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.action = 'redo';
	        return _this;
	    }
	    return RedoAction;
	}(HistoryAction));
	exports.RedoAction = RedoAction;
	var Yank = (function (_super) {
	    __extends(Yank, _super);
	    function Yank() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    Yank.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var text = ext.state.getFromRing(repeat);
	        if (!text) {
	            return;
	        }
	        var pos = editor.getPosition();
	        editor.executeEdits(exports.SOURCE, [{
	                range: monaco.Range.fromPositions(pos, pos),
	                text: text,
	                forceMoveMarkers: true,
	            }]);
	    };
	    return Yank;
	}(BaseAction));
	exports.Yank = Yank;
	var YankSelectionToRing = (function (_super) {
	    __extends(YankSelectionToRing, _super);
	    function YankSelectionToRing() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    YankSelectionToRing.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var sel = editor.getSelection();
	        if (sel.isEmpty()) {
	            return;
	        }
	        ext.state.addToRing(editor.getModel().getValueInRange(sel));
	        ext.selectionMode = false;
	        var pos = ext.getCursorAnchor();
	        editor.setSelection(monaco.Selection.fromPositions(pos, pos));
	    };
	    return YankSelectionToRing;
	}(BaseAction));
	exports.YankSelectionToRing = YankSelectionToRing;
	var YankRotate = (function (_super) {
	    __extends(YankRotate, _super);
	    function YankRotate() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    YankRotate.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var text = ext.state.popFromRing();
	        if (!text) {
	            return;
	        }
	        var pos = ext.getCursorAnchor();
	        editor.executeEdits(exports.SOURCE, [{
	                range: monaco.Range.fromPositions(pos),
	                text: text,
	                forceMoveMarkers: true,
	            }]);
	    };
	    return YankRotate;
	}(BaseAction));
	exports.YankRotate = YankRotate;
	var RevealEditorAction = (function (_super) {
	    __extends(RevealEditorAction, _super);
	    function RevealEditorAction() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    RevealEditorAction.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var sel = editor.getSelection();
	        if (this.revealFunction === 'up') {
	            editor.trigger(exports.SOURCE, 'scrollPageUp', null);
	        }
	        else {
	            editor[this.revealFunction](sel);
	        }
	    };
	    return RevealEditorAction;
	}(BaseAction));
	exports.RevealEditorAction = RevealEditorAction;
	var RevealToTopAction = (function (_super) {
	    __extends(RevealToTopAction, _super);
	    function RevealToTopAction() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.revealFunction = 'revealRangeAtTop';
	        return _this;
	    }
	    return RevealToTopAction;
	}(RevealEditorAction));
	exports.RevealToTopAction = RevealToTopAction;
	var RevealToCenterAction = (function (_super) {
	    __extends(RevealToCenterAction, _super);
	    function RevealToCenterAction() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.revealFunction = 'revealRangeInCenter';
	        return _this;
	    }
	    return RevealToCenterAction;
	}(RevealEditorAction));
	exports.RevealToCenterAction = RevealToCenterAction;
	var RevealToBottomAction = (function (_super) {
	    __extends(RevealToBottomAction, _super);
	    function RevealToBottomAction() {
	        var _this = _super !== null && _super.apply(this, arguments) || this;
	        _this.revealFunction = 'up';
	        return _this;
	    }
	    return RevealToBottomAction;
	}(RevealEditorAction));
	exports.RevealToBottomAction = RevealToBottomAction;
	var InsertTabs = (function (_super) {
	    __extends(InsertTabs, _super);
	    function InsertTabs() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    InsertTabs.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var model = editor.getModel();
	        var _a = model.getOptions(), tabSize = _a.tabSize, insertSpaces = _a.insertSpaces;
	        var text = '';
	        for (var i = 0; i < repeat; i++) {
	            var spaces = '';
	            for (var j = 0; j < tabSize; j++) {
	                spaces += ' ';
	            }
	            text += (insertSpaces ? spaces : '\t');
	        }
	        editor.executeEdits(exports.SOURCE, [{
	                range: editor.getSelection(),
	                text: text,
	                forceMoveMarkers: true,
	            }]);
	    };
	    return InsertTabs;
	}(BaseAction));
	exports.InsertTabs = InsertTabs;
	var RotateCursorOnScreen = (function (_super) {
	    __extends(RotateCursorOnScreen, _super);
	    function RotateCursorOnScreen() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    RotateCursorOnScreen.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var ranges = editor.getVisibleRanges();
	        if (!ranges.length) {
	            return;
	        }
	        var lineMapping = [];
	        for (var i = 0; i < ranges.length; i++) {
	            var range = ranges[i];
	            for (var j = range.startLineNumber; j <= range.endLineNumber; j++) {
	                lineMapping.push(j);
	            }
	        }
	        var pos = editor.getPosition();
	        var expectedCenter = Math.ceil(lineMapping.length / 2);
	        var toMovePos;
	        if (pos.lineNumber === lineMapping[expectedCenter]) {
	            toMovePos = new monaco.Position(lineMapping[0], 1);
	        }
	        else if (pos.lineNumber === lineMapping[0]) {
	            toMovePos = new monaco.Position(lineMapping[lineMapping.length - 1], 1);
	        }
	        else {
	            toMovePos = new monaco.Position(lineMapping[expectedCenter], 1);
	        }
	        editor.setPosition(toMovePos);
	    };
	    return RotateCursorOnScreen;
	}(BaseAction));
	exports.RotateCursorOnScreen = RotateCursorOnScreen;
	var GotoLine = (function (_super) {
	    __extends(GotoLine, _super);
	    function GotoLine() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    GotoLine.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        ext.getBasicInput('Goto Line: ').then(function (val) {
	            var line = parseInt(val) || 0;
	            var model = editor.getModel();
	            var totalLines = model.getLineCount();
	            editor.focus();
	            if (!line) {
	                line = 1;
	            }
	            else if (line > totalLines) {
	                line = totalLines;
	            }
	            var pos = new monaco.Position(line, 1);
	            var range;
	            if (!ext.selectionMode) {
	                range = monaco.Selection.fromPositions(pos);
	            }
	            else {
	                var sel = editor.getSelection();
	                if (sel.getDirection() === monaco.SelectionDirection.LTR) {
	                    range = monaco.Selection.fromPositions(sel.getStartPosition(), pos);
	                }
	                else {
	                    range = monaco.Selection.fromPositions(sel.getEndPosition(), pos);
	                }
	            }
	            editor.setSelection(range);
	            editor.revealRangeInCenter(range);
	        }).catch(function () {
	            editor.focus();
	        });
	    };
	    return GotoLine;
	}(BaseAction));
	exports.GotoLine = GotoLine;
	var InvertSelection = (function (_super) {
	    __extends(InvertSelection, _super);
	    function InvertSelection() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    InvertSelection.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        var sel = editor.getSelection();
	        if (sel.isEmpty()) {
	            return;
	        }
	        var newSel;
	        if (sel.getDirection() === monaco.SelectionDirection.LTR) {
	            newSel = monaco.Selection.fromPositions(sel.getEndPosition(), sel.getStartPosition());
	        }
	        else {
	            newSel = monaco.Selection.fromPositions(sel.getStartPosition(), sel.getEndPosition());
	        }
	        editor.setSelection(newSel);
	    };
	    return InvertSelection;
	}(BaseAction));
	exports.InvertSelection = InvertSelection;
	var Search = (function (_super) {
	    __extends(Search, _super);
	    function Search() {
	        return _super.call(this, 'editor.actions.findWithArgs') || this;
	    }
	    return Search;
	}(TriggerAction));
	exports.Search = Search;
	var SearchReplace = (function (_super) {
	    __extends(SearchReplace, _super);
	    function SearchReplace() {
	        return _super.call(this, 'editor.action.startFindReplaceAction') || this;
	    }
	    return SearchReplace;
	}(TriggerAction));
	exports.SearchReplace = SearchReplace;
	var DeleteLines = (function (_super) {
	    __extends(DeleteLines, _super);
	    function DeleteLines() {
	        return _super !== null && _super.apply(this, arguments) || this;
	    }
	    DeleteLines.prototype.run = function (editor, ext, repeat, repeatedTrigger) {
	        ext.selectionMode = false;
	        for (var i = 0; i < repeat; i++) {
	            editor.trigger(exports.SOURCE, 'editor.action.deleteLines', null);
	        }
	    };
	    return DeleteLines;
	}(BaseAction));
	exports.DeleteLines = DeleteLines; 
} (actions));
