笙默考试管理系统-MyExamTest----codemirror(31)
目录
},
isDead: function() { return this.from != null && this.to != null && this.from >= this.to; },
sameSet: function(x) { return this.set == x.set; }
};
function Bookmark(pos) {
this.from = pos; this.to = pos; this.line = null;
}
Bookmark.prototype = {
attach: function(line) { this.line = line; },
detach: function(line) { if (this.line == line) this.line = null; },
split: function(pos, lenBefore) {
if (pos < this.from) {
this.from = this.to = (this.from - pos) + lenBefore;
return this;
}
},
isDead: function() { return this.from > this.to; },
clipTo: function(fromOpen, from, toOpen, to, diff) {
if ((fromOpen || from < this.from) && (toOpen || to > this.to)) {
this.from = 0; this.to = -1;
} else if (this.from > from) {
this.from = this.to = Math.max(to, this.from) + diff;
}
},
sameSet: function(x) { return false; },
find: function() {
if (!this.line || !this.line.parent) return null;
return {line: lineNo(this.line), ch: this.from};
},
clear: function() {
if (this.line) {
var found = indexOf(this.line.marked, this);
if (found != -1) this.line.marked.splice(found, 1);
this.line = null;
}
}
};
// Line objects. These hold state related to a line, including
// highlighting info (the styles array).
function Line(text, styles) {
this.styles = styles || [text, null];
this.text = text;
this.height = 1;
this.marked = this.gutterMarker = this.className = this.handlers = null;
this.stateAfter = this.parent = this.hidden = null;
}
Line.inheritMarks = function(text, orig) {
var ln = new Line(text), mk = orig && orig.marked;
if (mk) {
for (var i = 0; i < mk.length; ++i) {
if (mk[i].to == null && mk[i].style) {
var newmk = ln.marked || (ln.marked = []), mark = mk[i];
var nmark = mark.dup(); newmk.push(nmark); nmark.attach(ln);
}
}
}
return ln;
}
Line.prototype = {
// Replace a piece of a line, keeping the styles around it intact.
replace: function(from, to_, text) {
var st = [], mk = this.marked, to = to_ == null ? this.text.length : to_;
copyStyles(0, from, this.styles, st);
if (text) st.push(text, null);
copyStyles(to, this.text.length, this.styles, st);
this.styles = st;
this.text = this.text.slice(0, from) + text + this.text.slice(to);
this.stateAfter = null;
if (mk) {
var diff = text.length - (to - from);
for (var i = 0, mark = mk[i]; i < mk.length; ++i) {
mark.clipTo(from == null, from || 0, to_ == null, to, diff);
if (mark.isDead()) {mark.detach(this); mk.splice(i--, 1);}
}