From e526c788c92b18e332116cc7dc1d57e37f17f2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 18 Nov 2020 12:28:08 +0100 Subject: [PATCH] add image command --- docs/src/demos/Nodes/Image/index.vue | 2 +- packages/extension-image/src/index.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/src/demos/Nodes/Image/index.vue b/docs/src/demos/Nodes/Image/index.vue index 143b1322b..391a82ea6 100644 --- a/docs/src/demos/Nodes/Image/index.vue +++ b/docs/src/demos/Nodes/Image/index.vue @@ -31,7 +31,7 @@ export default { addImage() { const url = window.prompt('URL') - this.editor.chain().focus().image({ src: url }).run() + this.editor.chain().focus().setImage({ src: url }).run() }, }, diff --git a/packages/extension-image/src/index.ts b/packages/extension-image/src/index.ts index 7eeb831ba..a4c67761f 100644 --- a/packages/extension-image/src/index.ts +++ b/packages/extension-image/src/index.ts @@ -58,11 +58,13 @@ const Image = Node.create({ /** * Add an image */ - image: (options: { src: string, alt?: string, title?: string }): Command => ({ tr }) => { + setImage: (options: { src: string, alt?: string, title?: string }): Command => ({ tr, dispatch }) => { const { selection } = tr const node = this.type.create(options) - tr.replaceRangeWith(selection.from, selection.to, node) + if (dispatch) { + tr.replaceRangeWith(selection.from, selection.to, node) + } return true },