import { TextSelection } from '@atlaskit/editor-prosemirror/state';
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
/**
 * A wrapper around ProseMirror removeMark and removeStoredMark, which handles mark removal in text, CellSelections and cursor stored marks.
 */
export var removeMark = function removeMark(mark) {
  return function (_ref) {
    var tr = _ref.tr;
    var selection = tr.selection;
    if (selection instanceof CellSelection) {
      selection.forEachCell(function (cell, cellPos) {
        var from = cellPos;
        var to = cellPos + cell.nodeSize;
        tr.removeMark(from, to, mark);
      });
    } else if (selection instanceof TextSelection && selection.$cursor) {
      tr.removeStoredMark(mark);
    } else {
      var from = selection.from,
        to = selection.to;
      tr.removeMark(from, to, mark);
    }
    return tr;
  };
};