Set cursor at the end

Hi,

This is a very easy question, but I took a look everywhere and couldn’t really find an easy solution.

I’m looking for a way to put cursor at the end.

It’s very useful to set cursor at the end when you’re editing content, because most of the time you want to append content, at least in my use-case.

Selection.atEnd can create a valid selection at the end of the document, which you can then pass to setSelection on a transaction.

Nice, it did the trick:

import { Selection } from 'prosemirror-state'

// set cursor at the end
const selection = Selection.atEnd(view.docView.node)
const tr = view.state.tr.setSelection(selection)
const state = view.state.apply(tr)
view.updateState(state)