diff --git a/demos/src/Commands/InsertContent/Vue/index.html b/demos/src/Commands/InsertContent/Vue/index.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/demos/src/Commands/InsertContent/Vue/index.spec.js b/demos/src/Commands/InsertContent/Vue/index.spec.js new file mode 100644 index 0000000000..8daa404475 --- /dev/null +++ b/demos/src/Commands/InsertContent/Vue/index.spec.js @@ -0,0 +1,11 @@ +context('/src/Commands/InsertContent/Vue/', () => { + before(() => { + cy.visit('/src/Commands/InsertContent/Vue/') + }) + + beforeEach(() => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.clearContent() + }) + }) +}) diff --git a/demos/src/Commands/InsertContent/Vue/index.vue b/demos/src/Commands/InsertContent/Vue/index.vue new file mode 100644 index 0000000000..546aa9358c --- /dev/null +++ b/demos/src/Commands/InsertContent/Vue/index.vue @@ -0,0 +1,102 @@ + + + + + diff --git a/packages/core/src/commands/insertContentAt.ts b/packages/core/src/commands/insertContentAt.ts index 63a1889913..b0d5409241 100644 --- a/packages/core/src/commands/insertContentAt.ts +++ b/packages/core/src/commands/insertContentAt.ts @@ -79,7 +79,15 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value, // if there is only plain text we have to use `insertText` // because this will keep the current marks if (isOnlyTextContent) { - tr.insertText(value as string, from, to) + // if value is string, we can use it directly + // otherwise if it is an array, we have to join it + if (Array.isArray(value)) { + tr.insertText(value.map(v => v.text || '').join(''), from, to) + } else if (typeof value === 'object' && !!value && !!value.text) { + tr.insertText(value.text, from, to) + } else { + tr.insertText(value as string, from, to) + } } else { tr.replaceWith(from, to, content) }