"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.anyMarkActive = void 0;
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
/**
 * Determine if a mark of a specific type exists anywhere in the selection.
 */
var anyMarkActive = exports.anyMarkActive = function anyMarkActive(state, markType) {
  var _state$selection = state.selection,
    $from = _state$selection.$from,
    from = _state$selection.from,
    to = _state$selection.to,
    empty = _state$selection.empty;
  if (empty) {
    return !!markType.isInSet(state.storedMarks || $from.marks());
  }
  var rangeHasMark = false;
  if (state.selection instanceof _cellSelection.CellSelection) {
    state.selection.forEachCell(function (cell, cellPos) {
      var from = cellPos;
      var to = cellPos + cell.nodeSize;
      if (!rangeHasMark) {
        rangeHasMark = state.doc.rangeHasMark(from, to, markType);
      }
    });
  } else {
    rangeHasMark = state.doc.rangeHasMark(from, to, markType);
  }
  return rangeHasMark;
};