最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Set focus of codemirror instance based on container - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question asked Oct 17, 2013 at 14:04 JeffJenkJeffJenk 2,6653 gold badges23 silver badges29 bronze badges 1
  • 1 CodeMirror will add a property CodeMirror to the container DOM node, pointing at the editor instance. – Marijn Commented Oct 22, 2013 at 13:46
Add a comment  | 

1 Answer 1

Reset to default 19

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.

发布评论

评论列表(0)

  1. 暂无评论