"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
class StableEditorScrollState {
  constructor(_visiblePosition, _visiblePositionScrollDelta, _cursorPosition) {
    this._visiblePosition = _visiblePosition;
    this._visiblePositionScrollDelta = _visiblePositionScrollDelta;
    this._cursorPosition = _cursorPosition;
  }
  static capture(editor) {
    let visiblePosition = null;
    let visiblePositionScrollDelta = 0;
    if (editor.getScrollTop() !== 0) {
      const visibleRanges = editor.getVisibleRanges();
      if (visibleRanges.length > 0) {
        visiblePosition = visibleRanges[0].getStartPosition();
        const visiblePositionScrollTop = editor.getTopForPosition(visiblePosition.lineNumber, visiblePosition.column);
        visiblePositionScrollDelta = editor.getScrollTop() - visiblePositionScrollTop;
      }
    }
    return new StableEditorScrollState(visiblePosition, visiblePositionScrollDelta, editor.getPosition());
  }
  restore(editor) {
    if (this._visiblePosition) {
      const visiblePositionScrollTop = editor.getTopForPosition(this._visiblePosition.lineNumber, this._visiblePosition.column);
      editor.setScrollTop(visiblePositionScrollTop + this._visiblePositionScrollDelta);
    }
  }
  restoreRelativeVerticalPositionOfCursor(editor) {
    const currentCursorPosition = editor.getPosition();
    if (!this._cursorPosition || !currentCursorPosition) {
      return;
    }
    const offset = editor.getTopForLineNumber(currentCursorPosition.lineNumber) - editor.getTopForLineNumber(this._cursorPosition.lineNumber);
    editor.setScrollTop(editor.getScrollTop() + offset);
  }
}
exports.StableEditorScrollState = StableEditorScrollState;
