From 4a31f8f1ca64964b816626a323919a5e36fae49c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 2 Oct 2018 23:01:53 +0200 Subject: [PATCH] add insertText command --- packages/tiptap-commands/src/commands/insertText.js | 10 ++++++++++ packages/tiptap-commands/src/index.js | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 packages/tiptap-commands/src/commands/insertText.js diff --git a/packages/tiptap-commands/src/commands/insertText.js b/packages/tiptap-commands/src/commands/insertText.js new file mode 100644 index 00000000..ee7d4ae7 --- /dev/null +++ b/packages/tiptap-commands/src/commands/insertText.js @@ -0,0 +1,10 @@ +export default function (text = '') { + return (state, dispatch) => { + const { $from } = state.selection + const { pos } = $from.pos + + dispatch(state.tr.insertText(text, pos)) + + return true + } +} diff --git a/packages/tiptap-commands/src/index.js b/packages/tiptap-commands/src/index.js index e2d9a318..0b83c23f 100644 --- a/packages/tiptap-commands/src/index.js +++ b/packages/tiptap-commands/src/index.js @@ -38,6 +38,7 @@ import { textblockTypeInputRule, } from 'prosemirror-inputrules' +import insertText from './commands/insertText' import markInputRule from './commands/markInputRule' import removeMark from './commands/removeMark' import replaceText from './commands/replaceText' @@ -86,6 +87,7 @@ export { textblockTypeInputRule, // custom + insertText, markInputRule, removeMark, replaceText,