About inserting text at the cursor

Insert text at the cursor, as follows

editor.current.view.dispatch({
            changes: {
                from: range.from,
                to: range.to,
                insert: text
            }
        })

but,I want to insert text at the cursor and place the cursor in the middle of the inserted text,I know the old version

  editor.replaceSelection(`**${selection}**`);
  const cursor = editor.getCursor();
  cursor.ch -= 2;
  editor.setCursor(cursor);

I don’t know how to do it in the new version

view.dispatch({
   changes: {
     from: range.from,
     to: range.to,
     insert: text
   },
   selection: {anchor: range.from + 1}
})

thank you very much

I have a problem

...
insert(editor, '#', 1)
editor.current.view.focus()
...
export const insert = (editor, text, selection) => {
    const state = editor.current.view.viewState.state;
    const range = state.selection.ranges[0];
    editor.current.view.dispatch({
        changes: {
            from: range.from,
            to: range.to,
            insert: `${text}`
        },
        selection: {anchor: range.from + selection}
    })
}

The first call is the correct insert#,But the second call inserts two #, this is why?