How to replace instead of insert? #1980
-
My tiptap editor uses both HardBreak and Paragraph: Currently, I use the following to insert a line at the current position: The issiue is, that if the editor content is empty, then it will look like this after I insertContent: Inserted Line However, what I want is for the editor content to look like this: Inserted Line We could check if this.editor.state.selection.$anchor.nodeBefore is null - and then do a replaceContent but I can't find any such function or similar methods by looking at the prosemirror docs. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can create a custom editor.commands.command(({ tr, commands }) => {
// get current selection
const selection = tr.selection
// calculate range to replace
const range = {
from: // ...
to: // ...
}
const content = // ... your content
return commands.insertContentAt(range, content)
}) |
Beta Was this translation helpful? Give feedback.
-
Thank you, I was able to find a solution with your response. |
Beta Was this translation helpful? Give feedback.
You can create a custom
command
, calculate arange
and callinsertContentAt
to replace a range.