I have a simple schema which consists exclusively of a flat list of blocks of a single type and a few marks like link
, em
:
doc: {
content: "heading+"
},
My whole doc usually has one single block and looks like this:
<h1>Title</h1>
Now I have a string of text representing an html fragment (without a block tag) to be added at the end of the first block, say
toAppend = '<strong> of the document</strong>'
And I want my new document to look like this:
<h1>Title<strong> of the document</strong></h1>
The cursor/selection is not to be trusted, this is: I should initialize it somehow and the cursor position should be just after the e
of Title
.
How should I do this?
Right now I am parsing the input fragment into a new heading
block, injecting that block manually in the doc state as
const newState = state;
const docToAppend = myManualHtml2DocCoverstion('<strong> of the document</strong>'); // returns a doc that would serialize to `<h1><strong> of the document</strong></h1>`
newState.doc.content.content.push(docToAppend.content.content[0]);
I then try to set the cursor at the beginning of the second block with
newState.selection = TextSelection.create(
newState.doc,
newState.doc.content.content[0].nodeSize)
and trying to simulate a joinBackward
command. But I am having an issue with it because, internally $cursor.parentOffset > 0
.
Is this the recommended approach to achieve what I want?
PS. I am indeed trying to simulate an editor in which each block is, itself an independent prosemirror editor.