From bad140fa1ca842c67b3039a5d7b588a9954aa21e Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 31 Jan 2019 08:00:28 +0100 Subject: [PATCH] Add onChange to CodeEditor --- src/code_manager/model/CodeMirrorEditor.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/code_manager/model/CodeMirrorEditor.js b/src/code_manager/model/CodeMirrorEditor.js index 0e059a7e7..bbb3da68c 100644 --- a/src/code_manager/model/CodeMirrorEditor.js +++ b/src/code_manager/model/CodeMirrorEditor.js @@ -1,3 +1,4 @@ +import { bindAll } from 'underscore'; import Backbone from 'backbone'; var CodeMirror = require('codemirror/lib/codemirror'); var htmlMode = require('codemirror/mode/htmlmixed/htmlmixed'); @@ -9,13 +10,14 @@ module.exports = Backbone.Model.extend({ input: '', label: '', codeName: '', - theme: '', + theme: 'hopscotch', readOnly: true, lineNumbers: true }, /** @inheritdoc */ init(el) { + bindAll(this, 'onChange'); this.editor = CodeMirror.fromTextArea(el, { dragDrop: false, lineWrapping: true, @@ -23,10 +25,15 @@ module.exports = Backbone.Model.extend({ ...this.attributes }); this.element = el; + this.editor.on('change', this.onChange); return this; }, + onChange() { + this.trigger('update', this); + }, + getEditor() { return this.editor; },