UNPKG

@portabletext/editor

Version:

Portable Text Editor made in React

29 lines (28 loc) 941 B
import { getBlockStartPoint, isKeyedSegment, reverseSelection } from "./util.slice-blocks.js"; import { getSelectionText } from "./selector.is-overlapping-selection.js"; const getBlockTextBefore = (snapshot) => { if (!snapshot.context.selection) return ""; const point = (snapshot.context.selection.backward ? reverseSelection(snapshot.context.selection) : snapshot.context.selection).anchor, key = isKeyedSegment(point.path[0]) ? point.path[0]._key : void 0, block = key ? snapshot.context.value.find((block2) => block2._key === key) : void 0; if (!block) return ""; const startOfBlock = getBlockStartPoint({ node: block, path: [{ _key: block._key }] }); return getSelectionText({ context: { ...snapshot.context, selection: { anchor: startOfBlock, focus: point } } }); }; export { getBlockTextBefore }; //# sourceMappingURL=selector.get-text-before.js.map