diff options
author | Yukai Huang | 2017-03-28 11:18:36 +0800 |
---|---|---|
committer | Yukai Huang | 2017-03-28 11:18:36 +0800 |
commit | 81666a726c831af23e1d04d18e8efae3ecc0930d (patch) | |
tree | ebd6b7eea6d43574b894a5803f84dbfd0d866782 /public/js/lib/editor | |
parent | fff7ebd1b57467ed43925de33cfe013f6e61e5a7 (diff) |
Impl multiple codemirror event listener
Diffstat (limited to '')
-rw-r--r-- | public/js/lib/editor/index.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/public/js/lib/editor/index.js b/public/js/lib/editor/index.js index 6ae40d82..8d617247 100644 --- a/public/js/lib/editor/index.js +++ b/public/js/lib/editor/index.js @@ -116,6 +116,19 @@ export default class Editor { utils.wrapTextWith(this.editor, cm, 'Backspace') } } + this.eventListeners = {} + } + + on (event, cb) { + if (!this.eventListeners[event]) { + this.eventListeners[event] = [cb] + } else { + this.eventListeners[event].push(cb) + } + + this.editor.on(event, (...args) => { + this.eventListeners[event].forEach(cb => cb(...args)) + }) } getStatusBarTemplate (callback) { |