Showing with 3,546 additions and 584 deletions.
  1. +2 −0 .gitignore
  2. +3 −3 addon/comment/comment.js
  3. +3 −1 addon/edit/closebrackets.js
  4. +51 −0 addon/edit/matchtags.js
  5. +9 −6 addon/fold/brace-fold.js
  6. +9 −4 addon/fold/foldcode.js
  7. +122 −0 addon/fold/foldgutter.js
  8. +3 −2 addon/fold/indent-fold.js
  9. +24 −17 addon/fold/xml-fold.js
  10. +34 −0 addon/hint/anyword-hint.js
  11. +5 −3 addon/hint/html-hint.js
  12. +7 −3 addon/hint/javascript-hint.js
  13. +4 −2 addon/hint/pig-hint.js
  14. +4 −2 addon/hint/python-hint.js
  15. +6 −2 addon/hint/show-hint.js
  16. +5 −2 addon/hint/xml-hint.js
  17. +3 −2 addon/lint/coffeescript-lint.js
  18. +3 −6 addon/lint/javascript-lint.js
  19. +3 −2 addon/lint/json-lint.js
  20. +12 −6 addon/lint/lint.js
  21. +39 −29 addon/merge/merge.css
  22. +40 −24 addon/merge/merge.js
  23. +3 −1 addon/runmode/runmode-standalone.js
  24. +3 −1 addon/runmode/runmode.node.js
  25. +11 −9 addon/search/match-highlighter.js
  26. +1 −1 addon/selection/active-line.js
  27. +85 −0 addon/tern/tern.css
  28. +608 −0 addon/tern/tern.js
  29. +39 −0 addon/tern/worker.js
  30. +1 −1 bower.json
  31. +69 −0 demo/anywordhint.html
  32. +1 −1 demo/complete.html
  33. +27 −11 demo/folding.html
  34. +1 −1 demo/html5complete.html
  35. +3 −3 demo/lint.html
  36. +1 −1 demo/matchhighlighter.html
  37. +38 −0 demo/matchtags.html
  38. +122 −0 demo/tern.html
  39. +10 −0 demo/theme.html
  40. +2 −2 demo/vim.html
  41. +2 −2 demo/xmlcomplete.html
  42. +29 −20 doc/compress.html
  43. +161 −54 doc/manual.html
  44. +4 −0 doc/modes.html
  45. +12 −0 doc/oldrelease.html
  46. +6 −0 doc/realworld.html
  47. +12 −13 index.html
  48. +120 −101 keymap/vim.js
  49. +10 −0 lib/codemirror.css
  50. +177 −93 lib/codemirror.js
  51. +2 −1 mode/clike/clike.js
  52. +2 −1 mode/coffeescript/coffeescript.js
  53. +33 −16 mode/css/css.js
  54. +1 −1 mode/css/scss_test.js
  55. +13 −0 mode/css/test.js
  56. +2 −1 mode/groovy/groovy.js
  57. +54 −0 mode/jade/index.html
  58. +90 −0 mode/jade/jade.js
  59. +21 −18 mode/javascript/javascript.js
  60. +10 −0 mode/javascript/test.js
  61. +6 −1 mode/markdown/index.html
  62. +26 −1 mode/markdown/markdown.js
  63. +14 −0 mode/markdown/test.js
  64. +5 −1 mode/meta.js
  65. +167 −0 mode/nginx/index.html
  66. +163 −0 mode/nginx/nginx.js
  67. +43 −3 mode/python/index.html
  68. +19 −2 mode/python/python.js
  69. +1 −1 mode/rst/LICENSE.txt
  70. +30 −19 mode/rst/rst.js
  71. +4 −4 mode/ruby/ruby.js
  72. +2 −1 mode/rust/rust.js
  73. +12 −2 mode/smalltalk/smalltalk.js
  74. +107 −0 mode/smartymixed/index.html
  75. +170 −0 mode/smartymixed/smartymixed.js
  76. +4 −2 mode/sparql/sparql.js
  77. +2 −1 mode/vbscript/index.html
  78. +330 −22 mode/vbscript/vbscript.js
  79. +18 −3 mode/xml/xml.js
  80. +1 −1 package.json
  81. +1 −0 test/index.html
  82. +1 −1 test/mode_test.js
  83. +29 −0 test/test.js
  84. +41 −33 test/vim_test.js
  85. +33 −0 theme/3024-day.css
  86. +33 −0 theme/3024-night.css
  87. +33 −0 theme/base16-dark.css
  88. +33 −0 theme/base16-light.css
  89. +1 −1 theme/lesser-dark.css
  90. +5 −14 theme/midnight.css
  91. +33 −0 theme/tomorrow-night-eighties.css
  92. +2 −2 theme/vibrant-ink.css
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/npm-debug.log
test.html
.tern-*
*~
*.swp
6 changes: 3 additions & 3 deletions addon/comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

