How to insert an openEnded slice

For my prosemirror-suggestion-mode plugin I’ve now supported markup but having trouble with one interaction - deleting multi-line text. I’ve also posted this issue to github if you prefer

How to replicate:

Go to this demo

I highlight from “functionality.\nProsemirror”

Image

and hit enter, it puts a block around the suggestion_deleted text.

Image

From the log there you can see that the removedSlice.content.size is 2 larger than the to and from.

I get the slice with:

const removedSlice = oldState.doc.slice(step.from, step.to, false); and it has openStart = 1 and openEnd = 1.

I get that it’s adding additional wrapping for the slice and that’s the 2 extra chars. Later I reinsert it with:

tr.insert(step.from, removedSlice.content); What I don’t get is how I can (knowing openStart and openEnd = 1) insert the removedSlice without it having the extra wrapping. I’ve also tried

tr.replaceWith(step.from, step.from removedSlice.content) but that doesn’t work either.

The code in question is here

How are you to nicely insert a slice that’s openEnded?

By using .content, you’re stripping off the slice information about open sides. What you want is tr.replace(step.from, step.from, removedSlice) (which will insert the slice at step.from).

A slice’s size is slice.size. The content size may be bigger, but the open values will be subtracted from that, since they cause some open/close tokens at the sides to not be inserted.

Awesome that worked great and simplified the code quite a bit. Thank you!