mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-29 16:38:24 +08:00
add replacetext command
This commit is contained in:
parent
aa0d5df017
commit
a8dce68290
20
packages/tiptap-commands/src/commands/replaceText.js
Normal file
20
packages/tiptap-commands/src/commands/replaceText.js
Normal 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
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user