"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var set_text_selection_exports = {};
__export(set_text_selection_exports, {
  setTextSelection: () => setTextSelection
});
module.exports = __toCommonJS(set_text_selection_exports);
var import_state = require("./../../pm/state.js");
var import_min_max = require("../utilities/min-max.js");
const setTextSelection = (position) => ({ tr, dispatch }) => {
  if (dispatch) {
    const { doc } = tr;
    const { from, to } = typeof position === "number" ? { from: position, to: position } : position;
    const minPos = import_state.TextSelection.atStart(doc).from;
    const maxPos = import_state.TextSelection.atEnd(doc).to;
    const resolvedFrom = (0, import_min_max.minMax)(from, minPos, maxPos);
    const resolvedEnd = (0, import_min_max.minMax)(to, minPos, maxPos);
    const selection = import_state.TextSelection.create(doc, resolvedFrom, resolvedEnd);
    tr.setSelection(selection);
  }
  return true;
};
//# sourceMappingURL=set-text-selection.js.map
