"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const lifecycle = require("../../../../base/common/lifecycle.js");
class OvertypingCapturer {
  constructor(editor, suggestModel) {
    this._disposables = new lifecycle.DisposableStore();
    this._lastOvertyped = [];
    this._empty = true;
    this._disposables.add(editor.onWillType(() => {
      if (!this._empty) {
        return;
      }
      if (!editor.hasModel()) {
        return;
      }
      const selections = editor.getSelections();
      const selectionsLength = selections.length;
      let willOvertype = false;
      for (let i = 0; i < selectionsLength; i++) {
        if (!selections[i].isEmpty()) {
          willOvertype = true;
          break;
        }
      }
      if (!willOvertype) {
        return;
      }
      this._lastOvertyped = [];
      const model = editor.getModel();
      for (let i = 0; i < selectionsLength; i++) {
        const selection = selections[i];
        if (model.getValueLengthInRange(selection) > OvertypingCapturer._maxSelectionLength) {
          return;
        }
        this._lastOvertyped[i] = { value: model.getValueInRange(selection), multiline: selection.startLineNumber !== selection.endLineNumber };
      }
      this._empty = false;
    }));
    this._disposables.add(suggestModel.onDidCancel((e) => {
      if (!this._empty && !e.retrigger) {
        this._empty = true;
      }
    }));
  }
  getLastOvertypedInfo(idx) {
    if (!this._empty && idx >= 0 && idx < this._lastOvertyped.length) {
      return this._lastOvertyped[idx];
    }
    return void 0;
  }
  dispose() {
    this._disposables.dispose();
  }
}
OvertypingCapturer._maxSelectionLength = 51200;
exports.OvertypingCapturer = OvertypingCapturer;
