How can I insert white spaces and newlines using the API

#1

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.

#2

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

1 Like
#3

It worked, thanks