How to find the CodeMirror instance?

The documentation indicates that there is a CodeMirror instance in the CodeEditorWrapper instance: Notebook — JupyterLab 3.0.16 documentation

I found an editor there. I thought it might be an instance like the one described here: CodeMirror: User Manual, but it appears that it’s not.

Does anyone know how can get a reference to the CodeMirror instance?

Edit:

See also: jupyter lab - How can I get a reference to a CodeMirror instance in JupyterLab? - Stack Overflow

Specifically, I am trying do what they are doing here: Get visible lines (with respect to current scroll) - discuss.CodeMirror

CodeMirror is kind of an odd duck. You can pull a reference to the global Codemirror object from ICodeMirror.CodeMirror.

As for an instance of a specific editor bound to a widget… yeah, it’s in there somewhere. There are a few layers of abstraction, but somewhere you’ll find an IEditor that has a .editor, and that is indeed a CodeMirror instance. A number of functions are also available from it’s .document.

However: it’s a little vague where you are trying to find this from, whether with a handle to a Lab Editor instance, or individual cells in a NotebookPanel, etc.

Also: re that approach: watch yourself on getBoundingClientRect… it’s very expensive, especially with large notebooks on the screen!

2 Likes

Thank you for the guidance on this. After some casting, I was able to find it: jupyter lab - How can I get a reference to a CodeMirror instance in JupyterLab? - Stack Overflow