"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const strings = require("../../../base/common/strings.js");
const cursorCommon = require("../cursorCommon.js");
const cursorDeleteOperations = require("./cursorDeleteOperations.js");
const wordCharacterClassifier = require("../core/wordCharacterClassifier.js");
const position = require("../core/position.js");
const range = require("../core/range.js");
class WordOperations {
  static _createWord(lineContent, wordType, nextCharClass, start, end) {
    return { start, end, wordType, nextCharClass };
  }
  static _findPreviousWordOnLine(wordSeparators, model, position2) {
    const lineContent = model.getLineContent(position2.lineNumber);
    return this._doFindPreviousWordOnLine(lineContent, wordSeparators, position2);
  }
  static _doFindPreviousWordOnLine(lineContent, wordSeparators, position2) {
    let wordType = 0;
    for (let chIndex = position2.column - 2; chIndex >= 0; chIndex--) {
      const chCode = lineContent.charCodeAt(chIndex);
      const chClass = wordSeparators.get(chCode);
      if (chClass === 0) {
        if (wordType === 2) {
          return this._createWord(lineContent, wordType, chClass, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1));
        }
        wordType = 1;
      } else if (chClass === 2) {
        if (wordType === 1) {
          return this._createWord(lineContent, wordType, chClass, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1));
        }
        wordType = 2;
      } else if (chClass === 1) {
        if (wordType !== 0) {
          return this._createWord(lineContent, wordType, chClass, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1));
        }
      }
    }
    if (wordType !== 0) {
      return this._createWord(lineContent, wordType, 1, 0, this._findEndOfWord(lineContent, wordSeparators, wordType, 0));
    }
    return null;
  }
  static _findEndOfWord(lineContent, wordSeparators, wordType, startIndex) {
    const len = lineContent.length;
    for (let chIndex = startIndex; chIndex < len; chIndex++) {
      const chCode = lineContent.charCodeAt(chIndex);
      const chClass = wordSeparators.get(chCode);
      if (chClass === 1) {
        return chIndex;
      }
      if (wordType === 1 && chClass === 2) {
        return chIndex;
      }
      if (wordType === 2 && chClass === 0) {
        return chIndex;
      }
    }
    return len;
  }
  static _findNextWordOnLine(wordSeparators, model, position2) {
    const lineContent = model.getLineContent(position2.lineNumber);
    return this._doFindNextWordOnLine(lineContent, wordSeparators, position2);
  }
  static _doFindNextWordOnLine(lineContent, wordSeparators, position2) {
    let wordType = 0;
    const len = lineContent.length;
    for (let chIndex = position2.column - 1; chIndex < len; chIndex++) {
      const chCode = lineContent.charCodeAt(chIndex);
      const chClass = wordSeparators.get(chCode);
      if (chClass === 0) {
        if (wordType === 2) {
          return this._createWord(lineContent, wordType, chClass, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex);
        }
        wordType = 1;
      } else if (chClass === 2) {
        if (wordType === 1) {
          return this._createWord(lineContent, wordType, chClass, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex);
        }
        wordType = 2;
      } else if (chClass === 1) {
        if (wordType !== 0) {
          return this._createWord(lineContent, wordType, chClass, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex);
        }
      }
    }
    if (wordType !== 0) {
      return this._createWord(lineContent, wordType, 1, this._findStartOfWord(lineContent, wordSeparators, wordType, len - 1), len);
    }
    return null;
  }
  static _findStartOfWord(lineContent, wordSeparators, wordType, startIndex) {
    for (let chIndex = startIndex; chIndex >= 0; chIndex--) {
      const chCode = lineContent.charCodeAt(chIndex);
      const chClass = wordSeparators.get(chCode);
      if (chClass === 1) {
        return chIndex + 1;
      }
      if (wordType === 1 && chClass === 2) {
        return chIndex + 1;
      }
      if (wordType === 2 && chClass === 0) {
        return chIndex + 1;
      }
    }
    return 0;
  }
  static moveWordLeft(wordSeparators, model, position$1, wordNavigationType) {
    let lineNumber = position$1.lineNumber;
    let column = position$1.column;
    if (column === 1) {
      if (lineNumber > 1) {
        lineNumber = lineNumber - 1;
        column = model.getLineMaxColumn(lineNumber);
      }
    }
    let prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new position.Position(lineNumber, column));
    if (wordNavigationType === 0) {
      return new position.Position(lineNumber, prevWordOnLine ? prevWordOnLine.start + 1 : 1);
    }
    if (wordNavigationType === 1) {
      if (prevWordOnLine && prevWordOnLine.wordType === 2 && prevWordOnLine.end - prevWordOnLine.start === 1 && prevWordOnLine.nextCharClass === 0) {
        prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new position.Position(lineNumber, prevWordOnLine.start + 1));
      }
      return new position.Position(lineNumber, prevWordOnLine ? prevWordOnLine.start + 1 : 1);
    }
    if (wordNavigationType === 3) {
      while (prevWordOnLine && prevWordOnLine.wordType === 2) {
        prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new position.Position(lineNumber, prevWordOnLine.start + 1));
      }
      return new position.Position(lineNumber, prevWordOnLine ? prevWordOnLine.start + 1 : 1);
    }
    if (prevWordOnLine && column <= prevWordOnLine.end + 1) {
      prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new position.Position(lineNumber, prevWordOnLine.start + 1));
    }
    return new position.Position(lineNumber, prevWordOnLine ? prevWordOnLine.end + 1 : 1);
  }
  static _moveWordPartLeft(model, position$1) {
    const lineNumber = position$1.lineNumber;
    const maxColumn = model.getLineMaxColumn(lineNumber);
    if (position$1.column === 1) {
      return lineNumber > 1 ? new position.Position(lineNumber - 1, model.getLineMaxColumn(lineNumber - 1)) : position$1;
    }
    const lineContent = model.getLineContent(lineNumber);
    for (let column = position$1.column - 1; column > 1; column--) {
      const left = lineContent.charCodeAt(column - 2);
      const right = lineContent.charCodeAt(column - 1);
      if (left === 95 && right !== 95) {
        return new position.Position(lineNumber, column);
      }
      if (strings.isLowerAsciiLetter(left) && strings.isUpperAsciiLetter(right)) {
        return new position.Position(lineNumber, column);
      }
      if (strings.isUpperAsciiLetter(left) && strings.isUpperAsciiLetter(right)) {
        if (column + 1 < maxColumn) {
          const rightRight = lineContent.charCodeAt(column);
          if (strings.isLowerAsciiLetter(rightRight)) {
            return new position.Position(lineNumber, column);
          }
        }
      }
    }
    return new position.Position(lineNumber, 1);
  }
  static moveWordRight(wordSeparators, model, position$1, wordNavigationType) {
    let lineNumber = position$1.lineNumber;
    let column = position$1.column;
    let movedDown = false;
    if (column === model.getLineMaxColumn(lineNumber)) {
      if (lineNumber < model.getLineCount()) {
        movedDown = true;
        lineNumber = lineNumber + 1;
        column = 1;
      }
    }
    let nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new position.Position(lineNumber, column));
    if (wordNavigationType === 2) {
      if (nextWordOnLine && nextWordOnLine.wordType === 2) {
        if (nextWordOnLine.end - nextWordOnLine.start === 1 && nextWordOnLine.nextCharClass === 0) {
          nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new position.Position(lineNumber, nextWordOnLine.end + 1));
        }
      }
      if (nextWordOnLine) {
        column = nextWordOnLine.end + 1;
      } else {
        column = model.getLineMaxColumn(lineNumber);
      }
    } else if (wordNavigationType === 3) {
      if (movedDown) {
        column = 0;
      }
      while (nextWordOnLine && (nextWordOnLine.wordType === 2 || nextWordOnLine.start + 1 <= column)) {
        nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new position.Position(lineNumber, nextWordOnLine.end + 1));
      }
      if (nextWordOnLine) {
        column = nextWordOnLine.start + 1;
      } else {
        column = model.getLineMaxColumn(lineNumber);
      }
    } else {
      if (nextWordOnLine && !movedDown && column >= nextWordOnLine.start + 1) {
        nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new position.Position(lineNumber, nextWordOnLine.end + 1));
      }
      if (nextWordOnLine) {
        column = nextWordOnLine.start + 1;
      } else {
        column = model.getLineMaxColumn(lineNumber);
      }
    }
    return new position.Position(lineNumber, column);
  }
  static _moveWordPartRight(model, position$1) {
    const lineNumber = position$1.lineNumber;
    const maxColumn = model.getLineMaxColumn(lineNumber);
    if (position$1.column === maxColumn) {
      return lineNumber < model.getLineCount() ? new position.Position(lineNumber + 1, 1) : position$1;
    }
    const lineContent = model.getLineContent(lineNumber);
    for (let column = position$1.column + 1; column < maxColumn; column++) {
      const left = lineContent.charCodeAt(column - 2);
      const right = lineContent.charCodeAt(column - 1);
      if (left !== 95 && right === 95) {
        return new position.Position(lineNumber, column);
      }
      if (strings.isLowerAsciiLetter(left) && strings.isUpperAsciiLetter(right)) {
        return new position.Position(lineNumber, column);
      }
      if (strings.isUpperAsciiLetter(left) && strings.isUpperAsciiLetter(right)) {
        if (column + 1 < maxColumn) {
          const rightRight = lineContent.charCodeAt(column);
          if (strings.isLowerAsciiLetter(rightRight)) {
            return new position.Position(lineNumber, column);
          }
        }
      }
    }
    return new position.Position(lineNumber, maxColumn);
  }
  static _deleteWordLeftWhitespace(model, position2) {
    const lineContent = model.getLineContent(position2.lineNumber);
    const startIndex = position2.column - 2;
    const lastNonWhitespace = strings.lastNonWhitespaceIndex(lineContent, startIndex);
    if (lastNonWhitespace + 1 < startIndex) {
      return new range.Range(position2.lineNumber, lastNonWhitespace + 2, position2.lineNumber, position2.column);
    }
    return null;
  }
  static deleteWordLeft(ctx, wordNavigationType) {
    const wordSeparators = ctx.wordSeparators;
    const model = ctx.model;
    const selection = ctx.selection;
    const whitespaceHeuristics = ctx.whitespaceHeuristics;
    if (!selection.isEmpty()) {
      return selection;
    }
    if (cursorDeleteOperations.DeleteOperations.isAutoClosingPairDelete(ctx.autoClosingDelete, ctx.autoClosingBrackets, ctx.autoClosingQuotes, ctx.autoClosingPairs.autoClosingPairsOpenByEnd, ctx.model, [ctx.selection], ctx.autoClosedCharacters)) {
      const position2 = ctx.selection.getPosition();
      return new range.Range(position2.lineNumber, position2.column - 1, position2.lineNumber, position2.column + 1);
    }
    const position$1 = new position.Position(selection.positionLineNumber, selection.positionColumn);
    let lineNumber = position$1.lineNumber;
    let column = position$1.column;
    if (lineNumber === 1 && column === 1) {
      return null;
    }
    if (whitespaceHeuristics) {
      const r = this._deleteWordLeftWhitespace(model, position$1);
      if (r) {
        return r;
      }
    }
    let prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, position$1);
    if (wordNavigationType === 0) {
      if (prevWordOnLine) {
        column = prevWordOnLine.start + 1;
      } else {
        if (column > 1) {
          column = 1;
        } else {
          lineNumber--;
          column = model.getLineMaxColumn(lineNumber);
        }
      }
    } else {
      if (prevWordOnLine && column <= prevWordOnLine.end + 1) {
        prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new position.Position(lineNumber, prevWordOnLine.start + 1));
      }
      if (prevWordOnLine) {
        column = prevWordOnLine.end + 1;
      } else {
        if (column > 1) {
          column = 1;
        } else {
          lineNumber--;
          column = model.getLineMaxColumn(lineNumber);
        }
      }
    }
    return new range.Range(lineNumber, column, position$1.lineNumber, position$1.column);
  }
  static deleteInsideWord(wordSeparators, model, selection) {
    if (!selection.isEmpty()) {
      return selection;
    }
    const position$1 = new position.Position(selection.positionLineNumber, selection.positionColumn);
    const r = this._deleteInsideWordWhitespace(model, position$1);
    if (r) {
      return r;
    }
    return this._deleteInsideWordDetermineDeleteRange(wordSeparators, model, position$1);
  }
  static _charAtIsWhitespace(str, index) {
    const charCode = str.charCodeAt(index);
    return charCode === 32 || charCode === 9;
  }
  static _deleteInsideWordWhitespace(model, position2) {
    const lineContent = model.getLineContent(position2.lineNumber);
    const lineContentLength = lineContent.length;
    if (lineContentLength === 0) {
      return null;
    }
    let leftIndex = Math.max(position2.column - 2, 0);
    if (!this._charAtIsWhitespace(lineContent, leftIndex)) {
      return null;
    }
    let rightIndex = Math.min(position2.column - 1, lineContentLength - 1);
    if (!this._charAtIsWhitespace(lineContent, rightIndex)) {
      return null;
    }
    while (leftIndex > 0 && this._charAtIsWhitespace(lineContent, leftIndex - 1)) {
      leftIndex--;
    }
    while (rightIndex + 1 < lineContentLength && this._charAtIsWhitespace(lineContent, rightIndex + 1)) {
      rightIndex++;
    }
    return new range.Range(position2.lineNumber, leftIndex + 1, position2.lineNumber, rightIndex + 2);
  }
  static _deleteInsideWordDetermineDeleteRange(wordSeparators, model, position2) {
    const lineContent = model.getLineContent(position2.lineNumber);
    const lineLength = lineContent.length;
    if (lineLength === 0) {
      if (position2.lineNumber > 1) {
        return new range.Range(position2.lineNumber - 1, model.getLineMaxColumn(position2.lineNumber - 1), position2.lineNumber, 1);
      } else {
        if (position2.lineNumber < model.getLineCount()) {
          return new range.Range(position2.lineNumber, 1, position2.lineNumber + 1, 1);
        } else {
          return new range.Range(position2.lineNumber, 1, position2.lineNumber, 1);
        }
      }
    }
    const touchesWord = (word) => {
      return word.start + 1 <= position2.column && position2.column <= word.end + 1;
    };
    const createRangeWithPosition = (startColumn, endColumn) => {
      startColumn = Math.min(startColumn, position2.column);
      endColumn = Math.max(endColumn, position2.column);
      return new range.Range(position2.lineNumber, startColumn, position2.lineNumber, endColumn);
    };
    const deleteWordAndAdjacentWhitespace = (word) => {
      let startColumn = word.start + 1;
      let endColumn = word.end + 1;
      let expandedToTheRight = false;
      while (endColumn - 1 < lineLength && this._charAtIsWhitespace(lineContent, endColumn - 1)) {
        expandedToTheRight = true;
        endColumn++;
      }
      if (!expandedToTheRight) {
        while (startColumn > 1 && this._charAtIsWhitespace(lineContent, startColumn - 2)) {
          startColumn--;
        }
      }
      return createRangeWithPosition(startColumn, endColumn);
    };
    const prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, position2);
    if (prevWordOnLine && touchesWord(prevWordOnLine)) {
      return deleteWordAndAdjacentWhitespace(prevWordOnLine);
    }
    const nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, position2);
    if (nextWordOnLine && touchesWord(nextWordOnLine)) {
      return deleteWordAndAdjacentWhitespace(nextWordOnLine);
    }
    if (prevWordOnLine && nextWordOnLine) {
      return createRangeWithPosition(prevWordOnLine.end + 1, nextWordOnLine.start + 1);
    }
    if (prevWordOnLine) {
      return createRangeWithPosition(prevWordOnLine.start + 1, prevWordOnLine.end + 1);
    }
    if (nextWordOnLine) {
      return createRangeWithPosition(nextWordOnLine.start + 1, nextWordOnLine.end + 1);
    }
    return createRangeWithPosition(1, lineLength + 1);
  }
  static _deleteWordPartLeft(model, selection) {
    if (!selection.isEmpty()) {
      return selection;
    }
    const pos = selection.getPosition();
    const toPosition = WordOperations._moveWordPartLeft(model, pos);
    return new range.Range(pos.lineNumber, pos.column, toPosition.lineNumber, toPosition.column);
  }
  static _findFirstNonWhitespaceChar(str, startIndex) {
    const len = str.length;
    for (let chIndex = startIndex; chIndex < len; chIndex++) {
      const ch = str.charAt(chIndex);
      if (ch !== " " && ch !== "	") {
        return chIndex;
      }
    }
    return len;
  }
  static _deleteWordRightWhitespace(model, position2) {
    const lineContent = model.getLineContent(position2.lineNumber);
    const startIndex = position2.column - 1;
    const firstNonWhitespace = this._findFirstNonWhitespaceChar(lineContent, startIndex);
    if (startIndex + 1 < firstNonWhitespace) {
      return new range.Range(position2.lineNumber, position2.column, position2.lineNumber, firstNonWhitespace + 1);
    }
    return null;
  }
  static deleteWordRight(ctx, wordNavigationType) {
    const wordSeparators = ctx.wordSeparators;
    const model = ctx.model;
    const selection = ctx.selection;
    const whitespaceHeuristics = ctx.whitespaceHeuristics;
    if (!selection.isEmpty()) {
      return selection;
    }
    const position$1 = new position.Position(selection.positionLineNumber, selection.positionColumn);
    let lineNumber = position$1.lineNumber;
    let column = position$1.column;
    const lineCount = model.getLineCount();
    const maxColumn = model.getLineMaxColumn(lineNumber);
    if (lineNumber === lineCount && column === maxColumn) {
      return null;
    }
    if (whitespaceHeuristics) {
      const r = this._deleteWordRightWhitespace(model, position$1);
      if (r) {
        return r;
      }
    }
    let nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, position$1);
    if (wordNavigationType === 2) {
      if (nextWordOnLine) {
        column = nextWordOnLine.end + 1;
      } else {
        if (column < maxColumn || lineNumber === lineCount) {
          column = maxColumn;
        } else {
          lineNumber++;
          nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new position.Position(lineNumber, 1));
          if (nextWordOnLine) {
            column = nextWordOnLine.start + 1;
          } else {
            column = model.getLineMaxColumn(lineNumber);
          }
        }
      }
    } else {
      if (nextWordOnLine && column >= nextWordOnLine.start + 1) {
        nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new position.Position(lineNumber, nextWordOnLine.end + 1));
      }
      if (nextWordOnLine) {
        column = nextWordOnLine.start + 1;
      } else {
        if (column < maxColumn || lineNumber === lineCount) {
          column = maxColumn;
        } else {
          lineNumber++;
          nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new position.Position(lineNumber, 1));
          if (nextWordOnLine) {
            column = nextWordOnLine.start + 1;
          } else {
            column = model.getLineMaxColumn(lineNumber);
          }
        }
      }
    }
    return new range.Range(lineNumber, column, position$1.lineNumber, position$1.column);
  }
  static _deleteWordPartRight(model, selection) {
    if (!selection.isEmpty()) {
      return selection;
    }
    const pos = selection.getPosition();
    const toPosition = WordOperations._moveWordPartRight(model, pos);
    return new range.Range(pos.lineNumber, pos.column, toPosition.lineNumber, toPosition.column);
  }
  static _createWordAtPosition(model, lineNumber, word) {
    const range$1 = new range.Range(lineNumber, word.start + 1, lineNumber, word.end + 1);
    return {
      word: model.getValueInRange(range$1),
      startColumn: range$1.startColumn,
      endColumn: range$1.endColumn
    };
  }
  static getWordAtPosition(model, _wordSeparators, position2) {
    const wordSeparators = wordCharacterClassifier.getMapForWordSeparators(_wordSeparators);
    const prevWord = WordOperations._findPreviousWordOnLine(wordSeparators, model, position2);
    if (prevWord && prevWord.wordType === 1 && prevWord.start <= position2.column - 1 && position2.column - 1 <= prevWord.end) {
      return WordOperations._createWordAtPosition(model, position2.lineNumber, prevWord);
    }
    const nextWord = WordOperations._findNextWordOnLine(wordSeparators, model, position2);
    if (nextWord && nextWord.wordType === 1 && nextWord.start <= position2.column - 1 && position2.column - 1 <= nextWord.end) {
      return WordOperations._createWordAtPosition(model, position2.lineNumber, nextWord);
    }
    return null;
  }
  static word(config, model, cursor, inSelectionMode, position$1) {
    const wordSeparators = wordCharacterClassifier.getMapForWordSeparators(config.wordSeparators);
    const prevWord = WordOperations._findPreviousWordOnLine(wordSeparators, model, position$1);
    const nextWord = WordOperations._findNextWordOnLine(wordSeparators, model, position$1);
    if (!inSelectionMode) {
      let startColumn2;
      let endColumn2;
      if (prevWord && prevWord.wordType === 1 && prevWord.start <= position$1.column - 1 && position$1.column - 1 <= prevWord.end) {
        startColumn2 = prevWord.start + 1;
        endColumn2 = prevWord.end + 1;
      } else if (nextWord && nextWord.wordType === 1 && nextWord.start <= position$1.column - 1 && position$1.column - 1 <= nextWord.end) {
        startColumn2 = nextWord.start + 1;
        endColumn2 = nextWord.end + 1;
      } else {
        if (prevWord) {
          startColumn2 = prevWord.end + 1;
        } else {
          startColumn2 = 1;
        }
        if (nextWord) {
          endColumn2 = nextWord.start + 1;
        } else {
          endColumn2 = model.getLineMaxColumn(position$1.lineNumber);
        }
      }
      return new cursorCommon.SingleCursorState(new range.Range(position$1.lineNumber, startColumn2, position$1.lineNumber, endColumn2), 0, new position.Position(position$1.lineNumber, endColumn2), 0);
    }
    let startColumn;
    let endColumn;
    if (prevWord && prevWord.wordType === 1 && prevWord.start < position$1.column - 1 && position$1.column - 1 < prevWord.end) {
      startColumn = prevWord.start + 1;
      endColumn = prevWord.end + 1;
    } else if (nextWord && nextWord.wordType === 1 && nextWord.start < position$1.column - 1 && position$1.column - 1 < nextWord.end) {
      startColumn = nextWord.start + 1;
      endColumn = nextWord.end + 1;
    } else {
      startColumn = position$1.column;
      endColumn = position$1.column;
    }
    const lineNumber = position$1.lineNumber;
    let column;
    if (cursor.selectionStart.containsPosition(position$1)) {
      column = cursor.selectionStart.endColumn;
    } else if (position$1.isBeforeOrEqual(cursor.selectionStart.getStartPosition())) {
      column = startColumn;
      const possiblePosition = new position.Position(lineNumber, column);
      if (cursor.selectionStart.containsPosition(possiblePosition)) {
        column = cursor.selectionStart.endColumn;
      }
    } else {
      column = endColumn;
      const possiblePosition = new position.Position(lineNumber, column);
      if (cursor.selectionStart.containsPosition(possiblePosition)) {
        column = cursor.selectionStart.startColumn;
      }
    }
    return cursor.move(true, lineNumber, column, 0);
  }
}
class WordPartOperations extends WordOperations {
  static deleteWordPartLeft(ctx) {
    const candidates = enforceDefined([
      WordOperations.deleteWordLeft(
        ctx,
        0
        /* WordStart */
      ),
      WordOperations.deleteWordLeft(
        ctx,
        2
        /* WordEnd */
      ),
      WordOperations._deleteWordPartLeft(ctx.model, ctx.selection)
    ]);
    candidates.sort(range.Range.compareRangesUsingEnds);
    return candidates[2];
  }
  static deleteWordPartRight(ctx) {
    const candidates = enforceDefined([
      WordOperations.deleteWordRight(
        ctx,
        0
        /* WordStart */
      ),
      WordOperations.deleteWordRight(
        ctx,
        2
        /* WordEnd */
      ),
      WordOperations._deleteWordPartRight(ctx.model, ctx.selection)
    ]);
    candidates.sort(range.Range.compareRangesUsingStarts);
    return candidates[0];
  }
  static moveWordPartLeft(wordSeparators, model, position$1) {
    const candidates = enforceDefined([
      WordOperations.moveWordLeft(
        wordSeparators,
        model,
        position$1,
        0
        /* WordStart */
      ),
      WordOperations.moveWordLeft(
        wordSeparators,
        model,
        position$1,
        2
        /* WordEnd */
      ),
      WordOperations._moveWordPartLeft(model, position$1)
    ]);
    candidates.sort(position.Position.compare);
    return candidates[2];
  }
  static moveWordPartRight(wordSeparators, model, position$1) {
    const candidates = enforceDefined([
      WordOperations.moveWordRight(
        wordSeparators,
        model,
        position$1,
        0
        /* WordStart */
      ),
      WordOperations.moveWordRight(
        wordSeparators,
        model,
        position$1,
        2
        /* WordEnd */
      ),
      WordOperations._moveWordPartRight(model, position$1)
    ]);
    candidates.sort(position.Position.compare);
    return candidates[0];
  }
}
function enforceDefined(arr) {
  return arr.filter((el) => Boolean(el));
}
exports.WordOperations = WordOperations;
exports.WordPartOperations = WordPartOperations;
