Get CodeMirror instance

后端 未结 6 783
礼貌的吻别
礼貌的吻别 2020-12-23 17:14

I want to get an instance of CodeMirror (it is binded to a textarea \'#code\'). From an onclick-event I want to add a value to the current value of the CodeMirror instance.

6条回答
  •  自闭症患者
    2020-12-23 17:35

    Someone just posted an answer but removed it. Nevertheless, it was a working solution. Thanks!

    -- Basically this was his solution:

    // create an instance
    var editor = CodeMirror.fromTextArea('code');
    // store it
    $('#code').data('CodeMirrorInstance', editor);
    // get it
    var myInstance = $('code').data('CodeMirrorInstance');
    // from here on the API functions are available to 'myInstance' again.
    

提交回复
热议问题