문제

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