Hello,
Can I change the ReadOnly mode of each Buffer?
Thank you for your answers.
Hello,
Can I change the ReadOnly mode of each Buffer?
Thank you for your answers.
I wrote this code. Tips to improve it would be welcome.
<div><link rel="stylesheet" href="scripts/js/external/codemirror/codemirror.css">
<link rel="stylesheet" href="scripts/js/external/codemirror/theme/ambiance.css">
<script src="scripts/js/external/codemirror/codemirror.js"></script>
<script src="scripts/js/external/codemirror/mode/python/python.js"></script>
<script src="scripts/js/external/codemirror/mode/clike/clike.js"></script>
<script src="scripts/js/external/codemirror/addon/edit/matchbrackets.js"></script>
<div class="wims_editor" id="wims_editor2">
<span onclick="initialisation2();" class="wims_button" style="cursor:pointer;">Initialisation</span>
<div><select id="select_wims_editor2">
<option value="code1">code1</option>
<option value="Hello">Hello</option>
<option value="boucle">boucle</option>
</select></div>
<div id="2"></div>
</div>
<script>
var list_2=[false, true, false,];
var sel_2=document.getElementById("select_wims_editor2");
CodeMirror.on(sel_2, "change", function() {
selectBuffer(editor2.setOption("readOnly",list_2[sel_2.selectedIndex]), sel_2.options[ sel_2.selectedIndex].value);});
var buffers = {};
function openBuffer(name, text, mode) {buffers[name] = CodeMirror.Doc(text, mode);}
function selectBuffer(editor, name) {
var buf = buffers[name];
if (buf.getEditor()) buf = buf.linkedDoc({sharedHist: true});
var old = editor2.swapDoc(buf);
var linked = old.iterLinkedDocs(function(doc) {linked = doc;});
if (linked) {
for (var name in buffers) if (buffers[name] == old) buffers[name] = linked;
old.unlinkDoc(linked);
}
editor2.focus();}
openBuffer("code1","a=23*797961\nprint a" , "python");
openBuffer("Hello","#include <stdio.h>\n#include <stdlib.h>\nint main()\n{\nprintf(\"Hello world!\");\nreturn 0;\n}" , "clike");
openBuffer("boucle","n=0\nwhile n<10:\n print n,n\n n=n+1" , "python");
var editor2 = CodeMirror(document.getElementById("2"), {
lineNumbers: true,
theme:"ambiance",
matchBrackets: true,
mode: "python",
readOnly:false,
styleSelectedText: true,
viewportMargin: 10,
indentUnit:2,
autocapitalize:true
});
selectBuffer(editor2, "code1");
function initialisation2(){ openBuffer("code1","a=23*797961\nprint a" , "python");
openBuffer("Hello","#include <stdio.h>\n#include <stdlib.h>\nint main()\n{\nprintf(\"Hello world!\");\nreturn 0;\n}" , "clike");
openBuffer("boucle","n=0\nwhile n<10:\n print n,n\n n=n+1" , "python");
selectBuffer(editor2, "code1");
document.getElementById("select_wims_editor2").options[0].selected = true;
}
</script></div>
Blockquote