CodeMirror 6: Setting the contents of the editor

I have this snippet of code:

setInterval(() => {
    const transaction = view.state.replaceSelection('foobar');
    const update = view.state.update(transaction);
    view.update([update]);
}, 1000);

Based on the documentation, I expect this code to continually replace the contents of the editor with a single ‘foobar’. This is the actual behavior:

replaceSelection

Am I using these methods incorrectly? Is there a more direct way of setting the contents to some string value?

replaceSelection will replace the selection, not the entire document. You could create a transaction like state.update({changes: {from: 0, to: state.doc.length, insert: "foobar"}}) to replace the entire document.

Ah, that makes sense, my apologies. Thanks.