Multiple Buffer & Split View Demo
59
val = val.slice(val.match(/^\s*/)[0].length, val.length - val.match(/\s*$/)[0].length) + "\n";1
var sel_top = document.getElementById("buffers_top");2
CodeMirror.on(sel_top, "change", function() {3
selectBuffer(ed_top, sel_top.options[sel_top.selectedIndex].value);4
});5
6
var sel_bot = document.getElementById("buffers_bot");7
CodeMirror.on(sel_bot, "change", function() {8
selectBuffer(ed_bot, sel_bot.options[sel_bot.selectedIndex].value);9
});10
11
var buffers = {};12
13
function openBuffer(name, text, mode) {14
buffers[name] = CodeMirror.Doc(text, mode);15
var opt = document.createElement("option");16
opt.appendChild(document.createTextNode(name));17
sel_top.appendChild(opt);18
sel_bot.appendChild(opt.cloneNode(true));19
}20
21
function newBuf(where) {22
var name = prompt("Name for the buffer", "*scratch*");23
if (name == null) return;24
if (buffers.hasOwnProperty(name)) {25
alert("There's already a buffer by that name.");26
return;27
}28
openBuffer(name, "", "javascript");
Select buffer:
1
59
val = val.slice(val.match(/^\s*/)[0].length, val.length - val.match(/\s*$/)[0].length) + "\n";1
var sel_top = document.getElementById("buffers_top");2
CodeMirror.on(sel_top, "change", function() {3
selectBuffer(ed_top, sel_top.options[sel_top.selectedIndex].value);4
});5
6
var sel_bot = document.getElementById("buffers_bot");7
CodeMirror.on(sel_bot, "change", function() {8
selectBuffer(ed_bot, sel_bot.options[sel_bot.selectedIndex].value);9
});10
11
var buffers = {};12
13
function openBuffer(name, text, mode) {14
buffers[name] = CodeMirror.Doc(text, mode);15
var opt = document.createElement("option");16
opt.appendChild(document.createTextNode(name));17
sel_top.appendChild(opt);18
sel_bot.appendChild(opt.cloneNode(true));19
}20
21
function newBuf(where) {22
var name = prompt("Name for the buffer", "*scratch*");23
if (name == null) return;24
if (buffers.hasOwnProperty(name)) {25
alert("There's already a buffer by that name.");26
return;27
}28
openBuffer(name, "", "javascript");
Select buffer:
Demonstration of
using linked documents
to provide a split view on a document, and
using swapDoc
to use a single editor to display multiple documents.
