From 2bbfab2f8f1e1a75a3e46ae7e786ac9b14919fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 22 Nov 2018 22:48:00 +0100 Subject: [PATCH] range is optional for replaceText command --- packages/tiptap-commands/src/commands/replaceText.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/tiptap-commands/src/commands/replaceText.js b/packages/tiptap-commands/src/commands/replaceText.js index ecc6b86a..2df8b171 100644 --- a/packages/tiptap-commands/src/commands/replaceText.js +++ b/packages/tiptap-commands/src/commands/replaceText.js @@ -1,14 +1,16 @@ -export default function (range, type, attrs = {}) { +export default function (range = null, type, attrs = {}) { return (state, dispatch) => { - const { $from } = state.selection + const { $from, $to } = state.selection const index = $from.index() + const from = range ? range.from : $from.pos + const to = range ? range.to : $to.pos if (!$from.parent.canReplaceWith(index, index, type)) { return false } if (dispatch) { - dispatch(state.tr.replaceWith(range.from, range.to, type.create(attrs))) + dispatch(state.tr.replaceWith(from, to, type.create(attrs))) } return true