سؤال

I am using CodeMirror and the merge addon to compare some edited code with an original document. In a normal view (not a merge view) I can add a listener to the CodeMirror constructor to listen for changes and give the user visual feedback to show that the changes have not been saved yet.

Like so:

//codemirror constructor
var cmConstructor = CodeMirror(target, setOptions());
cmConstructor.on('change', function() {codeChange(variables)});

Now when I call it on a merge constructor like so:

//codemirror merge constructor
var cmConstructor = CodeMirror.MergeView(target, setOptions());
cmConstructor.on('change', function() {codeChange(variables)});

I get the following error: Uncaught TypeError: Object #<Object> has no method 'on'

Any idea how I can listen for changes within a mergeView?

هل كانت مفيدة؟

المحلول

The MergeView encapsulates two (or three) editors, you can get at the editors with the .editor(), .leftOriginal() and .rightOriginal() methods. In this case, since the originals don't change, you want

mergeView.editor().on("change", function(cm, change) { ... });
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top