v6 scroll to the end to show cursor in multi-line code

Hello team, when I enter a character at the end of multi-line code, Codemirror 6 editor doesn’t scroll to the end. It used to work in codemirror 5. Am I missing anything in the following code?

const value = "<=";
let cursor = cm.state.selection.main.head;
// set cursor at the end of code
cm.dispatch({ selection: { anchor: cm.state.doc.length } });
cursor = cm.state.selection.main.head;

cm.dispatch(cm.state.replaceSelection(value)); // This adds the value at the end
cm.focus();

Editor is in focus but doesn’t scroll to the end to show cursor -

New characters added on line 8 which shows the cursor, but I need to scroll to see the new characters

You have to include scrollIntoView: true in your transaction spec if you want the change to scroll the cursor into view.

1 Like