@portabletext/editor
Version:
Portable Text Editor made in React
25 lines (21 loc) • 590 B
text/typescript
import {Transforms} from 'slate'
import {toSlateRange} from '../internal-utils/ranges'
import type {BehaviorActionImplementation} from './behavior.actions'
export const deleteBlockActionImplementation: BehaviorActionImplementation<
'delete.block'
> = ({action}) => {
const range = toSlateRange(
{
anchor: {path: action.at, offset: 0},
focus: {path: action.at, offset: 0},
},
action.editor,
)
if (!range) {
console.error('Unable to find Slate range from selection points')
return
}
Transforms.removeNodes(action.editor, {
at: range,
})
}