Showing with 4,911 additions and 1,788 deletions.
  1. +29 −0 addon/edit/closebrackets.js
  2. +8 −7 addon/edit/closetag.js
  3. +1 −1 addon/edit/continuecomment.js
  4. +19 −8 addon/edit/matchbrackets.js
  5. +1 −1 addon/fold/collapserange.js
  6. +9 −9 addon/fold/foldcode.js
  7. +8 −6 addon/hint/javascript-hint.js
  8. +2 −2 addon/hint/pig-hint.js
  9. +2 −2 addon/hint/python-hint.js
  10. +38 −0 addon/hint/show-hint.css
  11. +155 −0 addon/hint/show-hint.js
  12. +4 −17 addon/hint/xml-hint.js
  13. +121 −0 addon/lint/javascript-lint.js
  14. +14 −0 addon/lint/json-lint.js
  15. +96 −0 addon/lint/lint.css
  16. +182 −0 addon/lint/lint.js
  17. +2 −3 addon/runmode/runmode-standalone.js
  18. +2 −3 addon/runmode/runmode.node.js
  19. +52 −38 addon/search/match-highlighter.js
  20. +5 −5 addon/search/search.js
  21. +17 −12 addon/search/searchcursor.js
  22. +39 −0 addon/selection/active-line.js
  23. +34 −0 addon/selection/mark-selection.js
  24. +1 −1 bin/compress
  25. +3 −9 demo/activeline.html
  26. +61 −0 demo/bidi.html
  27. +1 −1 demo/btree.html
  28. +98 −0 demo/buffers.html
  29. +59 −0 demo/closebrackets.html
  30. +3 −3 demo/complete.html
  31. +9 −1 demo/formatting.html
  32. +90 −0 demo/lint.html
  33. +36 −0 demo/markselection.html
  34. +9 −7 demo/matchhighlighter.html
  35. +1 −1 demo/variableheight.html
  36. +14 −6 demo/xmlcomplete.html
  37. +10 −0 doc/compress.html
  38. +1 −1 doc/docs.css
  39. +532 −263 doc/manual.html
  40. +2 −0 doc/modes.html
  41. +37 −0 doc/oldrelease.html
  42. +7 −1 doc/realworld.html
  43. +45 −38 index.html
  44. +126 −48 keymap/vim.js
  45. +5 −0 lib/codemirror.css
  46. +1,595 −986 lib/codemirror.js
  47. +1 −1 mode/coffeescript/coffeescript.js
  48. +2 −2 mode/haxe/haxe.js
  49. +43 −23 mode/htmlmixed/htmlmixed.js
  50. +22 −1 mode/htmlmixed/index.html
  51. +10 −6 mode/javascript/javascript.js
  52. +2 −1 mode/meta.js
  53. +1 −1 mode/php/php.js
  54. +11 −0 mode/python/index.html
  55. +7 −7 mode/python/python.js
  56. +131 −0 mode/q/index.html
  57. +124 −0 mode/q/q.js
  58. +1 −1 mode/sass/sass.js
  59. +39 −0 mode/turtle/index.html
  60. +145 −0 mode/turtle/turtle.js
  61. +1 −1 mode/vb/vb.js
  62. +1 −1 package.json
  63. +329 −0 test/doc_test.js
  64. +3 −3 test/driver.js
  65. +3 −6 test/index.html
  66. +4 −0 test/lint/lint.js
  67. +391 −250 test/test.js
  68. +55 −4 test/vim_test.js
29 changes: 29 additions & 0 deletions addon/edit/closebrackets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(function() {
var DEFAULT_BRACKETS = "()[]{}''\"\"";

CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
var wasOn = old && old != CodeMirror.Init;
if (val && !wasOn)
cm.addKeyMap(buildKeymap(typeof val == "string" ? val : DEFAULT_BRACKETS));
else if (!val && wasOn)
cm.removeKeyMap("autoCloseBrackets");
});

