How can I insert white spaces and newlines using the API

Hi,

1 / I would like to insert multiple white spaces at a given positon using the API.

I tried: Transaction.insertText(' ', pos) but multiple spaces don’t work as the DOM concatenates whitespaces inside <p>

I tried Transaction.insertText('&nbsp;', pos) but it inserted it as a word and it didn’t get converted into a space.

2/ I would like to insert newlines, i have no idea how to achieve this.

Thanks.

Make sure you are loading prosemirror-view/style/prosemirror.css, which will disable whitespace collapsing within the editor.

1 Like

It worked, thanks