UNPKG

@portabletext/editor

Version:

Portable Text Editor made in React

31 lines (27 loc) 719 B
import type {PortableTextBlock} from '@sanity/types' import type {EditorSelector} from '../editor/editor-selector' import type {BlockPath} from '../types/paths' import {getSelectionEndPoint} from '../utils/util.get-selection-end-point' import {getFocusBlock} from './selectors' export const getSelectionEndBlock: EditorSelector< | { node: PortableTextBlock path: BlockPath } | undefined > = (snapshot) => { const endPoint = getSelectionEndPoint(snapshot.context.selection) if (!endPoint) { return undefined } return getFocusBlock({ ...snapshot, context: { ...snapshot.context, selection: { anchor: endPoint, focus: endPoint, }, }, }) }