CodeMirror.defineExtension("lineComment", function(from, to, options) {
if (!options) options = noOptions;
var self = this, mode = CodeMirror.innerMode(self.getMode(), self.getTokenAt(from).state).mode;
var self = this, mode = self.getModeAt(from);
var commentString = options.lineComment || mode.lineComment;
if (!commentString) {
if (options.blockCommentStart || mode.blockCommentStart) {
Expand Down Expand Up @@ -52,7 +52,7 @@

CodeMirror.defineExtension("blockComment", function(from, to, options) {
if (!options) options = noOptions;
var self = this, mode = CodeMirror.innerMode(self.getMode(), self.getTokenAt(from).state).mode;
var self = this, mode = self.getModeAt(from);
var startString = options.blockCommentStart || mode.blockCommentStart;
var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) {
Expand Down Expand Up @@ -85,7 +85,7 @@

CodeMirror.defineExtension("uncomment", function(from, to, options) {
if (!options) options = noOptions;
var self = this, mode = CodeMirror.innerMode(self.getMode(), self.getTokenAt(from).state).mode;
var self = this, mode = self.getModeAt(from);
var end = Math.min(to.line, self.lastLine()), start = Math.min(from.line, end);

// Try finding line comments
Expand Down
4 changes: 3 additions & 1 deletion addon/edit/closebrackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
if (cm.somethingSelected()) return surround(cm);
if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
var cur = cm.getCursor(), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);
var line = cm.getLine(cur.line), nextChar = line.charAt(cur.ch);
var line = cm.getLine(cur.line), nextChar = line.charAt(cur.ch), curChar = cur.ch > 0 ? line.charAt(cur.ch - 1) : "";
if (left == right && CodeMirror.isWordChar(curChar))
return CodeMirror.Pass;
if (line.length == cur.ch || closingBrackets.indexOf(nextChar) >= 0 || SPACE_CHAR_REGEX.test(nextChar))
cm.replaceSelection(left + right, {head: ahead, anchor: ahead});
else
Expand Down
51 changes: 51 additions & 0 deletions addon/edit/matchtags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(function() {
"use strict";

CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.off("cursorActivity", doMatchTags);
cm.off("viewportChange", maybeUpdateMatch);
clear(cm);
}
if (val) {
cm.on("cursorActivity", doMatchTags);
cm.on("viewportChange", maybeUpdateMatch);
doMatchTags(cm);
}
});

function clear(cm) {
if (cm.state.matchedTag) {
cm.state.matchedTag.clear();
cm.state.matchedTag = null;
}
}

function doMatchTags(cm) {
cm.state.failedTagMatch = false;
cm.operation(function() {
clear(cm);
var cur = cm.getCursor(), range = cm.getViewport();
range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
var match = CodeMirror.findMatchingTag(cm, cur, range);
if (!match) return;
var other = match.at == "close" ? match.open : match.close;
if (other)
cm.state.matchedTag = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
else
cm.state.failedTagMatch = true;
});
}

function maybeUpdateMatch(cm) {
if (cm.state.failedTagMatch) doMatchTags(cm);
}

CodeMirror.commands.toMatchingTag = function(cm) {
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
if (found) {
var other = found.at == "close" ? found.open : found.close;
if (other) cm.setSelection(other.to, other.from);
}
};
})();
15 changes: 9 additions & 6 deletions addon/fold/brace-fold.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CodeMirror.braceRangeFinder = function(cm, start) {
CodeMirror.registerHelper("fold", "brace", function(cm, start) {
var line = start.line, lineText = cm.getLine(line);
var startCh, tokenType;

Expand Down Expand Up @@ -44,9 +44,10 @@ CodeMirror.braceRangeFinder = function(cm, start) {
if (end == null || line == end && endCh == startCh) return;
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
};
});
CodeMirror.braceRangeFinder = CodeMirror.fold.brace; // deprecated

CodeMirror.importRangeFinder = function(cm, start) {
CodeMirror.registerHelper("fold", "import", function(cm, start) {
function hasImport(line) {
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
Expand All @@ -68,9 +69,10 @@ CodeMirror.importRangeFinder = function(cm, start) {
end = next.end;
}
return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
};
});
CodeMirror.importRangeFinder = CodeMirror.fold["import"]; // deprecated

CodeMirror.includeRangeFinder = function(cm, start) {
CodeMirror.registerHelper("fold", "include", function(cm, start) {
function hasInclude(line) {
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
Expand All @@ -87,4 +89,5 @@ CodeMirror.includeRangeFinder = function(cm, start) {
}
return {from: CodeMirror.Pos(start, has + 1),
to: cm.clipPos(CodeMirror.Pos(end))};
};
});
CodeMirror.includeRangeFinder = CodeMirror.fold.include; // deprecated
13 changes: 9 additions & 4 deletions addon/fold/foldcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"use strict";

function doFold(cm, pos, options) {
var finder = options.call ? options : (options && options.rangeFinder);
var finder = options && (options.call ? options : options.rangeFinder);
if (!finder) finder = cm.getHelper(pos, "fold");
if (!finder) return;
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
var minSize = options && options.minFoldSize || 0;
Expand All @@ -29,12 +30,16 @@
if (!range || range.cleared) return;

var myWidget = makeWidget(options);
CodeMirror.on(myWidget, "mousedown", function() {myRange.clear();});
CodeMirror.on(myWidget, "mousedown", function() { myRange.clear(); });
var myRange = cm.markText(range.from, range.to, {
replacedWith: myWidget,
clearOnEnter: true,
__isFold: true
});
myRange.on("clear", function(from, to) {
CodeMirror.signal(cm, "unfold", cm, from, to);
});
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
}

function makeWidget(options) {
Expand All @@ -56,13 +61,13 @@
// New-style interface
CodeMirror.defineExtension("foldCode", function(pos, options) { doFold(this, pos, options); });

CodeMirror.combineRangeFinders = function() {
CodeMirror.registerHelper("fold", "combine", function() {
var funcs = Array.prototype.slice.call(arguments, 0);
return function(cm, start) {
for (var i = 0; i < funcs.length; ++i) {
var found = funcs[i](cm, start);
if (found) return found;
}
};
};
});
})();
122 changes: 122 additions & 0 deletions addon/fold/foldgutter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
(function() {
"use strict";

CodeMirror.defineOption("foldGutter", false, function(cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.clearGutter(cm.state.foldGutter.options.gutter);
cm.state.foldGutter = null;
cm.off("gutterClick", onGutterClick);
cm.off("change", onChange);
cm.off("viewportChange", onViewportChange);
cm.off("fold", onFold);
cm.off("unfold", onFold);
}
if (val) {
cm.state.foldGutter = new State(parseOptions(val));
updateInViewport(cm);
cm.on("gutterClick", onGutterClick);
cm.on("change", onChange);
cm.on("viewportChange", onViewportChange);
cm.on("fold", onFold);
cm.on("unfold", onFold);
}
});

var Pos = CodeMirror.Pos;

function State(options) {
this.options = options;
this.from = this.to = 0;
}

function parseOptions(opts) {
if (opts === true) opts = {};
if (opts.gutter == null) opts.gutter = "CodeMirror-foldgutter";
if (opts.indicatorOpen == null) opts.indicatorOpen = "CodeMirror-foldgutter-open";
if (opts.indicatorFolded == null) opts.indicatorFolded = "CodeMirror-foldgutter-folded";
return opts;
}

function isFolded(cm, line) {
var marks = cm.findMarksAt(Pos(line));
for (var i = 0; i < marks.length; ++i)
if (marks[i].__isFold && marks[i].find().from.line == line) return true;
}

function marker(spec) {
if (typeof spec == "string") {
var elt = document.createElement("div");
elt.className = spec;
return elt;
} else {
return spec.cloneNode(true);
}
}

function updateFoldInfo(cm, from, to) {
var opts = cm.state.foldGutter.options, cur = from;
cm.eachLine(from, to, function(line) {
var mark = null;
if (isFolded(cm, cur)) {
mark = marker(opts.indicatorFolded);
} else {
var pos = Pos(cur, 0), func = opts.rangeFinder || cm.getHelper(pos, "fold");
var range = func && func(cm, pos);
if (range && range.from.line + 1 < range.to.line)
mark = marker(opts.indicatorOpen);
}
cm.setGutterMarker(line, opts.gutter, mark);
++cur;
});
}

function updateInViewport(cm) {
var vp = cm.getViewport(), state = cm.state.foldGutter;
if (!state) return;
cm.operation(function() {
updateFoldInfo(cm, vp.from, vp.to);
});
state.from = vp.from; state.to = vp.to;
}

function onGutterClick(cm, line, gutter) {
var opts = cm.state.foldGutter.options;
if (gutter != opts.gutter) return;
cm.foldCode(Pos(line, 0), opts.rangeFinder);
}

function onChange(cm) {
var state = cm.state.foldGutter;
state.from = state.to = 0;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, 600);
}

function onViewportChange(cm) {
var state = cm.state.foldGutter;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function() {
var vp = cm.getViewport();
if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
updateInViewport(cm);
} else {
cm.operation(function() {
if (vp.from < state.from) {
updateFoldInfo(cm, vp.from, state.from);
state.from = vp.from;
}
if (vp.to > state.to) {
updateFoldInfo(cm, state.to, vp.to);
state.to = vp.to;
}
});
}
}, 400);
}

function onFold(cm, from) {
var state = cm.state.foldGutter, line = from.line;
if (line >= state.from && line < state.to)
updateFoldInfo(cm, line, line + 1);
}
})();
5 changes: 3 additions & 2 deletions addon/fold/indent-fold.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CodeMirror.indentRangeFinder = function(cm, start) {
CodeMirror.registerHelper("fold", "indent", function(cm, start) {
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
var myIndent = CodeMirror.countColumn(firstLine, null, tabSize);
for (var i = start.line + 1, end = cm.lineCount(); i < end; ++i) {
Expand All @@ -8,4 +8,5 @@ CodeMirror.indentRangeFinder = function(cm, start) {
return {from: CodeMirror.Pos(start.line, firstLine.length),
to: CodeMirror.Pos(i, curLine.length)};
}
};
});
CodeMirror.indentRangeFinder = CodeMirror.fold.indent; // deprecated
Loading