UNPKG

contenido

Version:

Contenido is a library with a set of tools to help you create your own rich text editor on top of draft-js without thinking about how to handle things.

24 lines (19 loc) 592 B
// Custom Types import type { State } from '../../types'; const getSelectedBlocksMap = (state: State) => { const contentState = state.getCurrentContent(); const blockMap = contentState.getBlockMap(); const selection = state.getSelection(); const startKey = selection.getStartKey(); const endKey = selection.getEndKey(); if (startKey === endKey) { return [blockMap.get(startKey)]; } else { return blockMap .toSeq() .skipUntil((_, k) => k === startKey) .takeUntil((_, k) => k === endKey) .toArray(); } }; export default getSelectedBlocksMap;