Files
tiptap/packages/tiptap-commands/src/commands/replaceText.js
Philipp Kühn 640094171e wording
2018-09-29 12:34:11 +02:00

17 lines
347 B
JavaScript

export default function (range, type, attrs = {}) {
return (state, dispatch) => {
const { $from } = state.selection
const index = $from.index()
if (!$from.parent.canReplaceWith(index, index, type)) {
return false
}
if (dispatch) {
dispatch(state.tr.replaceWith(range.from, range.to, type.create(attrs)))
}
return true
}
}