function buildKeymap(pairs) {
var map = {name : "autoCloseBrackets"};
for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
function maybeOverwrite(cm) {
var cur = cm.getCursor(), ahead = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
if (ahead != right) return CodeMirror.Pass;
else cm.execCommand("goCharRight");
}
map["'" + left + "'"] = function(cm) {
if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
var cur = cm.getCursor("start"), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);
cm.replaceSelection(left + right, {head: ahead, anchor: ahead});
};
if (left != right) map["'" + right + "'"] = maybeOverwrite;
})(pairs.charAt(i), pairs.charAt(i + 1));
return map;
}
})();
15 changes: 8 additions & 7 deletions addon/edit/closetag.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
if (val && (old == CodeMirror.Init || !old)) {
var map = {name: "autoCloseTags"};
if (typeof val != "object" || val.whenClosing)
map["'/'"] = function(cm) { autoCloseTag(cm, '/'); };
map["'/'"] = function(cm) { return autoCloseTag(cm, '/'); };
if (typeof val != "object" || val.whenOpening)
map["'>'"] = function(cm) { autoCloseTag(cm, '>'); };
map["'>'"] = function(cm) { return autoCloseTag(cm, '>'); };
cm.addKeyMap(map);
} else if (!val && (old != CodeMirror.Init && old)) {
cm.removeKeyMap("autoCloseTags");
Expand All @@ -44,7 +44,7 @@
function autoCloseTag(cm, ch) {
var pos = cm.getCursor(), tok = cm.getTokenAt(pos);
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
if (inner.mode.name != "xml") throw CodeMirror.Pass;
if (inner.mode.name != "xml") return CodeMirror.Pass;

var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
Expand All @@ -58,22 +58,23 @@
if (tok.type == "tag" && state.type == "closeTag" ||
/\/\s*$/.test(tok.string) ||
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1)
throw CodeMirror.Pass;
return CodeMirror.Pass;

var doIndent = indentTags && indexOf(indentTags, lowerTagName) > -1;
var curPos = doIndent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1);
cm.replaceSelection(">" + (doIndent ? "\n\n" : "") + "</" + tagName + ">",
doIndent ? {line: pos.line + 1, ch: 0} : {line: pos.line, ch: pos.ch + 1});
{head: curPos, anchor: curPos});
if (doIndent) {
cm.indentLine(pos.line + 1);
cm.indentLine(pos.line + 2);
}
return;
} else if (ch == "/" && tok.type == "tag" && tok.string == "<") {
} else if (ch == "/" && tok.string == "<") {
var tagName = state.context && state.context.tagName;
if (tagName) cm.replaceSelection("/" + tagName + ">", "end");
return;
}
throw CodeMirror.Pass;
return CodeMirror.Pass;
}

