我正在使用Codemirror开发一个基于实验性协作 Web 的 IDE ,但是在我附加了 Codemirror 的新实例之后。它在附加它的机器上运行良好(只要 togetherjs 没有运行),但是当我用我的另一台笔记本电脑(chromebook 和 macbook)测试它以测试协作时,当我附加一个时,macbook 显示两个,然后当我从我的 chromebook 中附加了另一个,它在我的 macbook 上显示了 5,而在我的 chromebook 上显示了 3。提供不准确的信息。
更不用说我无法实际使用一些附加的新编辑器。第一个测试(意味着在任何其他测试之前先追加)我可以使用编辑器,但在任一设备上都没有显示。
我使用的协作工具是 Mozilla 的TogetherJS。
$(".add").click(function() {
var count = Date.now();
$(".editor-container").append("<div id='code" + count + "'></div>");
$(".scripts").append("<scr" + "ipt>\n// Initialize CodeMirror editor\nvar editor" + count + " = CodeMirror(document.getElementById('code" + count + "'), {\n mode: 'text/html',\n tabMode: 'indent',\n styleActiveLine: true,\n lineNumbers: true,\n lineWrapping: true,\n autoCloseTags: true,\n foldGutter: true,\n dragDrop : true,\n gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],\n value: 'new codemirror editor = " + count + "'\n});</scr" + "ipt>");
var editableeditors = $(".editor-container").html();
var scripts = $(".scripts").html();
if (TogetherJS.running) {
TogetherJS.send({
type: "editable-editors",
output: editableeditors
});
TogetherJS.send({
type: "call-scripts",
output: scripts
});
}
});
// Update TogetherJS
TogetherJS.hub.on("editable-editors", function (msg) {
if (! msg.sameUrl) {
return;
}
$(".editor-container").html(msg.output);
});
TogetherJS.hub.on("call-scripts", function (msg) {
if (! msg.sameUrl) {
return;
}
$(".scripts").html(msg.output);
});
.head {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 50px;
}
.add {
width: 100%;
height: 100%;
}
.editor-container {
position: absolute;
top: 50px;
left: 0;
right: 0;
bottom: 0;
background: #262A32;
overflow: auto;
}
.CodeMirror {
float: left;
width: 45%;
height: 45%;
border: 1px solid black;
}
<link type='text/css' rel='stylesheet' href='http://necolas.github.io/normalize.css/3.0.1/normalize.css'/>
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.min.js'></script>
<script src='http://codemirror.net/lib/codemirror.js'></script>
<link rel='stylesheet' href='http://codemirror.net/lib/codemirror.css'>
<link rel='stylesheet' href='http://codemirror.net/addon/fold/foldgutter.css' />
<script src='http://codemirror.net/javascripts/code-completion.js'></script>
<script src='http://codemirror.net/javascripts/css-completion.js'></script>
<script src='http://codemirror.net/javascripts/html-completion.js'></script>
<script src='http://codemirror.net/mode/javascript/javascript.js'></script>
<script src='http://codemirror.net/mode/xml/xml.js'></script>
<script src='http://codemirror.net/mode/css/css.js'></script>
<script src='http://codemirror.net/mode/htmlmixed/htmlmixed.js'></script>
<script src='http://codemirror.net/addon/edit/closetag.js'></script>
<script src='http://codemirror.net/addon/edit/matchbrackets.js'></script>
<script src='http://codemirror.net/addon/selection/active-line.js'></script>
<script src='http://codemirror.net/keymap/extra.js'></script>
<script src='http://codemirror.net/addon/fold/foldcode.js'></script>
<script src='http://codemirror.net/addon/fold/foldgutter.js'></script>
<script src='http://codemirror.net/addon/fold/brace-fold.js'></script>
<script src='http://codemirror.net/addon/fold/xml-fold.js'></script>
<script src='http://codemirror.net/addon/fold/comment-fold.js'></script>
<div class="head">
<button class="add">Add CodeMirror</button>
</div>
<div class="editor-container"></div>
<div class="scripts"></div>