Thanks again, grateful for your help. I'm sure that other plugins will find these examples helpful.

After playing with the various versions of the scripts I realized that what I thought was broken code in my last reply was actually very different behaviour exhibited by CM6 compared to CM5. CM5 scrolled the line to the top of the view (or at least that's what the snippet I had did), while CM6 (by default) only keeps the line in view (and sometimes not even that, if it's at the bottom). The result was that on most of my tests there was zero change in the scroll position.

I modified the command to scroll the line to the top of the editor, if anyone finds this useful:

const lineInfo = editor.state.doc.line(lineNumber);
editor.dispatch(editor.state.update({
    effects: EditorView.scrollIntoView(lineInfo.from, {y: 'start'})
}));
1 Like