-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheditor-hook.js
40 lines (32 loc) · 1.04 KB
/
editor-hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
define(function (require, exports, module) {
"use strict";
var EditorManager = brackets.getModule('editor/EditorManager'),
editor = EditorManager.getActiveEditor();
var status = require('status'),
connection = require('connection');
function sendCode() {
if (!status.isOwner() || !editor || !editor.document) {
// only the owner of the channel can publish code
return;
}
connection.sendCode(editor.document.getText());
}
function refreshEditorBinding() {
if (!editor) {
return;
}
$(editor).on("change", sendCode);
}
refreshEditorBinding();
$(EditorManager).on('activeEditorChange', function() {
editor = EditorManager.getActiveEditor();
refreshEditorBinding();
sendCode();
});
$(connection).bind('receiveCodeText', function(event, codeText) {
if (!editor) {
return;
}
editor.document.setText(codeText);
});
});