"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../services/markerDecorations.js");
require("./media/editor.css.js");
const nls = require("../../../nls.js");
const dom = require("../../../base/browser/dom.js");
const errors = require("../../../base/common/errors.js");
const event = require("../../../base/common/event.js");
const lifecycle = require("../../../base/common/lifecycle.js");
const network = require("../../../base/common/network.js");
const editorConfiguration = require("../config/editorConfiguration.js");
const editorExtensions = require("../editorExtensions.js");
const codeEditorService = require("../services/codeEditorService.js");
const view = require("../view.js");
const viewUserInputEvents = require("../view/viewUserInputEvents.js");
const editorOptions = require("../../common/config/editorOptions.js");
const cursor = require("../../common/cursor/cursor.js");
const cursorColumns = require("../../common/core/cursorColumns.js");
const position = require("../../common/core/position.js");
const range = require("../../common/core/range.js");
const selection = require("../../common/core/selection.js");
const editorAction = require("../../common/editorAction.js");
const editorCommon = require("../../common/editorCommon.js");
const editorContextKeys = require("../../common/editorContextKeys.js");
const editorColorRegistry = require("../../common/core/editorColorRegistry.js");
const colorRegistry = require("../../../platform/theme/common/colorRegistry.js");
const viewModelImpl = require("../../common/viewModel/viewModelImpl.js");
const commands = require("../../../platform/commands/common/commands.js");
const contextkey = require("../../../platform/contextkey/common/contextkey.js");
const instantiation = require("../../../platform/instantiation/common/instantiation.js");
const serviceCollection = require("../../../platform/instantiation/common/serviceCollection.js");
const notification = require("../../../platform/notification/common/notification.js");
const themeService = require("../../../platform/theme/common/themeService.js");
const accessibility = require("../../../platform/accessibility/common/accessibility.js");
const types = require("../../../base/common/types.js");
const monospaceLineBreaksComputer = require("../../common/viewModel/monospaceLineBreaksComputer.js");
const domLineBreaksComputer = require("../view/domLineBreaksComputer.js");
const cursorWordOperations = require("../../common/cursor/cursorWordOperations.js");
const languageConfigurationRegistry = require("../../common/languages/languageConfigurationRegistry.js");
const domFontInfo = require("../config/domFontInfo.js");
const languageFeatures = require("../../common/services/languageFeatures.js");
var __decorate = globalThis && globalThis.__decorate || function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1; i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = globalThis && globalThis.__param || function(paramIndex, decorator) {
  return function(target, key) {
    decorator(target, key, paramIndex);
  };
};
let EDITOR_ID = 0;
class ModelData {
  constructor(model, viewModel, view2, hasRealView, listenersToRemove) {
    this.model = model;
    this.viewModel = viewModel;
    this.view = view2;
    this.hasRealView = hasRealView;
    this.listenersToRemove = listenersToRemove;
  }
  dispose() {
    lifecycle.dispose(this.listenersToRemove);
    this.model.onBeforeDetached();
    if (this.hasRealView) {
      this.view.dispose();
    }
    this.viewModel.dispose();
  }
}
exports.CodeEditorWidget = class CodeEditorWidget extends lifecycle.Disposable {
  constructor(domElement, _options, codeEditorWidgetOptions, instantiationService, codeEditorService2, commandService, contextKeyService, themeService2, notificationService, accessibilityService, languageConfigurationService, languageFeaturesService) {
    super();
    this.languageConfigurationService = languageConfigurationService;
    this._onDidDispose = this._register(new event.Emitter());
    this.onDidDispose = this._onDidDispose.event;
    this._onDidChangeModelContent = this._register(new event.Emitter());
    this.onDidChangeModelContent = this._onDidChangeModelContent.event;
    this._onDidChangeModelLanguage = this._register(new event.Emitter());
    this.onDidChangeModelLanguage = this._onDidChangeModelLanguage.event;
    this._onDidChangeModelLanguageConfiguration = this._register(new event.Emitter());
    this.onDidChangeModelLanguageConfiguration = this._onDidChangeModelLanguageConfiguration.event;
    this._onDidChangeModelOptions = this._register(new event.Emitter());
    this.onDidChangeModelOptions = this._onDidChangeModelOptions.event;
    this._onDidChangeModelDecorations = this._register(new event.Emitter());
    this.onDidChangeModelDecorations = this._onDidChangeModelDecorations.event;
    this._onDidChangeConfiguration = this._register(new event.Emitter());
    this.onDidChangeConfiguration = this._onDidChangeConfiguration.event;
    this._onDidChangeModel = this._register(new event.Emitter());
    this.onDidChangeModel = this._onDidChangeModel.event;
    this._onDidChangeCursorPosition = this._register(new event.Emitter());
    this.onDidChangeCursorPosition = this._onDidChangeCursorPosition.event;
    this._onDidChangeCursorSelection = this._register(new event.Emitter());
    this.onDidChangeCursorSelection = this._onDidChangeCursorSelection.event;
    this._onDidAttemptReadOnlyEdit = this._register(new event.Emitter());
    this.onDidAttemptReadOnlyEdit = this._onDidAttemptReadOnlyEdit.event;
    this._onDidLayoutChange = this._register(new event.Emitter());
    this.onDidLayoutChange = this._onDidLayoutChange.event;
    this._editorTextFocus = this._register(new BooleanEventEmitter());
    this.onDidFocusEditorText = this._editorTextFocus.onDidChangeToTrue;
    this.onDidBlurEditorText = this._editorTextFocus.onDidChangeToFalse;
    this._editorWidgetFocus = this._register(new BooleanEventEmitter());
    this.onDidFocusEditorWidget = this._editorWidgetFocus.onDidChangeToTrue;
    this.onDidBlurEditorWidget = this._editorWidgetFocus.onDidChangeToFalse;
    this._onWillType = this._register(new event.Emitter());
    this.onWillType = this._onWillType.event;
    this._onDidType = this._register(new event.Emitter());
    this.onDidType = this._onDidType.event;
    this._onDidCompositionStart = this._register(new event.Emitter());
    this.onDidCompositionStart = this._onDidCompositionStart.event;
    this._onDidCompositionEnd = this._register(new event.Emitter());
    this.onDidCompositionEnd = this._onDidCompositionEnd.event;
    this._onDidPaste = this._register(new event.Emitter());
    this.onDidPaste = this._onDidPaste.event;
    this._onMouseUp = this._register(new event.Emitter());
    this.onMouseUp = this._onMouseUp.event;
    this._onMouseDown = this._register(new event.Emitter());
    this.onMouseDown = this._onMouseDown.event;
    this._onMouseDrag = this._register(new event.Emitter());
    this.onMouseDrag = this._onMouseDrag.event;
    this._onMouseDrop = this._register(new event.Emitter());
    this.onMouseDrop = this._onMouseDrop.event;
    this._onMouseDropCanceled = this._register(new event.Emitter());
    this.onMouseDropCanceled = this._onMouseDropCanceled.event;
    this._onContextMenu = this._register(new event.Emitter());
    this.onContextMenu = this._onContextMenu.event;
    this._onMouseMove = this._register(new event.Emitter());
    this.onMouseMove = this._onMouseMove.event;
    this._onMouseLeave = this._register(new event.Emitter());
    this.onMouseLeave = this._onMouseLeave.event;
    this._onMouseWheel = this._register(new event.Emitter());
    this.onMouseWheel = this._onMouseWheel.event;
    this._onKeyUp = this._register(new event.Emitter());
    this.onKeyUp = this._onKeyUp.event;
    this._onKeyDown = this._register(new event.Emitter());
    this.onKeyDown = this._onKeyDown.event;
    this._onDidContentSizeChange = this._register(new event.Emitter());
    this.onDidContentSizeChange = this._onDidContentSizeChange.event;
    this._onDidScrollChange = this._register(new event.Emitter());
    this.onDidScrollChange = this._onDidScrollChange.event;
    this._onDidChangeViewZones = this._register(new event.Emitter());
    this.onDidChangeViewZones = this._onDidChangeViewZones.event;
    this._onDidChangeHiddenAreas = this._register(new event.Emitter());
    this.onDidChangeHiddenAreas = this._onDidChangeHiddenAreas.event;
    this._bannerDomNode = null;
    const options = Object.assign({}, _options);
    this._domElement = domElement;
    this._overflowWidgetsDomNode = options.overflowWidgetsDomNode;
    delete options.overflowWidgetsDomNode;
    this._id = ++EDITOR_ID;
    this._decorationTypeKeysToIds = {};
    this._decorationTypeSubtypes = {};
    this._telemetryData = codeEditorWidgetOptions.telemetryData;
    this._configuration = this._register(this._createConfiguration(codeEditorWidgetOptions.isSimpleWidget || false, options, accessibilityService));
    this._register(this._configuration.onDidChange((e) => {
      this._onDidChangeConfiguration.fire(e);
      const options2 = this._configuration.options;
      if (e.hasChanged(
        131
        /* layoutInfo */
      )) {
        const layoutInfo = options2.get(
          131
          /* layoutInfo */
        );
        this._onDidLayoutChange.fire(layoutInfo);
      }
    }));
    this._contextKeyService = this._register(contextKeyService.createScoped(this._domElement));
    this._notificationService = notificationService;
    this._codeEditorService = codeEditorService2;
    this._commandService = commandService;
    this._themeService = themeService2;
    this._register(new EditorContextKeysManager(this, this._contextKeyService));
    this._register(new EditorModeContext(this, this._contextKeyService, languageFeaturesService));
    this._instantiationService = instantiationService.createChild(new serviceCollection.ServiceCollection([contextkey.IContextKeyService, this._contextKeyService]));
    this._modelData = null;
    this._contributions = {};
    this._actions = {};
    this._focusTracker = new CodeEditorWidgetFocusTracker(domElement);
    this._register(this._focusTracker.onChange(() => {
      this._editorWidgetFocus.setValue(this._focusTracker.hasFocus());
    }));
    this._contentWidgets = {};
    this._overlayWidgets = {};
    let contributions;
    if (Array.isArray(codeEditorWidgetOptions.contributions)) {
      contributions = codeEditorWidgetOptions.contributions;
    } else {
      contributions = editorExtensions.EditorExtensionsRegistry.getEditorContributions();
    }
    for (const desc of contributions) {
      if (this._contributions[desc.id]) {
        errors.onUnexpectedError(new Error(`Cannot have two contributions with the same id ${desc.id}`));
        continue;
      }
      try {
        const contribution = this._instantiationService.createInstance(desc.ctor, this);
        this._contributions[desc.id] = contribution;
      } catch (err) {
        errors.onUnexpectedError(err);
      }
    }
    editorExtensions.EditorExtensionsRegistry.getEditorActions().forEach((action) => {
      if (this._actions[action.id]) {
        errors.onUnexpectedError(new Error(`Cannot have two actions with the same id ${action.id}`));
        return;
      }
      const internalAction = new editorAction.InternalEditorAction(action.id, action.label, action.alias, types.withNullAsUndefined(action.precondition), () => {
        return this._instantiationService.invokeFunction((accessor) => {
          return Promise.resolve(action.runEditorCommand(accessor, this, null));
        });
      }, this._contextKeyService);
      this._actions[internalAction.id] = internalAction;
    });
    this._codeEditorService.addCodeEditor(this);
  }
  //#endregion
  get isSimpleWidget() {
    return this._configuration.isSimpleWidget;
  }
  _createConfiguration(isSimpleWidget, options, accessibilityService) {
    return new editorConfiguration.EditorConfiguration(isSimpleWidget, options, this._domElement, accessibilityService);
  }
  getId() {
    return this.getEditorType() + ":" + this._id;
  }
  getEditorType() {
    return editorCommon.EditorType.ICodeEditor;
  }
  dispose() {
    this._codeEditorService.removeCodeEditor(this);
    this._focusTracker.dispose();
    const keys = Object.keys(this._contributions);
    for (let i = 0, len = keys.length; i < len; i++) {
      const contributionId = keys[i];
      this._contributions[contributionId].dispose();
    }
    this._contributions = {};
    this._actions = {};
    this._contentWidgets = {};
    this._overlayWidgets = {};
    this._removeDecorationTypes();
    this._postDetachModelCleanup(this._detachModel());
    this._onDidDispose.fire();
    super.dispose();
  }
  invokeWithinContext(fn) {
    return this._instantiationService.invokeFunction(fn);
  }
  updateOptions(newOptions) {
    this._configuration.updateOptions(newOptions || {});
  }
  getOptions() {
    return this._configuration.options;
  }
  getOption(id) {
    return this._configuration.options.get(id);
  }
  getRawOptions() {
    return this._configuration.getRawOptions();
  }
  getOverflowWidgetsDomNode() {
    return this._overflowWidgetsDomNode;
  }
  getConfiguredWordAtPosition(position2) {
    if (!this._modelData) {
      return null;
    }
    return cursorWordOperations.WordOperations.getWordAtPosition(this._modelData.model, this._configuration.options.get(
      117
      /* wordSeparators */
    ), position2);
  }
  getValue(options = null) {
    if (!this._modelData) {
      return "";
    }
    const preserveBOM = options && options.preserveBOM ? true : false;
    let eolPreference = 0;
    if (options && options.lineEnding && options.lineEnding === "\n") {
      eolPreference = 1;
    } else if (options && options.lineEnding && options.lineEnding === "\r\n") {
      eolPreference = 2;
    }
    return this._modelData.model.getValue(eolPreference, preserveBOM);
  }
  setValue(newValue) {
    if (!this._modelData) {
      return;
    }
    this._modelData.model.setValue(newValue);
  }
  getModel() {
    if (!this._modelData) {
      return null;
    }
    return this._modelData.model;
  }
  setModel(_model = null) {
    const model = _model;
    if (this._modelData === null && model === null) {
      return;
    }
    if (this._modelData && this._modelData.model === model) {
      return;
    }
    const hasTextFocus = this.hasTextFocus();
    const detachedModel = this._detachModel();
    this._attachModel(model);
    if (hasTextFocus && this.hasModel()) {
      this.focus();
    }
    const e = {
      oldModelUrl: detachedModel ? detachedModel.uri : null,
      newModelUrl: model ? model.uri : null
    };
    this._removeDecorationTypes();
    this._onDidChangeModel.fire(e);
    this._postDetachModelCleanup(detachedModel);
  }
  _removeDecorationTypes() {
    this._decorationTypeKeysToIds = {};
    if (this._decorationTypeSubtypes) {
      for (let decorationType in this._decorationTypeSubtypes) {
        const subTypes = this._decorationTypeSubtypes[decorationType];
        for (let subType in subTypes) {
          this._removeDecorationType(decorationType + "-" + subType);
        }
      }
      this._decorationTypeSubtypes = {};
    }
  }
  getVisibleRanges() {
    if (!this._modelData) {
      return [];
    }
    return this._modelData.viewModel.getVisibleRanges();
  }
  getVisibleRangesPlusViewportAboveBelow() {
    if (!this._modelData) {
      return [];
    }
    return this._modelData.viewModel.getVisibleRangesPlusViewportAboveBelow();
  }
  getWhitespaces() {
    if (!this._modelData) {
      return [];
    }
    return this._modelData.viewModel.viewLayout.getWhitespaces();
  }
  static _getVerticalOffsetForPosition(modelData, modelLineNumber, modelColumn) {
    const modelPosition = modelData.model.validatePosition({
      lineNumber: modelLineNumber,
      column: modelColumn
    });
    const viewPosition = modelData.viewModel.coordinatesConverter.convertModelPositionToViewPosition(modelPosition);
    return modelData.viewModel.viewLayout.getVerticalOffsetForLineNumber(viewPosition.lineNumber);
  }
  getTopForLineNumber(lineNumber) {
    if (!this._modelData) {
      return -1;
    }
    return CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, lineNumber, 1);
  }
  getTopForPosition(lineNumber, column) {
    if (!this._modelData) {
      return -1;
    }
    return CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, lineNumber, column);
  }
  setHiddenAreas(ranges) {
    if (this._modelData) {
      this._modelData.viewModel.setHiddenAreas(ranges.map((r) => range.Range.lift(r)));
    }
  }
  getVisibleColumnFromPosition(rawPosition) {
    if (!this._modelData) {
      return rawPosition.column;
    }
    const position2 = this._modelData.model.validatePosition(rawPosition);
    const tabSize = this._modelData.model.getOptions().tabSize;
    return cursorColumns.CursorColumns.visibleColumnFromColumn(this._modelData.model.getLineContent(position2.lineNumber), position2.column, tabSize) + 1;
  }
  getPosition() {
    if (!this._modelData) {
      return null;
    }
    return this._modelData.viewModel.getPosition();
  }
  setPosition(position$1, source = "api") {
    if (!this._modelData) {
      return;
    }
    if (!position.Position.isIPosition(position$1)) {
      throw new Error("Invalid arguments");
    }
    this._modelData.viewModel.setSelections(source, [{
      selectionStartLineNumber: position$1.lineNumber,
      selectionStartColumn: position$1.column,
      positionLineNumber: position$1.lineNumber,
      positionColumn: position$1.column
    }]);
  }
  _sendRevealRange(modelRange, verticalType, revealHorizontal, scrollType) {
    if (!this._modelData) {
      return;
    }
    if (!range.Range.isIRange(modelRange)) {
      throw new Error("Invalid arguments");
    }
    const validatedModelRange = this._modelData.model.validateRange(modelRange);
    const viewRange = this._modelData.viewModel.coordinatesConverter.convertModelRangeToViewRange(validatedModelRange);
    this._modelData.viewModel.revealRange("api", revealHorizontal, viewRange, verticalType, scrollType);
  }
  revealLine(lineNumber, scrollType = 0) {
    this._revealLine(lineNumber, 0, scrollType);
  }
  revealLineInCenter(lineNumber, scrollType = 0) {
    this._revealLine(lineNumber, 1, scrollType);
  }
  revealLineInCenterIfOutsideViewport(lineNumber, scrollType = 0) {
    this._revealLine(lineNumber, 2, scrollType);
  }
  revealLineNearTop(lineNumber, scrollType = 0) {
    this._revealLine(lineNumber, 5, scrollType);
  }
  _revealLine(lineNumber, revealType, scrollType) {
    if (typeof lineNumber !== "number") {
      throw new Error("Invalid arguments");
    }
    this._sendRevealRange(new range.Range(lineNumber, 1, lineNumber, 1), revealType, false, scrollType);
  }
  revealPosition(position2, scrollType = 0) {
    this._revealPosition(position2, 0, true, scrollType);
  }
  revealPositionInCenter(position2, scrollType = 0) {
    this._revealPosition(position2, 1, true, scrollType);
  }
  revealPositionInCenterIfOutsideViewport(position2, scrollType = 0) {
    this._revealPosition(position2, 2, true, scrollType);
  }
  revealPositionNearTop(position2, scrollType = 0) {
    this._revealPosition(position2, 5, true, scrollType);
  }
  _revealPosition(position$1, verticalType, revealHorizontal, scrollType) {
    if (!position.Position.isIPosition(position$1)) {
      throw new Error("Invalid arguments");
    }
    this._sendRevealRange(new range.Range(position$1.lineNumber, position$1.column, position$1.lineNumber, position$1.column), verticalType, revealHorizontal, scrollType);
  }
  getSelection() {
    if (!this._modelData) {
      return null;
    }
    return this._modelData.viewModel.getSelection();
  }
  getSelections() {
    if (!this._modelData) {
      return null;
    }
    return this._modelData.viewModel.getSelections();
  }
  setSelection(something, source = "api") {
    const isSelection = selection.Selection.isISelection(something);
    const isRange = range.Range.isIRange(something);
    if (!isSelection && !isRange) {
      throw new Error("Invalid arguments");
    }
    if (isSelection) {
      this._setSelectionImpl(something, source);
    } else if (isRange) {
      const selection2 = {
        selectionStartLineNumber: something.startLineNumber,
        selectionStartColumn: something.startColumn,
        positionLineNumber: something.endLineNumber,
        positionColumn: something.endColumn
      };
      this._setSelectionImpl(selection2, source);
    }
  }
  _setSelectionImpl(sel, source) {
    if (!this._modelData) {
      return;
    }
    const selection$1 = new selection.Selection(sel.selectionStartLineNumber, sel.selectionStartColumn, sel.positionLineNumber, sel.positionColumn);
    this._modelData.viewModel.setSelections(source, [selection$1]);
  }
  revealLines(startLineNumber, endLineNumber, scrollType = 0) {
    this._revealLines(startLineNumber, endLineNumber, 0, scrollType);
  }
  revealLinesInCenter(startLineNumber, endLineNumber, scrollType = 0) {
    this._revealLines(startLineNumber, endLineNumber, 1, scrollType);
  }
  revealLinesInCenterIfOutsideViewport(startLineNumber, endLineNumber, scrollType = 0) {
    this._revealLines(startLineNumber, endLineNumber, 2, scrollType);
  }
  revealLinesNearTop(startLineNumber, endLineNumber, scrollType = 0) {
    this._revealLines(startLineNumber, endLineNumber, 5, scrollType);
  }
  _revealLines(startLineNumber, endLineNumber, verticalType, scrollType) {
    if (typeof startLineNumber !== "number" || typeof endLineNumber !== "number") {
      throw new Error("Invalid arguments");
    }
    this._sendRevealRange(new range.Range(startLineNumber, 1, endLineNumber, 1), verticalType, false, scrollType);
  }
  revealRange(range2, scrollType = 0, revealVerticalInCenter = false, revealHorizontal = true) {
    this._revealRange(range2, revealVerticalInCenter ? 1 : 0, revealHorizontal, scrollType);
  }
  revealRangeInCenter(range2, scrollType = 0) {
    this._revealRange(range2, 1, true, scrollType);
  }
  revealRangeInCenterIfOutsideViewport(range2, scrollType = 0) {
    this._revealRange(range2, 2, true, scrollType);
  }
  revealRangeNearTop(range2, scrollType = 0) {
    this._revealRange(range2, 5, true, scrollType);
  }
  revealRangeNearTopIfOutsideViewport(range2, scrollType = 0) {
    this._revealRange(range2, 6, true, scrollType);
  }
  revealRangeAtTop(range2, scrollType = 0) {
    this._revealRange(range2, 3, true, scrollType);
  }
  _revealRange(range$1, verticalType, revealHorizontal, scrollType) {
    if (!range.Range.isIRange(range$1)) {
      throw new Error("Invalid arguments");
    }
    this._sendRevealRange(range.Range.lift(range$1), verticalType, revealHorizontal, scrollType);
  }
  setSelections(ranges, source = "api", reason = 0) {
    if (!this._modelData) {
      return;
    }
    if (!ranges || ranges.length === 0) {
      throw new Error("Invalid arguments");
    }
    for (let i = 0, len = ranges.length; i < len; i++) {
      if (!selection.Selection.isISelection(ranges[i])) {
        throw new Error("Invalid arguments");
      }
    }
    this._modelData.viewModel.setSelections(source, ranges, reason);
  }
  getContentWidth() {
    if (!this._modelData) {
      return -1;
    }
    return this._modelData.viewModel.viewLayout.getContentWidth();
  }
  getScrollWidth() {
    if (!this._modelData) {
      return -1;
    }
    return this._modelData.viewModel.viewLayout.getScrollWidth();
  }
  getScrollLeft() {
    if (!this._modelData) {
      return -1;
    }
    return this._modelData.viewModel.viewLayout.getCurrentScrollLeft();
  }
  getContentHeight() {
    if (!this._modelData) {
      return -1;
    }
    return this._modelData.viewModel.viewLayout.getContentHeight();
  }
  getScrollHeight() {
    if (!this._modelData) {
      return -1;
    }
    return this._modelData.viewModel.viewLayout.getScrollHeight();
  }
  getScrollTop() {
    if (!this._modelData) {
      return -1;
    }
    return this._modelData.viewModel.viewLayout.getCurrentScrollTop();
  }
  setScrollLeft(newScrollLeft, scrollType = 1) {
    if (!this._modelData) {
      return;
    }
    if (typeof newScrollLeft !== "number") {
      throw new Error("Invalid arguments");
    }
    this._modelData.viewModel.viewLayout.setScrollPosition({
      scrollLeft: newScrollLeft
    }, scrollType);
  }
  setScrollTop(newScrollTop, scrollType = 1) {
    if (!this._modelData) {
      return;
    }
    if (typeof newScrollTop !== "number") {
      throw new Error("Invalid arguments");
    }
    this._modelData.viewModel.viewLayout.setScrollPosition({
      scrollTop: newScrollTop
    }, scrollType);
  }
  setScrollPosition(position2, scrollType = 1) {
    if (!this._modelData) {
      return;
    }
    this._modelData.viewModel.viewLayout.setScrollPosition(position2, scrollType);
  }
  saveViewState() {
    if (!this._modelData) {
      return null;
    }
    const contributionsState = {};
    const keys = Object.keys(this._contributions);
    for (const id of keys) {
      const contribution = this._contributions[id];
      if (typeof contribution.saveViewState === "function") {
        contributionsState[id] = contribution.saveViewState();
      }
    }
    const cursorState = this._modelData.viewModel.saveCursorState();
    const viewState = this._modelData.viewModel.saveState();
    return {
      cursorState,
      viewState,
      contributionsState
    };
  }
  restoreViewState(s) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return;
    }
    const codeEditorState = s;
    if (codeEditorState && codeEditorState.cursorState && codeEditorState.viewState) {
      const cursorState = codeEditorState.cursorState;
      if (Array.isArray(cursorState)) {
        if (cursorState.length > 0) {
          this._modelData.viewModel.restoreCursorState(cursorState);
        }
      } else {
        this._modelData.viewModel.restoreCursorState([cursorState]);
      }
      const contributionsState = codeEditorState.contributionsState || {};
      const keys = Object.keys(this._contributions);
      for (let i = 0, len = keys.length; i < len; i++) {
        const id = keys[i];
        const contribution = this._contributions[id];
        if (typeof contribution.restoreViewState === "function") {
          contribution.restoreViewState(contributionsState[id]);
        }
      }
      const reducedState = this._modelData.viewModel.reduceRestoreState(codeEditorState.viewState);
      this._modelData.view.restoreState(reducedState);
    }
  }
  getContribution(id) {
    return this._contributions[id] || null;
  }
  getActions() {
    const result = [];
    const keys = Object.keys(this._actions);
    for (let i = 0, len = keys.length; i < len; i++) {
      const id = keys[i];
      result.push(this._actions[id]);
    }
    return result;
  }
  getSupportedActions() {
    let result = this.getActions();
    result = result.filter((action) => action.isSupported());
    return result;
  }
  getAction(id) {
    return this._actions[id] || null;
  }
  trigger(source, handlerId, payload) {
    payload = payload || {};
    switch (handlerId) {
      case "compositionStart":
        this._startComposition();
        return;
      case "compositionEnd":
        this._endComposition(source);
        return;
      case "type": {
        const args = payload;
        this._type(source, args.text || "");
        return;
      }
      case "replacePreviousChar": {
        const args = payload;
        this._compositionType(source, args.text || "", args.replaceCharCnt || 0, 0, 0);
        return;
      }
      case "compositionType": {
        const args = payload;
        this._compositionType(source, args.text || "", args.replacePrevCharCnt || 0, args.replaceNextCharCnt || 0, args.positionDelta || 0);
        return;
      }
      case "paste": {
        const args = payload;
        this._paste(source, args.text || "", args.pasteOnNewLine || false, args.multicursorText || null, args.mode || null);
        return;
      }
      case "cut":
        this._cut(source);
        return;
    }
    const action = this.getAction(handlerId);
    if (action) {
      Promise.resolve(action.run()).then(void 0, errors.onUnexpectedError);
      return;
    }
    if (!this._modelData) {
      return;
    }
    if (this._triggerEditorCommand(source, handlerId, payload)) {
      return;
    }
    this._triggerCommand(handlerId, payload);
  }
  _triggerCommand(handlerId, payload) {
    this._commandService.executeCommand(handlerId, payload);
  }
  _startComposition() {
    if (!this._modelData) {
      return;
    }
    this._modelData.viewModel.startComposition();
    this._onDidCompositionStart.fire();
  }
  _endComposition(source) {
    if (!this._modelData) {
      return;
    }
    this._modelData.viewModel.endComposition(source);
    this._onDidCompositionEnd.fire();
  }
  _type(source, text) {
    if (!this._modelData || text.length === 0) {
      return;
    }
    if (source === "keyboard") {
      this._onWillType.fire(text);
    }
    this._modelData.viewModel.type(text, source);
    if (source === "keyboard") {
      this._onDidType.fire(text);
    }
  }
  _compositionType(source, text, replacePrevCharCnt, replaceNextCharCnt, positionDelta) {
    if (!this._modelData) {
      return;
    }
    this._modelData.viewModel.compositionType(text, replacePrevCharCnt, replaceNextCharCnt, positionDelta, source);
  }
  _paste(source, text, pasteOnNewLine, multicursorText, mode) {
    if (!this._modelData || text.length === 0) {
      return;
    }
    const startPosition = this._modelData.viewModel.getSelection().getStartPosition();
    this._modelData.viewModel.paste(text, pasteOnNewLine, multicursorText, source);
    const endPosition = this._modelData.viewModel.getSelection().getStartPosition();
    if (source === "keyboard") {
      this._onDidPaste.fire({
        range: new range.Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column),
        languageId: mode
      });
    }
  }
  _cut(source) {
    if (!this._modelData) {
      return;
    }
    this._modelData.viewModel.cut(source);
  }
  _triggerEditorCommand(source, handlerId, payload) {
    const command = editorExtensions.EditorExtensionsRegistry.getEditorCommand(handlerId);
    if (command) {
      payload = payload || {};
      payload.source = source;
      this._instantiationService.invokeFunction((accessor) => {
        Promise.resolve(command.runEditorCommand(accessor, this, payload)).then(void 0, errors.onUnexpectedError);
      });
      return true;
    }
    return false;
  }
  _getViewModel() {
    if (!this._modelData) {
      return null;
    }
    return this._modelData.viewModel;
  }
  pushUndoStop() {
    if (!this._modelData) {
      return false;
    }
    if (this._configuration.options.get(
      81
      /* readOnly */
    )) {
      return false;
    }
    this._modelData.model.pushStackElement();
    return true;
  }
  popUndoStop() {
    if (!this._modelData) {
      return false;
    }
    if (this._configuration.options.get(
      81
      /* readOnly */
    )) {
      return false;
    }
    this._modelData.model.popStackElement();
    return true;
  }
  executeEdits(source, edits, endCursorState) {
    if (!this._modelData) {
      return false;
    }
    if (this._configuration.options.get(
      81
      /* readOnly */
    )) {
      return false;
    }
    let cursorStateComputer;
    if (!endCursorState) {
      cursorStateComputer = () => null;
    } else if (Array.isArray(endCursorState)) {
      cursorStateComputer = () => endCursorState;
    } else {
      cursorStateComputer = endCursorState;
    }
    this._modelData.viewModel.executeEdits(source, edits, cursorStateComputer);
    return true;
  }
  executeCommand(source, command) {
    if (!this._modelData) {
      return;
    }
    this._modelData.viewModel.executeCommand(command, source);
  }
  executeCommands(source, commands2) {
    if (!this._modelData) {
      return;
    }
    this._modelData.viewModel.executeCommands(commands2, source);
  }
  changeDecorations(callback) {
    if (!this._modelData) {
      return null;
    }
    return this._modelData.model.changeDecorations(callback, this._id);
  }
  getLineDecorations(lineNumber) {
    if (!this._modelData) {
      return null;
    }
    return this._modelData.model.getLineDecorations(lineNumber, this._id, editorOptions.filterValidationDecorations(this._configuration.options));
  }
  getDecorationsInRange(range2) {
    if (!this._modelData) {
      return null;
    }
    return this._modelData.model.getDecorationsInRange(range2, this._id, editorOptions.filterValidationDecorations(this._configuration.options));
  }
  deltaDecorations(oldDecorations, newDecorations) {
    if (!this._modelData) {
      return [];
    }
    if (oldDecorations.length === 0 && newDecorations.length === 0) {
      return oldDecorations;
    }
    return this._modelData.model.deltaDecorations(oldDecorations, newDecorations, this._id);
  }
  removeDecorations(decorationTypeKey) {
    const oldDecorationsIds = this._decorationTypeKeysToIds[decorationTypeKey];
    if (oldDecorationsIds) {
      this.deltaDecorations(oldDecorationsIds, []);
    }
    if (this._decorationTypeKeysToIds.hasOwnProperty(decorationTypeKey)) {
      delete this._decorationTypeKeysToIds[decorationTypeKey];
    }
    if (this._decorationTypeSubtypes.hasOwnProperty(decorationTypeKey)) {
      delete this._decorationTypeSubtypes[decorationTypeKey];
    }
  }
  getLayoutInfo() {
    const options = this._configuration.options;
    const layoutInfo = options.get(
      131
      /* layoutInfo */
    );
    return layoutInfo;
  }
  createOverviewRuler(cssClassName) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return null;
    }
    return this._modelData.view.createOverviewRuler(cssClassName);
  }
  getContainerDomNode() {
    return this._domElement;
  }
  getDomNode() {
    if (!this._modelData || !this._modelData.hasRealView) {
      return null;
    }
    return this._modelData.view.domNode.domNode;
  }
  delegateVerticalScrollbarMouseDown(browserEvent) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return;
    }
    this._modelData.view.delegateVerticalScrollbarMouseDown(browserEvent);
  }
  layout(dimension) {
    this._configuration.observeContainer(dimension);
    this.render();
  }
  focus() {
    if (!this._modelData || !this._modelData.hasRealView) {
      return;
    }
    this._modelData.view.focus();
  }
  hasTextFocus() {
    if (!this._modelData || !this._modelData.hasRealView) {
      return false;
    }
    return this._modelData.view.isFocused();
  }
  hasWidgetFocus() {
    return this._focusTracker && this._focusTracker.hasFocus();
  }
  addContentWidget(widget) {
    const widgetData = {
      widget,
      position: widget.getPosition()
    };
    if (this._contentWidgets.hasOwnProperty(widget.getId())) {
      console.warn("Overwriting a content widget with the same id.");
    }
    this._contentWidgets[widget.getId()] = widgetData;
    if (this._modelData && this._modelData.hasRealView) {
      this._modelData.view.addContentWidget(widgetData);
    }
  }
  layoutContentWidget(widget) {
    const widgetId = widget.getId();
    if (this._contentWidgets.hasOwnProperty(widgetId)) {
      const widgetData = this._contentWidgets[widgetId];
      widgetData.position = widget.getPosition();
      if (this._modelData && this._modelData.hasRealView) {
        this._modelData.view.layoutContentWidget(widgetData);
      }
    }
  }
  removeContentWidget(widget) {
    const widgetId = widget.getId();
    if (this._contentWidgets.hasOwnProperty(widgetId)) {
      const widgetData = this._contentWidgets[widgetId];
      delete this._contentWidgets[widgetId];
      if (this._modelData && this._modelData.hasRealView) {
        this._modelData.view.removeContentWidget(widgetData);
      }
    }
  }
  addOverlayWidget(widget) {
    const widgetData = {
      widget,
      position: widget.getPosition()
    };
    if (this._overlayWidgets.hasOwnProperty(widget.getId())) {
      console.warn("Overwriting an overlay widget with the same id.");
    }
    this._overlayWidgets[widget.getId()] = widgetData;
    if (this._modelData && this._modelData.hasRealView) {
      this._modelData.view.addOverlayWidget(widgetData);
    }
  }
  layoutOverlayWidget(widget) {
    const widgetId = widget.getId();
    if (this._overlayWidgets.hasOwnProperty(widgetId)) {
      const widgetData = this._overlayWidgets[widgetId];
      widgetData.position = widget.getPosition();
      if (this._modelData && this._modelData.hasRealView) {
        this._modelData.view.layoutOverlayWidget(widgetData);
      }
    }
  }
  removeOverlayWidget(widget) {
    const widgetId = widget.getId();
    if (this._overlayWidgets.hasOwnProperty(widgetId)) {
      const widgetData = this._overlayWidgets[widgetId];
      delete this._overlayWidgets[widgetId];
      if (this._modelData && this._modelData.hasRealView) {
        this._modelData.view.removeOverlayWidget(widgetData);
      }
    }
  }
  changeViewZones(callback) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return;
    }
    this._modelData.view.change(callback);
  }
  getTargetAtClientPoint(clientX, clientY) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return null;
    }
    return this._modelData.view.getTargetAtClientPoint(clientX, clientY);
  }
  getScrolledVisiblePosition(rawPosition) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return null;
    }
    const position2 = this._modelData.model.validatePosition(rawPosition);
    const options = this._configuration.options;
    const layoutInfo = options.get(
      131
      /* layoutInfo */
    );
    const top = CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, position2.lineNumber, position2.column) - this.getScrollTop();
    const left = this._modelData.view.getOffsetForColumn(position2.lineNumber, position2.column) + layoutInfo.glyphMarginWidth + layoutInfo.lineNumbersWidth + layoutInfo.decorationsWidth - this.getScrollLeft();
    return {
      top,
      left,
      height: options.get(
        59
        /* lineHeight */
      )
    };
  }
  getOffsetForColumn(lineNumber, column) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return -1;
    }
    return this._modelData.view.getOffsetForColumn(lineNumber, column);
  }
  render(forceRedraw = false) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return;
    }
    this._modelData.view.render(true, forceRedraw);
  }
  setAriaOptions(options) {
    if (!this._modelData || !this._modelData.hasRealView) {
      return;
    }
    this._modelData.view.setAriaOptions(options);
  }
  applyFontInfo(target) {
    domFontInfo.applyFontInfo(target, this._configuration.options.get(
      44
      /* fontInfo */
    ));
  }
  setBanner(domNode, domNodeHeight) {
    if (this._bannerDomNode && this._domElement.contains(this._bannerDomNode)) {
      this._domElement.removeChild(this._bannerDomNode);
    }
    this._bannerDomNode = domNode;
    this._configuration.setReservedHeight(domNode ? domNodeHeight : 0);
    if (this._bannerDomNode) {
      this._domElement.prepend(this._bannerDomNode);
    }
  }
  _attachModel(model) {
    if (!model) {
      this._modelData = null;
      return;
    }
    const listenersToRemove = [];
    this._domElement.setAttribute("data-mode-id", model.getLanguageId());
    this._configuration.setIsDominatedByLongLines(model.isDominatedByLongLines());
    this._configuration.setModelLineCount(model.getLineCount());
    model.onBeforeAttached();
    const viewModel = new viewModelImpl.ViewModel(this._id, this._configuration, model, domLineBreaksComputer.DOMLineBreaksComputerFactory.create(), monospaceLineBreaksComputer.MonospaceLineBreaksComputerFactory.create(this._configuration.options), (callback) => dom.scheduleAtNextAnimationFrame(callback), this.languageConfigurationService, this._themeService);
    listenersToRemove.push(model.onDidChangeDecorations((e) => this._onDidChangeModelDecorations.fire(e)));
    listenersToRemove.push(model.onDidChangeLanguage((e) => {
      this._domElement.setAttribute("data-mode-id", model.getLanguageId());
      this._onDidChangeModelLanguage.fire(e);
    }));
    listenersToRemove.push(model.onDidChangeLanguageConfiguration((e) => this._onDidChangeModelLanguageConfiguration.fire(e)));
    listenersToRemove.push(model.onDidChangeContent((e) => this._onDidChangeModelContent.fire(e)));
    listenersToRemove.push(model.onDidChangeOptions((e) => this._onDidChangeModelOptions.fire(e)));
    listenersToRemove.push(model.onWillDispose(() => this.setModel(null)));
    listenersToRemove.push(viewModel.onEvent((e) => {
      switch (e.kind) {
        case 0:
          this._onDidContentSizeChange.fire(e);
          break;
        case 1:
          this._editorTextFocus.setValue(e.hasFocus);
          break;
        case 2:
          this._onDidScrollChange.fire(e);
          break;
        case 3:
          this._onDidChangeViewZones.fire();
          break;
        case 4:
          this._onDidChangeHiddenAreas.fire();
          break;
        case 5:
          this._onDidAttemptReadOnlyEdit.fire();
          break;
        case 6: {
          if (e.reachedMaxCursorCount) {
            this._notificationService.warn(nls.localize("cursors.maximum", "The number of cursors has been limited to {0}.", cursor.CursorsController.MAX_CURSOR_COUNT));
          }
          const positions = [];
          for (let i = 0, len = e.selections.length; i < len; i++) {
            positions[i] = e.selections[i].getPosition();
          }
          const e1 = {
            position: positions[0],
            secondaryPositions: positions.slice(1),
            reason: e.reason,
            source: e.source
          };
          this._onDidChangeCursorPosition.fire(e1);
          const e2 = {
            selection: e.selections[0],
            secondarySelections: e.selections.slice(1),
            modelVersionId: e.modelVersionId,
            oldSelections: e.oldSelections,
            oldModelVersionId: e.oldModelVersionId,
            source: e.source,
            reason: e.reason
          };
          this._onDidChangeCursorSelection.fire(e2);
          break;
        }
      }
    }));
    const [view2, hasRealView] = this._createView(viewModel);
    if (hasRealView) {
      this._domElement.appendChild(view2.domNode.domNode);
      let keys = Object.keys(this._contentWidgets);
      for (let i = 0, len = keys.length; i < len; i++) {
        const widgetId = keys[i];
        view2.addContentWidget(this._contentWidgets[widgetId]);
      }
      keys = Object.keys(this._overlayWidgets);
      for (let i = 0, len = keys.length; i < len; i++) {
        const widgetId = keys[i];
        view2.addOverlayWidget(this._overlayWidgets[widgetId]);
      }
      view2.render(false, true);
      view2.domNode.domNode.setAttribute("data-uri", model.uri.toString());
    }
    this._modelData = new ModelData(model, viewModel, view2, hasRealView, listenersToRemove);
  }
  _createView(viewModel) {
    let commandDelegate;
    if (this.isSimpleWidget) {
      commandDelegate = {
        paste: (text, pasteOnNewLine, multicursorText, mode) => {
          this._paste("keyboard", text, pasteOnNewLine, multicursorText, mode);
        },
        type: (text) => {
          this._type("keyboard", text);
        },
        compositionType: (text, replacePrevCharCnt, replaceNextCharCnt, positionDelta) => {
          this._compositionType("keyboard", text, replacePrevCharCnt, replaceNextCharCnt, positionDelta);
        },
        startComposition: () => {
          this._startComposition();
        },
        endComposition: () => {
          this._endComposition("keyboard");
        },
        cut: () => {
          this._cut("keyboard");
        }
      };
    } else {
      commandDelegate = {
        paste: (text, pasteOnNewLine, multicursorText, mode) => {
          const payload = { text, pasteOnNewLine, multicursorText, mode };
          this._commandService.executeCommand("paste", payload);
        },
        type: (text) => {
          const payload = { text };
          this._commandService.executeCommand("type", payload);
        },
        compositionType: (text, replacePrevCharCnt, replaceNextCharCnt, positionDelta) => {
          if (replaceNextCharCnt || positionDelta) {
            const payload = { text, replacePrevCharCnt, replaceNextCharCnt, positionDelta };
            this._commandService.executeCommand("compositionType", payload);
          } else {
            const payload = { text, replaceCharCnt: replacePrevCharCnt };
            this._commandService.executeCommand("replacePreviousChar", payload);
          }
        },
        startComposition: () => {
          this._commandService.executeCommand("compositionStart", {});
        },
        endComposition: () => {
          this._commandService.executeCommand("compositionEnd", {});
        },
        cut: () => {
          this._commandService.executeCommand("cut", {});
        }
      };
    }
    const viewUserInputEvents$1 = new viewUserInputEvents.ViewUserInputEvents(viewModel.coordinatesConverter);
    viewUserInputEvents$1.onKeyDown = (e) => this._onKeyDown.fire(e);
    viewUserInputEvents$1.onKeyUp = (e) => this._onKeyUp.fire(e);
    viewUserInputEvents$1.onContextMenu = (e) => this._onContextMenu.fire(e);
    viewUserInputEvents$1.onMouseMove = (e) => this._onMouseMove.fire(e);
    viewUserInputEvents$1.onMouseLeave = (e) => this._onMouseLeave.fire(e);
    viewUserInputEvents$1.onMouseDown = (e) => this._onMouseDown.fire(e);
    viewUserInputEvents$1.onMouseUp = (e) => this._onMouseUp.fire(e);
    viewUserInputEvents$1.onMouseDrag = (e) => this._onMouseDrag.fire(e);
    viewUserInputEvents$1.onMouseDrop = (e) => this._onMouseDrop.fire(e);
    viewUserInputEvents$1.onMouseDropCanceled = (e) => this._onMouseDropCanceled.fire(e);
    viewUserInputEvents$1.onMouseWheel = (e) => this._onMouseWheel.fire(e);
    const view$1 = new view.View(commandDelegate, this._configuration, this._themeService.getColorTheme(), viewModel, viewUserInputEvents$1, this._overflowWidgetsDomNode);
    return [view$1, true];
  }
  _postDetachModelCleanup(detachedModel) {
    if (detachedModel) {
      detachedModel.removeAllDecorationsWithOwnerId(this._id);
    }
  }
  _detachModel() {
    if (!this._modelData) {
      return null;
    }
    const model = this._modelData.model;
    const removeDomNode = this._modelData.hasRealView ? this._modelData.view.domNode.domNode : null;
    this._modelData.dispose();
    this._modelData = null;
    this._domElement.removeAttribute("data-mode-id");
    if (removeDomNode && this._domElement.contains(removeDomNode)) {
      this._domElement.removeChild(removeDomNode);
    }
    if (this._bannerDomNode && this._domElement.contains(this._bannerDomNode)) {
      this._domElement.removeChild(this._bannerDomNode);
    }
    return model;
  }
  _removeDecorationType(key) {
    this._codeEditorService.removeDecorationType(key);
  }
  hasModel() {
    return this._modelData !== null;
  }
};
exports.CodeEditorWidget = __decorate([
  __param(3, instantiation.IInstantiationService),
  __param(4, codeEditorService.ICodeEditorService),
  __param(5, commands.ICommandService),
  __param(6, contextkey.IContextKeyService),
  __param(7, themeService.IThemeService),
  __param(8, notification.INotificationService),
  __param(9, accessibility.IAccessibilityService),
  __param(10, languageConfigurationRegistry.ILanguageConfigurationService),
  __param(11, languageFeatures.ILanguageFeaturesService)
], exports.CodeEditorWidget);
class BooleanEventEmitter extends lifecycle.Disposable {
  constructor() {
    super();
    this._onDidChangeToTrue = this._register(new event.Emitter());
    this.onDidChangeToTrue = this._onDidChangeToTrue.event;
    this._onDidChangeToFalse = this._register(new event.Emitter());
    this.onDidChangeToFalse = this._onDidChangeToFalse.event;
    this._value = 0;
  }
  setValue(_value) {
    const value = _value ? 2 : 1;
    if (this._value === value) {
      return;
    }
    this._value = value;
    if (this._value === 2) {
      this._onDidChangeToTrue.fire();
    } else if (this._value === 1) {
      this._onDidChangeToFalse.fire();
    }
  }
}
class EditorContextKeysManager extends lifecycle.Disposable {
  constructor(editor, contextKeyService) {
    super();
    this._editor = editor;
    contextKeyService.createKey("editorId", editor.getId());
    this._editorSimpleInput = editorContextKeys.EditorContextKeys.editorSimpleInput.bindTo(contextKeyService);
    this._editorFocus = editorContextKeys.EditorContextKeys.focus.bindTo(contextKeyService);
    this._textInputFocus = editorContextKeys.EditorContextKeys.textInputFocus.bindTo(contextKeyService);
    this._editorTextFocus = editorContextKeys.EditorContextKeys.editorTextFocus.bindTo(contextKeyService);
    this._editorTabMovesFocus = editorContextKeys.EditorContextKeys.tabMovesFocus.bindTo(contextKeyService);
    this._editorReadonly = editorContextKeys.EditorContextKeys.readOnly.bindTo(contextKeyService);
    this._inDiffEditor = editorContextKeys.EditorContextKeys.inDiffEditor.bindTo(contextKeyService);
    this._editorColumnSelection = editorContextKeys.EditorContextKeys.columnSelection.bindTo(contextKeyService);
    this._hasMultipleSelections = editorContextKeys.EditorContextKeys.hasMultipleSelections.bindTo(contextKeyService);
    this._hasNonEmptySelection = editorContextKeys.EditorContextKeys.hasNonEmptySelection.bindTo(contextKeyService);
    this._canUndo = editorContextKeys.EditorContextKeys.canUndo.bindTo(contextKeyService);
    this._canRedo = editorContextKeys.EditorContextKeys.canRedo.bindTo(contextKeyService);
    this._register(this._editor.onDidChangeConfiguration(() => this._updateFromConfig()));
    this._register(this._editor.onDidChangeCursorSelection(() => this._updateFromSelection()));
    this._register(this._editor.onDidFocusEditorWidget(() => this._updateFromFocus()));
    this._register(this._editor.onDidBlurEditorWidget(() => this._updateFromFocus()));
    this._register(this._editor.onDidFocusEditorText(() => this._updateFromFocus()));
    this._register(this._editor.onDidBlurEditorText(() => this._updateFromFocus()));
    this._register(this._editor.onDidChangeModel(() => this._updateFromModel()));
    this._register(this._editor.onDidChangeConfiguration(() => this._updateFromModel()));
    this._updateFromConfig();
    this._updateFromSelection();
    this._updateFromFocus();
    this._updateFromModel();
    this._editorSimpleInput.set(this._editor.isSimpleWidget);
  }
  _updateFromConfig() {
    const options = this._editor.getOptions();
    this._editorTabMovesFocus.set(options.get(
      130
      /* tabFocusMode */
    ));
    this._editorReadonly.set(options.get(
      81
      /* readOnly */
    ));
    this._inDiffEditor.set(options.get(
      54
      /* inDiffEditor */
    ));
    this._editorColumnSelection.set(options.get(
      18
      /* columnSelection */
    ));
  }
  _updateFromSelection() {
    const selections = this._editor.getSelections();
    if (!selections) {
      this._hasMultipleSelections.reset();
      this._hasNonEmptySelection.reset();
    } else {
      this._hasMultipleSelections.set(selections.length > 1);
      this._hasNonEmptySelection.set(selections.some((s) => !s.isEmpty()));
    }
  }
  _updateFromFocus() {
    this._editorFocus.set(this._editor.hasWidgetFocus() && !this._editor.isSimpleWidget);
    this._editorTextFocus.set(this._editor.hasTextFocus() && !this._editor.isSimpleWidget);
    this._textInputFocus.set(this._editor.hasTextFocus());
  }
  _updateFromModel() {
    const model = this._editor.getModel();
    this._canUndo.set(Boolean(model && model.canUndo()));
    this._canRedo.set(Boolean(model && model.canRedo()));
  }
}
class EditorModeContext extends lifecycle.Disposable {
  constructor(_editor, _contextKeyService, _languageFeaturesService) {
    super();
    this._editor = _editor;
    this._contextKeyService = _contextKeyService;
    this._languageFeaturesService = _languageFeaturesService;
    this._langId = editorContextKeys.EditorContextKeys.languageId.bindTo(_contextKeyService);
    this._hasCompletionItemProvider = editorContextKeys.EditorContextKeys.hasCompletionItemProvider.bindTo(_contextKeyService);
    this._hasCodeActionsProvider = editorContextKeys.EditorContextKeys.hasCodeActionsProvider.bindTo(_contextKeyService);
    this._hasCodeLensProvider = editorContextKeys.EditorContextKeys.hasCodeLensProvider.bindTo(_contextKeyService);
    this._hasDefinitionProvider = editorContextKeys.EditorContextKeys.hasDefinitionProvider.bindTo(_contextKeyService);
    this._hasDeclarationProvider = editorContextKeys.EditorContextKeys.hasDeclarationProvider.bindTo(_contextKeyService);
    this._hasImplementationProvider = editorContextKeys.EditorContextKeys.hasImplementationProvider.bindTo(_contextKeyService);
    this._hasTypeDefinitionProvider = editorContextKeys.EditorContextKeys.hasTypeDefinitionProvider.bindTo(_contextKeyService);
    this._hasHoverProvider = editorContextKeys.EditorContextKeys.hasHoverProvider.bindTo(_contextKeyService);
    this._hasDocumentHighlightProvider = editorContextKeys.EditorContextKeys.hasDocumentHighlightProvider.bindTo(_contextKeyService);
    this._hasDocumentSymbolProvider = editorContextKeys.EditorContextKeys.hasDocumentSymbolProvider.bindTo(_contextKeyService);
    this._hasReferenceProvider = editorContextKeys.EditorContextKeys.hasReferenceProvider.bindTo(_contextKeyService);
    this._hasRenameProvider = editorContextKeys.EditorContextKeys.hasRenameProvider.bindTo(_contextKeyService);
    this._hasSignatureHelpProvider = editorContextKeys.EditorContextKeys.hasSignatureHelpProvider.bindTo(_contextKeyService);
    this._hasInlayHintsProvider = editorContextKeys.EditorContextKeys.hasInlayHintsProvider.bindTo(_contextKeyService);
    this._hasDocumentFormattingProvider = editorContextKeys.EditorContextKeys.hasDocumentFormattingProvider.bindTo(_contextKeyService);
    this._hasDocumentSelectionFormattingProvider = editorContextKeys.EditorContextKeys.hasDocumentSelectionFormattingProvider.bindTo(_contextKeyService);
    this._hasMultipleDocumentFormattingProvider = editorContextKeys.EditorContextKeys.hasMultipleDocumentFormattingProvider.bindTo(_contextKeyService);
    this._hasMultipleDocumentSelectionFormattingProvider = editorContextKeys.EditorContextKeys.hasMultipleDocumentSelectionFormattingProvider.bindTo(_contextKeyService);
    this._isInWalkThrough = editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.bindTo(_contextKeyService);
    const update = () => this._update();
    this._register(_editor.onDidChangeModel(update));
    this._register(_editor.onDidChangeModelLanguage(update));
    this._register(_languageFeaturesService.completionProvider.onDidChange(update));
    this._register(_languageFeaturesService.codeActionProvider.onDidChange(update));
    this._register(_languageFeaturesService.codeLensProvider.onDidChange(update));
    this._register(_languageFeaturesService.definitionProvider.onDidChange(update));
    this._register(_languageFeaturesService.declarationProvider.onDidChange(update));
    this._register(_languageFeaturesService.implementationProvider.onDidChange(update));
    this._register(_languageFeaturesService.typeDefinitionProvider.onDidChange(update));
    this._register(_languageFeaturesService.hoverProvider.onDidChange(update));
    this._register(_languageFeaturesService.documentHighlightProvider.onDidChange(update));
    this._register(_languageFeaturesService.documentSymbolProvider.onDidChange(update));
    this._register(_languageFeaturesService.referenceProvider.onDidChange(update));
    this._register(_languageFeaturesService.renameProvider.onDidChange(update));
    this._register(_languageFeaturesService.documentFormattingEditProvider.onDidChange(update));
    this._register(_languageFeaturesService.documentRangeFormattingEditProvider.onDidChange(update));
    this._register(_languageFeaturesService.signatureHelpProvider.onDidChange(update));
    this._register(_languageFeaturesService.inlayHintsProvider.onDidChange(update));
    update();
  }
  dispose() {
    super.dispose();
  }
  reset() {
    this._contextKeyService.bufferChangeEvents(() => {
      this._langId.reset();
      this._hasCompletionItemProvider.reset();
      this._hasCodeActionsProvider.reset();
      this._hasCodeLensProvider.reset();
      this._hasDefinitionProvider.reset();
      this._hasDeclarationProvider.reset();
      this._hasImplementationProvider.reset();
      this._hasTypeDefinitionProvider.reset();
      this._hasHoverProvider.reset();
      this._hasDocumentHighlightProvider.reset();
      this._hasDocumentSymbolProvider.reset();
      this._hasReferenceProvider.reset();
      this._hasRenameProvider.reset();
      this._hasDocumentFormattingProvider.reset();
      this._hasDocumentSelectionFormattingProvider.reset();
      this._hasSignatureHelpProvider.reset();
      this._isInWalkThrough.reset();
    });
  }
  _update() {
    const model = this._editor.getModel();
    if (!model) {
      this.reset();
      return;
    }
    this._contextKeyService.bufferChangeEvents(() => {
      this._langId.set(model.getLanguageId());
      this._hasCompletionItemProvider.set(this._languageFeaturesService.completionProvider.has(model));
      this._hasCodeActionsProvider.set(this._languageFeaturesService.codeActionProvider.has(model));
      this._hasCodeLensProvider.set(this._languageFeaturesService.codeLensProvider.has(model));
      this._hasDefinitionProvider.set(this._languageFeaturesService.definitionProvider.has(model));
      this._hasDeclarationProvider.set(this._languageFeaturesService.declarationProvider.has(model));
      this._hasImplementationProvider.set(this._languageFeaturesService.implementationProvider.has(model));
      this._hasTypeDefinitionProvider.set(this._languageFeaturesService.typeDefinitionProvider.has(model));
      this._hasHoverProvider.set(this._languageFeaturesService.hoverProvider.has(model));
      this._hasDocumentHighlightProvider.set(this._languageFeaturesService.documentHighlightProvider.has(model));
      this._hasDocumentSymbolProvider.set(this._languageFeaturesService.documentSymbolProvider.has(model));
      this._hasReferenceProvider.set(this._languageFeaturesService.referenceProvider.has(model));
      this._hasRenameProvider.set(this._languageFeaturesService.renameProvider.has(model));
      this._hasSignatureHelpProvider.set(this._languageFeaturesService.signatureHelpProvider.has(model));
      this._hasInlayHintsProvider.set(this._languageFeaturesService.inlayHintsProvider.has(model));
      this._hasDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.has(model) || this._languageFeaturesService.documentRangeFormattingEditProvider.has(model));
      this._hasDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.has(model));
      this._hasMultipleDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.all(model).length + this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1);
      this._hasMultipleDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1);
      this._isInWalkThrough.set(model.uri.scheme === network.Schemas.walkThroughSnippet);
    });
  }
}
class CodeEditorWidgetFocusTracker extends lifecycle.Disposable {
  constructor(domElement) {
    super();
    this._onChange = this._register(new event.Emitter());
    this.onChange = this._onChange.event;
    this._hasFocus = false;
    this._domFocusTracker = this._register(dom.trackFocus(domElement));
    this._register(this._domFocusTracker.onDidFocus(() => {
      this._hasFocus = true;
      this._onChange.fire(void 0);
    }));
    this._register(this._domFocusTracker.onDidBlur(() => {
      this._hasFocus = false;
      this._onChange.fire(void 0);
    }));
  }
  hasFocus() {
    return this._hasFocus;
  }
}
const squigglyStart = encodeURIComponent(`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 6 3' enable-background='new 0 0 6 3' height='3' width='6'><g fill='`);
const squigglyEnd = encodeURIComponent(`'><polygon points='5.5,0 2.5,3 1.1,3 4.1,0'/><polygon points='4,0 6,2 6,0.6 5.4,0'/><polygon points='0,2 1,3 2.4,3 0,0.6'/></g></svg>`);
function getSquigglySVGData(color) {
  return squigglyStart + encodeURIComponent(color.toString()) + squigglyEnd;
}
const dotdotdotStart = encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" height="3" width="12"><g fill="`);
const dotdotdotEnd = encodeURIComponent(`"><circle cx="1" cy="1" r="1"/><circle cx="5" cy="1" r="1"/><circle cx="9" cy="1" r="1"/></g></svg>`);
function getDotDotDotSVGData(color) {
  return dotdotdotStart + encodeURIComponent(color.toString()) + dotdotdotEnd;
}
themeService.registerThemingParticipant((theme, collector) => {
  const errorBorderColor = theme.getColor(colorRegistry.editorErrorBorder);
  if (errorBorderColor) {
    collector.addRule(`.monaco-editor .${"squiggly-error"} { border-bottom: 4px double ${errorBorderColor}; }`);
  }
  const errorForeground = theme.getColor(colorRegistry.editorErrorForeground);
  if (errorForeground) {
    collector.addRule(`.monaco-editor .${"squiggly-error"} { background: url("data:image/svg+xml,${getSquigglySVGData(errorForeground)}") repeat-x bottom left; }`);
  }
  const errorBackground = theme.getColor(colorRegistry.editorErrorBackground);
  if (errorBackground) {
    collector.addRule(`.monaco-editor .${"squiggly-error"}::before { display: block; content: ''; width: 100%; height: 100%; background: ${errorBackground}; }`);
  }
  const warningBorderColor = theme.getColor(colorRegistry.editorWarningBorder);
  if (warningBorderColor) {
    collector.addRule(`.monaco-editor .${"squiggly-warning"} { border-bottom: 4px double ${warningBorderColor}; }`);
  }
  const warningForeground = theme.getColor(colorRegistry.editorWarningForeground);
  if (warningForeground) {
    collector.addRule(`.monaco-editor .${"squiggly-warning"} { background: url("data:image/svg+xml,${getSquigglySVGData(warningForeground)}") repeat-x bottom left; }`);
  }
  const warningBackground = theme.getColor(colorRegistry.editorWarningBackground);
  if (warningBackground) {
    collector.addRule(`.monaco-editor .${"squiggly-warning"}::before { display: block; content: ''; width: 100%; height: 100%; background: ${warningBackground}; }`);
  }
  const infoBorderColor = theme.getColor(colorRegistry.editorInfoBorder);
  if (infoBorderColor) {
    collector.addRule(`.monaco-editor .${"squiggly-info"} { border-bottom: 4px double ${infoBorderColor}; }`);
  }
  const infoForeground = theme.getColor(colorRegistry.editorInfoForeground);
  if (infoForeground) {
    collector.addRule(`.monaco-editor .${"squiggly-info"} { background: url("data:image/svg+xml,${getSquigglySVGData(infoForeground)}") repeat-x bottom left; }`);
  }
  const infoBackground = theme.getColor(colorRegistry.editorInfoBackground);
  if (infoBackground) {
    collector.addRule(`.monaco-editor .${"squiggly-info"}::before { display: block; content: ''; width: 100%; height: 100%; background: ${infoBackground}; }`);
  }
  const hintBorderColor = theme.getColor(colorRegistry.editorHintBorder);
  if (hintBorderColor) {
    collector.addRule(`.monaco-editor .${"squiggly-hint"} { border-bottom: 2px dotted ${hintBorderColor}; }`);
  }
  const hintForeground = theme.getColor(colorRegistry.editorHintForeground);
  if (hintForeground) {
    collector.addRule(`.monaco-editor .${"squiggly-hint"} { background: url("data:image/svg+xml,${getDotDotDotSVGData(hintForeground)}") no-repeat bottom left; }`);
  }
  const unnecessaryForeground = theme.getColor(editorColorRegistry.editorUnnecessaryCodeOpacity);
  if (unnecessaryForeground) {
    collector.addRule(`.monaco-editor.showUnused .${"squiggly-inline-unnecessary"} { opacity: ${unnecessaryForeground.rgba.a}; }`);
  }
  const unnecessaryBorder = theme.getColor(editorColorRegistry.editorUnnecessaryCodeBorder);
  if (unnecessaryBorder) {
    collector.addRule(`.monaco-editor.showUnused .${"squiggly-unnecessary"} { border-bottom: 2px dashed ${unnecessaryBorder}; }`);
  }
  const deprecatedForeground = theme.getColor(colorRegistry.editorForeground) || "inherit";
  collector.addRule(`.monaco-editor.showDeprecated .${"squiggly-inline-deprecated"} { text-decoration: line-through; text-decoration-color: ${deprecatedForeground}}`);
});
exports.BooleanEventEmitter = BooleanEventEmitter;
exports.EditorModeContext = EditorModeContext;
