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

18 lines
372 B
TypeScript
Raw Normal View History

2019-12-08 07:16:44 +08:00
import { Editor } from '../Editor'
2020-04-22 05:22:27 +08:00
type InsertText = (value: string) => any
2019-12-15 06:54:20 +08:00
declare module '../Editor' {
2019-12-08 07:16:44 +08:00
interface Editor {
2020-04-22 05:22:27 +08:00
insertText: InsertText,
2019-12-08 07:16:44 +08:00
}
}
2020-04-22 05:22:27 +08:00
export default (next: Function, editor: Editor, value: string): InsertText => () => {
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()
}