javascriptcodemirrorcodemirror-modesui-codemirror

Set Scrollbar position at given line number in CodeMirror


I want to set the scrollbar position in codemirror at given line. I am using scrollTo() method like below. But it is not working. Let's say if there are total 100 lines, Initially I want to show user from line 61.

editor = CodeMirror.fromTextArea(document.getElementById('cm'), {
              mode: "xml",
              theme: "default",
              lineNumbers: true
          });

editor.scrollTo(null,61);

Can anyone help me ?


Solution

  • Found solution :

    Use editor.setCursor(lineNumber) instead of scrollTo() method. It's working fine.