UNPKG

@portabletext/editor

Version:

Portable Text Editor made in React

20 lines (15 loc) 461 B
import {Point, type Operation, type Range} from 'slate' export function moveRangeByOperation( range: Range, operation: Operation, ): Range | null { const anchor = Point.transform(range.anchor, operation) const focus = Point.transform(range.focus, operation) if (anchor === null || focus === null) { return null } if (Point.equals(anchor, range.anchor) && Point.equals(focus, range.focus)) { return range } return {anchor, focus} }