add replacetext command

This commit is contained in:
Philipp Kühn
2018-09-28 12:48:09 +02:00
parent aa0d5df017
commit a8dce68290
2 changed files with 22 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
export default function (pos, type, attrs = {}) {
return (state, dispatch) => {
const { $from } = state.selection
const index = $from.index()
if (!$from.parent.canReplaceWith(index, index, type)) {
return false
}
if (dispatch) {
// const transform = state.tr
// .replaceWith(pos.from, pos.to, state.schema.nodes.mention.create({ id: 2, type: 'user', label: 'loool' }))
const transform = state.tr.replaceWith(pos.from, pos.to, type.create(attrs))
dispatch(transform)
}
return true
}
}