Skip to content

How to replace instead of insert? #1980

Discussion options

You must be logged in to vote

You can create a custom command, calculate a range and call insertContentAt to replace a range.

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)
})

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by newalphamedia
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants