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
}
}

View File

@ -40,6 +40,7 @@ import {
import markInputRule from './commands/markInputRule'
import removeMark from './commands/removeMark'
import replaceText from './commands/replaceText'
import setInlineBlockType from './commands/setInlineBlockType'
import splitToDefaultListItem from './commands/splitToDefaultListItem'
import toggleBlockType from './commands/toggleBlockType'
@ -87,6 +88,7 @@ export {
// custom
markInputRule,
removeMark,
replaceText,
setInlineBlockType,
splitToDefaultListItem,
toggleBlockType,