<script id='editor-codemirror-tpl' type='text/x-handlebars'>
<textarea id='codemirror' value='{{editor.code}}'></textarea>
</script>CodeMirror.fromTextArea(document.getElementById('codemirror'), {
autofocus: true,
lineNumbers: true,
mode: this.get('editor.mode')
});I usually set up things like Ace and CodeMirror as decorators so that the communication is more controlled, so you can group all of your control variables as params and debounce the sync between the editor and Ractive.
--
You received this message because you are subscribed to the Google Groups "Ractive.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ractive-js+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
var tooltipDecorator = function ( node, content ) {
// setup work goes here...
return {
teardown: function () {
// ...any cleanup work goes here
}
};
};
app.editor.com.codemirror = {
Component: null,
instance: null, // CodeMirror instance
init: function() {
console.log('========== Start app.editor.com.codemirror.init');
this.Component = Ractive.extend({
//isolated: true,
template: '#editor-codemirror-tpl',
oncomplete: function() {
console.log('mode: '+this.get('editor.mode'));
app.editor.com.codemirror.instance = CodeMirror.fromTextArea(document.getElementById('codemirror'), {
autofocus: true,
lineNumbers: true,
mode: this.get('editor.mode')
});
}
});
}
};To unsubscribe from this group and stop receiving emails from it, send an email to ractive-js+...@googlegroups.com.
> app.editor.instance.findComponent('CodeMirror').codeMirror.save()
> $('#codemirror').val()
"Updated text"
> app.editor.instance.get('editor.code')
"Not updated text"
> app.editor.instance.set('editor.code', 'Works!!')
> $('#codemirror').val()
"Works!!"editor = CodeMirror.fromTextArea(this.find("textarea"), {
mode: mode,
theme: this.get("theme") || "ractive",
lineWrapping: this.get("wrap")
});
doc = editor.getDoc();
editor.on("change", function () {
if (updating) {
return;
}
updating = true;
component.set("value", editor.getValue());
updating = false;
});
editor.on("keydown", function (editor, event) {
var name = CodeMirror.keyNames[event.which];
return;
if (name) {
component.fire(name.toLowerCase(), {
component: component,
shift: event.shiftKey,
original: event
});
}
});
this.observe("value", function (value) {
if (updating) {
return;
}
updating = true;
editor.setValue(value || "");
updating = false;
});
this.on("teardown", function () {
editor.toTextArea();
});