function indexOf(collection, elt) {
Expand Down
2 changes: 1 addition & 1 deletion addon/edit/continuecomment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

if (token.type == "comment" && mode.blockCommentStart) {
var end = token.string.indexOf(mode.blockCommentEnd);
var full = cm.getRange({line: pos.line, ch: 0}, {line: pos.line, ch: token.end}), found;
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length) {
// Comment ended, don't continue it
} else if (token.string.indexOf(mode.blockCommentStart) == 0) {
Expand Down
27 changes: 19 additions & 8 deletions addon/edit/matchbrackets.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
(function() {
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
(document.documentMode == null || document.documentMode < 8);

var Pos = CodeMirror.Pos;
// Disable brace matching in long lines, since it'll cause hugely slow updates
var maxLineLen = 1000;

var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
function findMatchingBracket(cm) {
var cur = cm.getCursor(), line = cm.getLineHandle(cur.line), pos = cur.ch - 1;
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
if (!match) return null;
var forward = match.charAt(1) == ">", d = forward ? 1 : -1;
var style = cm.getTokenAt({line: cur.line, ch: pos + 1}).type;
var style = cm.getTokenAt(Pos(cur.line, pos + 1)).type;

var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
function scan(line, lineNo, start) {
Expand All @@ -14,7 +21,7 @@
if (start != null) pos = start + d;
for (; pos != end; pos += d) {
var ch = line.text.charAt(pos);
if (re.test(ch) && cm.getTokenAt({line: lineNo, ch: pos + 1}).type == style) {
if (re.test(ch) && cm.getTokenAt(Pos(lineNo, pos + 1)).type == style) {
var match = matching[ch];
if (match.charAt(1) == ">" == forward) stack.push(ch);
else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
Expand All @@ -27,17 +34,21 @@
else found = scan(cm.getLineHandle(i), i);
if (found) break;
}
return {from: {line: cur.line, ch: pos}, to: found && {line: i, ch: found.pos}, match: found && found.match};
return {from: Pos(cur.line, pos), to: found && Pos(i, found.pos), match: found && found.match};
}

function matchBrackets(cm, autoclear) {
var found = findMatchingBracket(cm);
if (!found) return;
if (!found || cm.getLine(found.from.line).length > maxLineLen ||
found.to && cm.getLine(found.to.line).length > maxLineLen)
return;

var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
var one = cm.markText(found.from, {line: found.from.line, ch: found.from.ch + 1},
{className: style});
var two = found.to && cm.markText(found.to, {line: found.to.line, ch: found.to.ch + 1},
{className: style});
var one = cm.markText(found.from, Pos(found.from.line, found.from.ch + 1), {className: style});
var two = found.to && cm.markText(found.to, Pos(found.to.line, found.to.ch + 1), {className: style});
// Kludge to work around the IE bug from issue #1193, where text
// input stops going to the textare whever this fires.
if (ie_lt8 && cm.state.focused) cm.display.input.focus();
var clear = function() {
cm.operation(function() { one.clear(); two && two.clear(); });
};
Expand Down
2 changes: 1 addition & 1 deletion addon/fold/collapserange.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
var from = Math.min(old, line), to = Math.max(old, line);
if (from != to) {
// Finish this fold
var fold = cm.markText({line: from + 1, ch: 0}, {line: to - 1}, {
var fold = cm.markText(CodeMirror.Pos(from + 1, 0), {line: to - 1}, {
collapsed: true,
inclusiveLeft: true,
inclusiveRight: true,
Expand Down
18 changes: 9 additions & 9 deletions addon/fold/foldcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ CodeMirror.tagRangeFinder = function(cm, start) {
depth--;
else
depth++;
if (!depth) return {from: {line: start.line, ch: gtPos + 1},
to: {line: l, ch: match.index}};
if (!depth) return {from: CodeMirror.Pos(start.line, gtPos + 1),
to: CodeMirror.Pos(l, match.index)};
}
}
l++;
Expand All @@ -111,7 +111,7 @@ CodeMirror.braceRangeFinder = function(cm, start) {
for (;;) {
var found = lineText.lastIndexOf("{", at);
if (found < start.ch) break;
tokenType = cm.getTokenAt({line: line, ch: found}).type;
tokenType = cm.getTokenAt(CodeMirror.Pos(line, found + 1)).type;
if (!/^(comment|string)/.test(tokenType)) { startChar = found; break; }
at = found - 1;
}
Expand All @@ -125,16 +125,16 @@ CodeMirror.braceRangeFinder = function(cm, start) {
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (cm.getTokenAt({line: i, ch: pos + 1}).type == tokenType) {
if (cm.getTokenAt(CodeMirror.Pos(i, pos + 1)).type == tokenType) {
if (pos == nextOpen) ++count;
else if (!--count) { end = i; endCh = pos; break outer; }
}
++pos;
}
}
if (end == null || end == line + 1) return;
return {from: {line: line, ch: startChar + 1},
to: {line: end, ch: endCh}};
return {from: CodeMirror.Pos(line, startChar + 1),
to: CodeMirror.Pos(end, endCh)};
};

CodeMirror.indentRangeFinder = function(cm, start) {
Expand All @@ -144,8 +144,8 @@ CodeMirror.indentRangeFinder = function(cm, start) {
var curLine = cm.getLine(i);
if (CodeMirror.countColumn(curLine, null, tabSize) < myIndent &&
CodeMirror.countColumn(cm.getLine(i-1), null, tabSize) > myIndent)
return {from: {line: start.line, ch: firstLine.length},
to: {line: i, ch: curLine.length}};
return {from: CodeMirror.Pos(start.line, firstLine.length),
to: CodeMirror.Pos(i, curLine.length)};
}
};

Expand All @@ -159,7 +159,7 @@ CodeMirror.newFoldFunction = function(rangeFinder, widget) {
}

return function(cm, pos) {
if (typeof pos == "number") pos = {line: pos, ch: 0};
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
var range = rangeFinder(cm, pos);
if (!range) return;

Expand Down
14 changes: 8 additions & 6 deletions addon/hint/javascript-hint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(function () {
var Pos = CodeMirror.Pos;

function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
Expand Down Expand Up @@ -26,20 +28,20 @@
}
// If it is a property, find out what it is a property of.
while (tprop.type == "property") {
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (tprop.string != ".") return;
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (tprop.string == ')') {
var level = 1;
do {
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
tprop = getToken(editor, Pos(cur.line, tprop.start));
switch (tprop.string) {
case ')': level++; break;
case '(': level--; break;
default: break;
}
} while (level > 0);
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (tprop.type.indexOf("variable") === 0)
tprop.type = "function";
else return; // no clue
Expand All @@ -48,8 +50,8 @@
context.push(tprop);
}
return {list: getCompletions(token, context, keywords, options),
from: {line: cur.line, ch: token.start},
to: {line: cur.line, ch: token.end}};
from: Pos(cur.line, token.start),
to: Pos(cur.line, token.end)};
}

CodeMirror.javascriptHint = function(editor, options) {
Expand Down
4 changes: 2 additions & 2 deletions addon/hint/pig-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
}

return {list: completionList,
from: {line: cur.line, ch: token.start},
to: {line: cur.line, ch: token.end}};
from: CodeMirror.Pos(cur.line, token.start),
to: CodeMirror.Pos(cur.line, token.end)};
}

CodeMirror.pigHint = function(editor) {
Expand Down
4 changes: 2 additions & 2 deletions addon/hint/python-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
}

return {list: completionList,
from: {line: cur.line, ch: token.start},
to: {line: cur.line, ch: token.end}};
from: CodeMirror.Pos(cur.line, token.start),
to: CodeMirror.Pos(cur.line, token.end)};
}

CodeMirror.pythonHint = function(editor) {
Expand Down
38 changes: 38 additions & 0 deletions addon/hint/show-hint.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.CodeMirror-hints {
position: absolute;
z-index: 10;
overflow: hidden;
list-style: none;

margin: 0;
padding: 2px;

-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
border-radius: 3px;
border: 1px solid silver;

background: white;
font-size: 90%;
font-family: monospace;

max-height: 20em;
overflow-y: auto;
}

.CodeMirror-hint {
margin: 0;
padding: 0 4px;
border-radius: 2px;
max-width: 19em;
overflow: hidden;
white-space: pre;
color: black;
cursor: pointer;
}

.CodeMirror-hint-active {
background: #08f;
color: white;
}
Loading