import { Command } from 'prosemirror-commands' ; import { EditorState , Transaction } from 'prosemirror-state' ; export const removeLink = ( ) : Command => { return ( state , dispatch ? ) : boolean => { const { doc , selection , tr } = state ; const { $head : { pos } , from , to } = selection ; if ( from === to ) { const $pos = doc . resolve ( pos ) ; const linkStart = pos - $pos . textOffset ; const linkEnd = linkStart + $pos . parent . child ( $pos . index ( ) ) . nodeSize ; tr . removeMark ( linkStart , linkEnd ) ; } else { tr . removeMark ( from , to ) ; } if ( ! tr . docChanged ) { return false ; } dispatch ?. ( tr ) ; return true ; } ; } ; export default removeLink ;