Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge in CM2 latest

  • Loading branch information...
commit d496d482548499bb2335510f2983d13d2d54b210 1 parent 3bc2304
@mzero authored
Showing with 33 additions and 25 deletions.
  1. +33 −25 seed/static/codemirror.js
View
58 seed/static/codemirror.js
@@ -69,6 +69,9 @@ var CodeMirror = (function() {
for (var n = node; n != document.body; n = n.parentNode) {x -= n.scrollLeft; y -= n.scrollTop;}
return {left: x, top: y};
}
+ function eltText(node) {
+ return node.textContent || node.innerText || node.nodeValue || "";
+ }
function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
@@ -164,11 +167,11 @@ var CodeMirror = (function() {
function copyStyles(from, to, source, dest) {
for (var i = 0, pos = 0, state = 0; pos < to; i+=2) {
var part = source[i], end = pos + part.length;
- if (state === 0) {
+ if (state == 0) {
if (end > from) dest.push(part.slice(from - pos, Math.min(part.length, to - pos)), source[i+1]);
if (end >= from) state = 1;
}
- else if (state === 1) {
+ else if (state == 1) {
if (end > to) dest.push(part.slice(0, to - pos), source[i+1]);
else dest.push(part, source[i+1]);
}
@@ -243,11 +246,15 @@ var CodeMirror = (function() {
},
getTokenAt: function(mode, state, ch) {
var txt = this.text, stream = new StringStream(txt);
- while (stream.pos <= ch && !stream.eol()) {
+ while (stream.pos < ch && !stream.eol()) {
stream.start = stream.pos;
var style = mode.token(stream, state);
}
- return {start: stream.start, end: stream.pos, string: stream.current(), className: style || null};
+ return {start: stream.start,
+ end: stream.pos,
+ string: stream.current(),
+ className: style || null,
+ state: state};
},
indentation: function() {return countIndentation(this.text);},
getHTML: function(sfrom, sto, includePre) {
@@ -257,16 +264,12 @@ var CodeMirror = (function() {
if (style) html.push('<span class="', style, '">', htmlEscape(text), "</span>");
else html.push(htmlEscape(text));
}
- function finish() {
- if (includePre) html.push("</pre>");
- return html.join("");
- }
var st = this.styles, allText = this.text, marked = this.marked;
- if (sfrom === sto) sfrom = null;
+ if (sfrom == sto) sfrom = null;
if (!allText)
span(" ");
- else if (!marked && sfrom === null)
+ else if (!marked && sfrom == null)
for (var i = 0, e = st.length; i < e; i+=2) span(st[i], st[i+1]);
else {
var pos = 0, i = 0, text = "", style, sg = 0;
@@ -310,7 +313,8 @@ var CodeMirror = (function() {
copyUntil(upto, extraStyle);
}
}
- return finish();
+ if (includePre) html.push("</pre>");
+ return html.join("");
}
};
@@ -385,7 +389,7 @@ var CodeMirror = (function() {
operation(function(){setValue(options.value || ""); updateInput = false;})();
setTimeout(prepareInput, 20);
- connect(code, "mousedown", operation(onMouseDown));
+ connect(div, "mousedown", operation(onMouseDown));
connect(code, "dblclick", operation(onDblClick));
connect(div, "scroll", updateDisplay);
connect(window, "resize", updateDisplay);
@@ -399,7 +403,7 @@ var CodeMirror = (function() {
connect(div, "dragover", function(e){e.stop();});
connect(div, "drop", operation(onDrop));
connect(div, "paste", function(){input.focus(); fastPoll();});
- connect(input, "paste", fastPoll);
+ connect(input, "paste", function(){fastPoll();});
if (options.blockDocumentScroll) {
function stopScroll(e) {
@@ -429,17 +433,18 @@ var CodeMirror = (function() {
}
function onMouseDown(e) {
- var start = posFromMouse(e), last = start, target = e.target(), going;
- if (!start) return;
- setCursor(start.line, start.ch, false);
- if (e.button() != 1) return;
- for (var n = target; n != mover; n = n.parentNode)
+ for (var n = e.target(); n != div; n = n.parentNode)
if (n.parentNode == gutterText) {
if (options.onGutterClick)
options.onGutterClick(instance, indexOf(gutterText.childNodes, n) + showingFrom);
return;
}
+ var start = posFromMouse(e), last = start, going;
+ if (!start) return;
+ setCursor(start.line, start.ch, false);
+ if (e.button() != 1) return;
+
if (!focused) onFocus();
e.stop();
function end() {
@@ -530,7 +535,7 @@ var CodeMirror = (function() {
setSelRange(input, range.start, range.start);
}
}
- fastPoll(20, id);
+ fastPoll(id);
}
function onKeyUp(e) {
if (reducedSelection) {
@@ -894,9 +899,9 @@ var CodeMirror = (function() {
}
gutter.style.display = "none";
gutterText.innerHTML = html.join("");
- var minwidth = String(lines.length).length, firstNode = gutterText.firstChild.firstChild, val = firstNode.nodeValue;
- while (val.length < minwidth) val = "\u00a0" + val;
- firstNode.nodeValue = val;
+ var minwidth = String(lines.length).length, firstNode = gutterText.firstChild, val = eltText(firstNode), pad = "";
+ while (val.length + pad.length < minwidth) pad += "\u00a0";
+ if (pad) firstNode.insertBefore(document.createTextNode(pad), firstNode.firstChild);
gutter.style.display = "";
lineWrap.style.marginLeft = gutter.offsetWidth + "px";
}
@@ -1166,7 +1171,9 @@ var CodeMirror = (function() {
var off = eltOffset(lineWrap),
x = e.pageX() - off.left,
y = e.pageY() - off.top;
- if (e.target() == code && y < (lines.length * lineHeight())) return null;
+ if (!(e.target() == div && y > (lines.length * lineHeight())))
+ for (var n = e.target(); n != lineDiv; n = n.parentNode)
+ if (!n || n == div) return null;
var line = showingFrom + Math.floor(y / lineHeight());
return clipPos({line: line, ch: charFromX(clipLine(line), x)});
}
@@ -1446,11 +1453,11 @@ var CodeMirror = (function() {
setValue: operation(setValue),
getSelection: getSelection,
replaceSelection: operation(replaceSelection),
- focus: function(){input.focus(); onFocus();},
+ focus: function(){input.focus(); onFocus(); fastPoll();},
setOption: function(option, value) {
options[option] = value;
if (option == "lineNumbers" || option == "gutter") gutterChanged();
- else if (option == "mode") setMode(value);
+ else if (option == "mode" || option == "indentUnit") setMode(value);
},
getOption: function(option) {return options[option];},
undo: operation(undo),
@@ -1477,6 +1484,7 @@ var CodeMirror = (function() {
lineCount: function() {return lines.length;},
getCursor: function(start) {return copyPos(start ? sel.from : sel.to);},
+ somethingSelected: function() {return !posEq(sel.from, sel.to);},
setCursor: operation(function(line, ch) {
if (ch == null && typeof line.line == "number") setCursor(line.line, line.ch);
else setCursor(line, ch);
Please sign in to comment.
Something went wrong with that request. Please try again.