UNPKG

slate-edit-list

Version:

A Slate plugin to handle keyboard events in lists.

27 lines (21 loc) 589 B
// @flow import { type Change } from 'slate'; import type Options from '../options'; import { getCurrentItem } from '../utils'; /** * Split a list item at the start of the current range. */ function splitListItem(opts: Options, change: Change): Change { const { value } = change; const currentItem = getCurrentItem(opts, value); if (!currentItem) { return change; } const splitOffset = value.startOffset; return change.splitDescendantsByKey( currentItem.key, value.startKey, splitOffset ); } export default splitListItem;