"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const editorExtensions = require("../../../browser/editorExtensions.js");
const replaceCommand = require("../../../common/commands/replaceCommand.js");
const editorOptions = require("../../../common/config/editorOptions.js");
const cursorCommon = require("../../../common/cursorCommon.js");
const cursorWordOperations = require("../../../common/cursor/cursorWordOperations.js");
const wordCharacterClassifier = require("../../../common/core/wordCharacterClassifier.js");
const position = require("../../../common/core/position.js");
const range = require("../../../common/core/range.js");
const selection = require("../../../common/core/selection.js");
const editorContextKeys = require("../../../common/editorContextKeys.js");
const languageConfigurationRegistry = require("../../../common/languages/languageConfigurationRegistry.js");
const nls = require("../../../../nls.js");
const accessibility = require("../../../../platform/accessibility/common/accessibility.js");
const contextkey = require("../../../../platform/contextkey/common/contextkey.js");
const contextkeys = require("../../../../platform/contextkey/common/contextkeys.js");
class MoveWordCommand extends editorExtensions.EditorCommand {
  constructor(opts) {
    super(opts);
    this._inSelectionMode = opts.inSelectionMode;
    this._wordNavigationType = opts.wordNavigationType;
  }
  runEditorCommand(accessor, editor, args) {
    if (!editor.hasModel()) {
      return;
    }
    const wordSeparators = wordCharacterClassifier.getMapForWordSeparators(editor.getOption(
      117
      /* wordSeparators */
    ));
    const model = editor.getModel();
    const selections = editor.getSelections();
    const result = selections.map((sel) => {
      const inPosition = new position.Position(sel.positionLineNumber, sel.positionColumn);
      const outPosition = this._move(wordSeparators, model, inPosition, this._wordNavigationType);
      return this._moveTo(sel, outPosition, this._inSelectionMode);
    });
    model.pushStackElement();
    editor._getViewModel().setCursorStates("moveWordCommand", 3, result.map((r) => cursorCommon.CursorState.fromModelSelection(r)));
    if (result.length === 1) {
      const pos = new position.Position(result[0].positionLineNumber, result[0].positionColumn);
      editor.revealPosition(
        pos,
        0
        /* Smooth */
      );
    }
  }
  _moveTo(from, to, inSelectionMode) {
    if (inSelectionMode) {
      return new selection.Selection(from.selectionStartLineNumber, from.selectionStartColumn, to.lineNumber, to.column);
    } else {
      return new selection.Selection(to.lineNumber, to.column, to.lineNumber, to.column);
    }
  }
}
class WordLeftCommand extends MoveWordCommand {
  _move(wordSeparators, model, position2, wordNavigationType) {
    return cursorWordOperations.WordOperations.moveWordLeft(wordSeparators, model, position2, wordNavigationType);
  }
}
class WordRightCommand extends MoveWordCommand {
  _move(wordSeparators, model, position2, wordNavigationType) {
    return cursorWordOperations.WordOperations.moveWordRight(wordSeparators, model, position2, wordNavigationType);
  }
}
class CursorWordStartLeft extends WordLeftCommand {
  constructor() {
    super({
      inSelectionMode: false,
      wordNavigationType: 0,
      id: "cursorWordStartLeft",
      precondition: void 0
    });
  }
}
class CursorWordEndLeft extends WordLeftCommand {
  constructor() {
    super({
      inSelectionMode: false,
      wordNavigationType: 2,
      id: "cursorWordEndLeft",
      precondition: void 0
    });
  }
}
class CursorWordLeft extends WordLeftCommand {
  constructor() {
    var _a;
    super({
      inSelectionMode: false,
      wordNavigationType: 1,
      id: "cursorWordLeft",
      precondition: void 0,
      kbOpts: {
        kbExpr: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.textInputFocus, (_a = contextkey.ContextKeyExpr.and(accessibility.CONTEXT_ACCESSIBILITY_MODE_ENABLED, contextkeys.IsWindowsContext)) === null || _a === void 0 ? void 0 : _a.negate()),
        primary: 2048 | 15,
        mac: {
          primary: 512 | 15
          /* LeftArrow */
        },
        weight: 100
        /* EditorContrib */
      }
    });
  }
}
class CursorWordStartLeftSelect extends WordLeftCommand {
  constructor() {
    super({
      inSelectionMode: true,
      wordNavigationType: 0,
      id: "cursorWordStartLeftSelect",
      precondition: void 0
    });
  }
}
class CursorWordEndLeftSelect extends WordLeftCommand {
  constructor() {
    super({
      inSelectionMode: true,
      wordNavigationType: 2,
      id: "cursorWordEndLeftSelect",
      precondition: void 0
    });
  }
}
class CursorWordLeftSelect extends WordLeftCommand {
  constructor() {
    var _a;
    super({
      inSelectionMode: true,
      wordNavigationType: 1,
      id: "cursorWordLeftSelect",
      precondition: void 0,
      kbOpts: {
        kbExpr: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.textInputFocus, (_a = contextkey.ContextKeyExpr.and(accessibility.CONTEXT_ACCESSIBILITY_MODE_ENABLED, contextkeys.IsWindowsContext)) === null || _a === void 0 ? void 0 : _a.negate()),
        primary: 2048 | 1024 | 15,
        mac: {
          primary: 512 | 1024 | 15
          /* LeftArrow */
        },
        weight: 100
        /* EditorContrib */
      }
    });
  }
}
class CursorWordAccessibilityLeft extends WordLeftCommand {
  constructor() {
    super({
      inSelectionMode: false,
      wordNavigationType: 3,
      id: "cursorWordAccessibilityLeft",
      precondition: void 0
    });
  }
  _move(_, model, position2, wordNavigationType) {
    return super._move(wordCharacterClassifier.getMapForWordSeparators(editorOptions.EditorOptions.wordSeparators.defaultValue), model, position2, wordNavigationType);
  }
}
class CursorWordAccessibilityLeftSelect extends WordLeftCommand {
  constructor() {
    super({
      inSelectionMode: true,
      wordNavigationType: 3,
      id: "cursorWordAccessibilityLeftSelect",
      precondition: void 0
    });
  }
  _move(_, model, position2, wordNavigationType) {
    return super._move(wordCharacterClassifier.getMapForWordSeparators(editorOptions.EditorOptions.wordSeparators.defaultValue), model, position2, wordNavigationType);
  }
}
class CursorWordStartRight extends WordRightCommand {
  constructor() {
    super({
      inSelectionMode: false,
      wordNavigationType: 0,
      id: "cursorWordStartRight",
      precondition: void 0
    });
  }
}
class CursorWordEndRight extends WordRightCommand {
  constructor() {
    var _a;
    super({
      inSelectionMode: false,
      wordNavigationType: 2,
      id: "cursorWordEndRight",
      precondition: void 0,
      kbOpts: {
        kbExpr: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.textInputFocus, (_a = contextkey.ContextKeyExpr.and(accessibility.CONTEXT_ACCESSIBILITY_MODE_ENABLED, contextkeys.IsWindowsContext)) === null || _a === void 0 ? void 0 : _a.negate()),
        primary: 2048 | 17,
        mac: {
          primary: 512 | 17
          /* RightArrow */
        },
        weight: 100
        /* EditorContrib */
      }
    });
  }
}
class CursorWordRight extends WordRightCommand {
  constructor() {
    super({
      inSelectionMode: false,
      wordNavigationType: 2,
      id: "cursorWordRight",
      precondition: void 0
    });
  }
}
class CursorWordStartRightSelect extends WordRightCommand {
  constructor() {
    super({
      inSelectionMode: true,
      wordNavigationType: 0,
      id: "cursorWordStartRightSelect",
      precondition: void 0
    });
  }
}
class CursorWordEndRightSelect extends WordRightCommand {
  constructor() {
    var _a;
    super({
      inSelectionMode: true,
      wordNavigationType: 2,
      id: "cursorWordEndRightSelect",
      precondition: void 0,
      kbOpts: {
        kbExpr: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.textInputFocus, (_a = contextkey.ContextKeyExpr.and(accessibility.CONTEXT_ACCESSIBILITY_MODE_ENABLED, contextkeys.IsWindowsContext)) === null || _a === void 0 ? void 0 : _a.negate()),
        primary: 2048 | 1024 | 17,
        mac: {
          primary: 512 | 1024 | 17
          /* RightArrow */
        },
        weight: 100
        /* EditorContrib */
      }
    });
  }
}
class CursorWordRightSelect extends WordRightCommand {
  constructor() {
    super({
      inSelectionMode: true,
      wordNavigationType: 2,
      id: "cursorWordRightSelect",
      precondition: void 0
    });
  }
}
class CursorWordAccessibilityRight extends WordRightCommand {
  constructor() {
    super({
      inSelectionMode: false,
      wordNavigationType: 3,
      id: "cursorWordAccessibilityRight",
      precondition: void 0
    });
  }
  _move(_, model, position2, wordNavigationType) {
    return super._move(wordCharacterClassifier.getMapForWordSeparators(editorOptions.EditorOptions.wordSeparators.defaultValue), model, position2, wordNavigationType);
  }
}
class CursorWordAccessibilityRightSelect extends WordRightCommand {
  constructor() {
    super({
      inSelectionMode: true,
      wordNavigationType: 3,
      id: "cursorWordAccessibilityRightSelect",
      precondition: void 0
    });
  }
  _move(_, model, position2, wordNavigationType) {
    return super._move(wordCharacterClassifier.getMapForWordSeparators(editorOptions.EditorOptions.wordSeparators.defaultValue), model, position2, wordNavigationType);
  }
}
class DeleteWordCommand extends editorExtensions.EditorCommand {
  constructor(opts) {
    super(opts);
    this._whitespaceHeuristics = opts.whitespaceHeuristics;
    this._wordNavigationType = opts.wordNavigationType;
  }
  runEditorCommand(accessor, editor, args) {
    const languageConfigurationService = accessor.get(languageConfigurationRegistry.ILanguageConfigurationService);
    if (!editor.hasModel()) {
      return;
    }
    const wordSeparators = wordCharacterClassifier.getMapForWordSeparators(editor.getOption(
      117
      /* wordSeparators */
    ));
    const model = editor.getModel();
    const selections = editor.getSelections();
    const autoClosingBrackets = editor.getOption(
      5
      /* autoClosingBrackets */
    );
    const autoClosingQuotes = editor.getOption(
      8
      /* autoClosingQuotes */
    );
    const autoClosingPairs = languageConfigurationService.getLanguageConfiguration(model.getLanguageId()).getAutoClosingPairs();
    const viewModel = editor._getViewModel();
    const commands = selections.map((sel) => {
      const deleteRange = this._delete({
        wordSeparators,
        model,
        selection: sel,
        whitespaceHeuristics: this._whitespaceHeuristics,
        autoClosingDelete: editor.getOption(
          6
          /* autoClosingDelete */
        ),
        autoClosingBrackets,
        autoClosingQuotes,
        autoClosingPairs,
        autoClosedCharacters: viewModel.getCursorAutoClosedCharacters()
      }, this._wordNavigationType);
      return new replaceCommand.ReplaceCommand(deleteRange, "");
    });
    editor.pushUndoStop();
    editor.executeCommands(this.id, commands);
    editor.pushUndoStop();
  }
}
class DeleteWordLeftCommand extends DeleteWordCommand {
  _delete(ctx, wordNavigationType) {
    let r = cursorWordOperations.WordOperations.deleteWordLeft(ctx, wordNavigationType);
    if (r) {
      return r;
    }
    return new range.Range(1, 1, 1, 1);
  }
}
class DeleteWordRightCommand extends DeleteWordCommand {
  _delete(ctx, wordNavigationType) {
    let r = cursorWordOperations.WordOperations.deleteWordRight(ctx, wordNavigationType);
    if (r) {
      return r;
    }
    const lineCount = ctx.model.getLineCount();
    const maxColumn = ctx.model.getLineMaxColumn(lineCount);
    return new range.Range(lineCount, maxColumn, lineCount, maxColumn);
  }
}
class DeleteWordStartLeft extends DeleteWordLeftCommand {
  constructor() {
    super({
      whitespaceHeuristics: false,
      wordNavigationType: 0,
      id: "deleteWordStartLeft",
      precondition: editorContextKeys.EditorContextKeys.writable
    });
  }
}
class DeleteWordEndLeft extends DeleteWordLeftCommand {
  constructor() {
    super({
      whitespaceHeuristics: false,
      wordNavigationType: 2,
      id: "deleteWordEndLeft",
      precondition: editorContextKeys.EditorContextKeys.writable
    });
  }
}
class DeleteWordLeft extends DeleteWordLeftCommand {
  constructor() {
    super({
      whitespaceHeuristics: true,
      wordNavigationType: 0,
      id: "deleteWordLeft",
      precondition: editorContextKeys.EditorContextKeys.writable,
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.textInputFocus,
        primary: 2048 | 1,
        mac: {
          primary: 512 | 1
          /* Backspace */
        },
        weight: 100
        /* EditorContrib */
      }
    });
  }
}
class DeleteWordStartRight extends DeleteWordRightCommand {
  constructor() {
    super({
      whitespaceHeuristics: false,
      wordNavigationType: 0,
      id: "deleteWordStartRight",
      precondition: editorContextKeys.EditorContextKeys.writable
    });
  }
}
class DeleteWordEndRight extends DeleteWordRightCommand {
  constructor() {
    super({
      whitespaceHeuristics: false,
      wordNavigationType: 2,
      id: "deleteWordEndRight",
      precondition: editorContextKeys.EditorContextKeys.writable
    });
  }
}
class DeleteWordRight extends DeleteWordRightCommand {
  constructor() {
    super({
      whitespaceHeuristics: true,
      wordNavigationType: 2,
      id: "deleteWordRight",
      precondition: editorContextKeys.EditorContextKeys.writable,
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.textInputFocus,
        primary: 2048 | 20,
        mac: {
          primary: 512 | 20
          /* Delete */
        },
        weight: 100
        /* EditorContrib */
      }
    });
  }
}
class DeleteInsideWord extends editorExtensions.EditorAction {
  constructor() {
    super({
      id: "deleteInsideWord",
      precondition: editorContextKeys.EditorContextKeys.writable,
      label: nls.localize("deleteInsideWord", "Delete Word"),
      alias: "Delete Word"
    });
  }
  run(accessor, editor, args) {
    if (!editor.hasModel()) {
      return;
    }
    const wordSeparators = wordCharacterClassifier.getMapForWordSeparators(editor.getOption(
      117
      /* wordSeparators */
    ));
    const model = editor.getModel();
    const selections = editor.getSelections();
    const commands = selections.map((sel) => {
      const deleteRange = cursorWordOperations.WordOperations.deleteInsideWord(wordSeparators, model, sel);
      return new replaceCommand.ReplaceCommand(deleteRange, "");
    });
    editor.pushUndoStop();
    editor.executeCommands(this.id, commands);
    editor.pushUndoStop();
  }
}
editorExtensions.registerEditorCommand(new CursorWordStartLeft());
editorExtensions.registerEditorCommand(new CursorWordEndLeft());
editorExtensions.registerEditorCommand(new CursorWordLeft());
editorExtensions.registerEditorCommand(new CursorWordStartLeftSelect());
editorExtensions.registerEditorCommand(new CursorWordEndLeftSelect());
editorExtensions.registerEditorCommand(new CursorWordLeftSelect());
editorExtensions.registerEditorCommand(new CursorWordStartRight());
editorExtensions.registerEditorCommand(new CursorWordEndRight());
editorExtensions.registerEditorCommand(new CursorWordRight());
editorExtensions.registerEditorCommand(new CursorWordStartRightSelect());
editorExtensions.registerEditorCommand(new CursorWordEndRightSelect());
editorExtensions.registerEditorCommand(new CursorWordRightSelect());
editorExtensions.registerEditorCommand(new CursorWordAccessibilityLeft());
editorExtensions.registerEditorCommand(new CursorWordAccessibilityLeftSelect());
editorExtensions.registerEditorCommand(new CursorWordAccessibilityRight());
editorExtensions.registerEditorCommand(new CursorWordAccessibilityRightSelect());
editorExtensions.registerEditorCommand(new DeleteWordStartLeft());
editorExtensions.registerEditorCommand(new DeleteWordEndLeft());
editorExtensions.registerEditorCommand(new DeleteWordLeft());
editorExtensions.registerEditorCommand(new DeleteWordStartRight());
editorExtensions.registerEditorCommand(new DeleteWordEndRight());
editorExtensions.registerEditorCommand(new DeleteWordRight());
editorExtensions.registerEditorAction(DeleteInsideWord);
exports.CursorWordAccessibilityLeft = CursorWordAccessibilityLeft;
exports.CursorWordAccessibilityLeftSelect = CursorWordAccessibilityLeftSelect;
exports.CursorWordAccessibilityRight = CursorWordAccessibilityRight;
exports.CursorWordAccessibilityRightSelect = CursorWordAccessibilityRightSelect;
exports.CursorWordEndLeft = CursorWordEndLeft;
exports.CursorWordEndLeftSelect = CursorWordEndLeftSelect;
exports.CursorWordEndRight = CursorWordEndRight;
exports.CursorWordEndRightSelect = CursorWordEndRightSelect;
exports.CursorWordLeft = CursorWordLeft;
exports.CursorWordLeftSelect = CursorWordLeftSelect;
exports.CursorWordRight = CursorWordRight;
exports.CursorWordRightSelect = CursorWordRightSelect;
exports.CursorWordStartLeft = CursorWordStartLeft;
exports.CursorWordStartLeftSelect = CursorWordStartLeftSelect;
exports.CursorWordStartRight = CursorWordStartRight;
exports.CursorWordStartRightSelect = CursorWordStartRightSelect;
exports.DeleteInsideWord = DeleteInsideWord;
exports.DeleteWordCommand = DeleteWordCommand;
exports.DeleteWordEndLeft = DeleteWordEndLeft;
exports.DeleteWordEndRight = DeleteWordEndRight;
exports.DeleteWordLeft = DeleteWordLeft;
exports.DeleteWordLeftCommand = DeleteWordLeftCommand;
exports.DeleteWordRight = DeleteWordRight;
exports.DeleteWordRightCommand = DeleteWordRightCommand;
exports.DeleteWordStartLeft = DeleteWordStartLeft;
exports.DeleteWordStartRight = DeleteWordStartRight;
exports.MoveWordCommand = MoveWordCommand;
exports.WordLeftCommand = WordLeftCommand;
exports.WordRightCommand = WordRightCommand;
