Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set focus of codemirror instance based on container

I have multiple instances of codemirror running on my page. Some are hidden and you can move between them using tabs. What I would like to do is be able to set the focus based on the container.

At some point the instance was initiated like this:

var cmInstance = CodeMirror(target, options());

So I would either like to be able to get the instance that was initiated on that container by using the container, something like:

cm = target.getCodeMirror();

or perhaps set the focus based on the container, something like:

target.setFocus();

Is anything like this possible or should I rather keep a record of individual instances in an array or something?

like image 918
Jeffrey Jenkinson Avatar asked Oct 17 '13 14:10

Jeffrey Jenkinson


1 Answers

Okay so I opted to track my instances of codemirror in an array and address them based on an ID that I keep track of and link to the target. Once I have my instance I can just set focus using the codemirror method cmInstance.focus();

Currently I feel this is the best solution.

like image 118
Jeffrey Jenkinson Avatar answered Nov 15 '22 14:11

Jeffrey Jenkinson