function adjustBlockDepthForContentState()

in src/model/transaction/adjustBlockDepthForContentState.js [17:47]


function adjustBlockDepthForContentState(
  contentState: ContentState,
  selectionState: SelectionState,
  adjustment: number,
  maxDepth?: number,
): ContentState {
  const startKey = selectionState.getStartKey();
  const endKey = selectionState.getEndKey();
  let blockMap = contentState.getBlockMap();
  const blocks = blockMap
    .toSeq()
    .skipUntil((_, k) => k === startKey)
    .takeUntil((_, k) => k === endKey)
    .concat([[endKey, blockMap.get(endKey)]])
    .map(block => {
      let depth = block.getDepth() + adjustment;
      depth = Math.max(0, depth);
      if (maxDepth != null) {
        depth = Math.min(depth, maxDepth);
      }
      return block.set('depth', depth);
    });

  blockMap = blockMap.merge(blocks);

  return contentState.merge({
    blockMap,
    selectionBefore: selectionState,
    selectionAfter: selectionState,
  });
}