tiptap/packages/core/src/commands/insertText.ts

18 lines
375 B
TypeScript
Raw Normal View History

2019-12-08 07:16:44 +08:00
import { Editor } from '../Editor'
type InsertTextCommand = (value: string) => Editor
2020-04-22 05:22:27 +08:00
2019-12-15 06:54:20 +08:00
declare module '../Editor' {
2019-12-08 07:16:44 +08:00
interface Editor {
insertText: InsertTextCommand,
2019-12-08 07:16:44 +08:00
}
}
export default (next: Function, editor: Editor) => (value: string) => {
2020-03-05 04:27:22 +08:00
const { view, state } = editor
2019-12-15 06:54:20 +08:00
const transaction = state.tr.insertText(value)
view.dispatch(transaction)
2019-12-08 07:16:44 +08:00
next()
}