The idea is that users can predefine blocks of text as a snippet, so they can use them in other documents. These snippets should preserve markup, so they are stored in the DB by stringifying them. When retrieved they are turned back into a JSON array. I tried to insert the entire array at once, which I believe is not possible. So I ended up looping through all JSON entries and converting them to nodes, putting it into a transaction and then dispatching it after the loop. This works however after every insert there is a white line that wasn’t there when it was initially saved.
Is there a better solution available or how do I remove the white lines?
const snapshot = await documentRef.child(id).once('value');
if (!snapshot.val()) return;
const { state } = editorView;
const transaction = state.tr;
const { from } = state.selection;
const content = JSON.parse(snapshot.val().content)
//reverse for loop to paste the content in the correct order
for (let index = content.length - 1; index >= 0; index--) {
transaction.insert(from, fbSchema.nodeFromJSON(content[index]))
}
editorView.dispatch(transaction)
editorView.focus();