"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.removeMark = void 0;
var _state = require("@atlaskit/editor-prosemirror/state");
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
/**
 * A wrapper around ProseMirror removeMark and removeStoredMark, which handles mark removal in text, CellSelections and cursor stored marks.
 */
var removeMark = exports.removeMark = function removeMark(mark) {
  return function (_ref) {
    var tr = _ref.tr;
    var selection = tr.selection;
    if (selection instanceof _cellSelection.CellSelection) {
      selection.forEachCell(function (cell, cellPos) {
        var from = cellPos;
        var to = cellPos + cell.nodeSize;
        tr.removeMark(from, to, mark);
      });
    } else if (selection instanceof _state.TextSelection && selection.$cursor) {
      tr.removeStoredMark(mark);
    } else {
      var from = selection.from,
        to = selection.to;
      tr.removeMark(from, to, mark);
    }
    return tr;
  };
};