Showing with 2,978 additions and 705 deletions.
  1. +13 −0 AUTHORS
  2. +1 −1 LICENSE
  3. +2 −2 README.md
  4. +2 −2 addon/display/rulers.js
  5. +35 −18 addon/edit/closebrackets.js
  6. +18 −9 addon/edit/matchbrackets.js
  7. +1 −1 addon/hint/css-hint.js
  8. +3 −1 addon/hint/show-hint.js
  9. +31 −13 addon/hint/xml-hint.js
  10. +1 −0 addon/lint/css-lint.js
  11. +1 −0 addon/lint/javascript-lint.js
  12. +15 −10 addon/merge/merge.js
  13. +8 −2 addon/mode/overlay.js
  14. +1 −0 addon/runmode/runmode-standalone.js
  15. +1 −0 addon/runmode/runmode.js
  16. +1 −0 addon/runmode/runmode.node.js
  17. +14 −14 addon/search/search.js
  18. +1 −1 demo/bidi.html
  19. +26 −0 demo/merge.html
  20. +9 −3 demo/vim.html
  21. +4 −0 demo/xmlcomplete.html
  22. +4 −0 doc/compress.html
  23. +2 −2 doc/docs.css
  24. +18 −6 doc/manual.html
  25. +2 −0 doc/realworld.html
  26. +35 −3 doc/releases.html
  27. +0 −3 doc/upgrade_v4.html
  28. +8 −3 index.html
  29. +14 −2 keymap/sublime.js
  30. +212 −141 keymap/vim.js
  31. +5 −3 lib/codemirror.css
  32. +302 −115 lib/codemirror.js
  33. +4 −5 mode/clike/clike.js
  34. +4 −0 mode/clike/index.html
  35. +1 −1 mode/cobol/index.html
  36. +23 −6 mode/css/css.js
  37. +3 −0 mode/css/test.js
  38. +64 −0 mode/django/django.js
  39. +63 −0 mode/django/index.html
  40. +284 −0 mode/dylan/dylan.js
  41. +407 −0 mode/dylan/index.html
  42. +1 −1 mode/erlang/erlang.js
  43. +1 −0 mode/go/go.js
  44. +3 −8 mode/haml/haml.js
  45. +1 −1 mode/haml/test.js
  46. +75 −3 mode/haxe/haxe.js
  47. +25 −4 mode/haxe/index.html
  48. +3 −1 mode/index.html
  49. +14 −8 mode/javascript/javascript.js
  50. +19 −0 mode/javascript/test.js
  51. +20 −16 mode/jinja2/index.html
  52. +111 −35 mode/jinja2/jinja2.js
  53. +4 −4 mode/livescript/livescript.js
  54. +5 −2 mode/markdown/markdown.js
  55. +2 −0 mode/meta.js
  56. +5 −1 mode/php/index.html
  57. +99 −9 mode/php/php.js
  58. +145 −0 mode/php/test.js
  59. +1 −2 mode/r/index.html
  60. +3 −1 mode/r/r.js
  61. +89 −101 mode/verilog/index.html
  62. +114 −0 mode/verilog/test.js
  63. +237 −78 mode/verilog/verilog.js
  64. +48 −0 mode/xml/test.js
  65. +61 −29 mode/xml/xml.js
  66. +1 −1 package.json
  67. +23 −0 test/doc_test.js
  68. +6 −0 test/index.html
  69. +2 −0 test/mode_test.js
  70. +27 −0 test/test.js
  71. +186 −7 test/vim_test.js
  72. +0 −1 theme/ambiance.css
  73. +0 −4 theme/lesser-dark.css
  74. +1 −1 theme/mdn-like.css
  75. +0 −1 theme/pastel-on-dark.css
  76. +0 −2 theme/rubyblue.css
  77. +3 −17 theme/solarized.css
13 changes: 13 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ansel Santosa
Anthony Grimes
Anton Kovalyov
areos
as3boyan
AtomicPages LLC
Atul Bhouraskar
Aurelian Oancea
Expand All @@ -48,6 +49,7 @@ Beni Cherniavsky-Paskin
Benjamin DeCoste
Ben Keen
Bernhard Sirlinger
Bert Chang
Billy Moon
binny
B Krishna Chaitanya
Expand Down Expand Up @@ -88,6 +90,7 @@ dignifiedquire
domagoj412
Dominator008
Domizio Demichelis
Doug Wikle
Drew Bratcher
Drew Hintz
Drew Khoury
Expand All @@ -101,6 +104,7 @@ Eric Allam
eustas
Fabien O'Carroll
Fabio Zendhi Nagao
Faiza Alsaied
Fauntleroy
fbuchinger
feizhang365
Expand All @@ -116,6 +120,7 @@ Gabriel Horner
Gabriel Nahmias
galambalazs
Gautam Mehta
Gergely Hegykozi
Glenn Jorde
Glenn Ruehle
Golevka
Expand All @@ -124,6 +129,7 @@ Grant Skinner
greengiant
Guillaume Massé
Guillaume Massé
Gustavo Rodrigues
Hans Engel
Hardest
Hasan Karahan
Expand Down Expand Up @@ -171,6 +177,7 @@ Jon Malmaud
Joost-Wim Boekesteijn
Joseph Pecoraro
Joshua Newman
Josh Watzman
jots
jsoojeon
Juan Benavides Romero
Expand Down Expand Up @@ -219,6 +226,7 @@ Matthias BUSSONNIER
Matt McDonald
Matt Pass
Matt Sacks
mauricio
Maximilian Hils
Maxim Kraev
Max Kirsch
Expand Down Expand Up @@ -255,6 +263,7 @@ Nikolay Kostov
nlwillia
pablo
Page
paris
Patil Arpith
Patrick Strawderman
Paul Garvin
Expand All @@ -267,6 +276,7 @@ peterkroon
Peter Kroon
prasanthj
Prasanth J
Radek Piórkowski
Rahul
Randy Edmunds
Rasmus Erik Voel Jensen
Expand All @@ -290,6 +300,7 @@ Shawn A
sheopory
Shiv Deepak
Shmuel Englard
Shubham Jain
soliton4
sonson
spastorelli
Expand All @@ -301,6 +312,7 @@ Steffen Beyer
Steve O'Hara
stoskov
Taha Jahangir
Takuji Shimokawa
Tarmil
tfjgeorge
Thaddee Tyl
Expand All @@ -321,6 +333,7 @@ Triangle717
twifkak
Vestimir Markov
vf
Vincent Woo
Volker Mische
wenli
Wesley Wiser
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2013 by Marijn Haverbeke <marijnh@gmail.com> and others
Copyright (C) 2014 by Marijn Haverbeke <marijnh@gmail.com> and others

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CodeMirror
[![Build Status](https://secure.travis-ci.org/marijnh/CodeMirror.png?branch=master)](http://travis-ci.org/marijnh/CodeMirror)
[![NPM version](https://badge.fury.io/js/codemirror.png)](http://badge.fury.io/js/codemirror)
[![Build Status](https://travis-ci.org/marijnh/CodeMirror.svg)](https://travis-ci.org/marijnh/CodeMirror)
[![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror)

CodeMirror is a JavaScript component that provides a code editor in
the browser. When a mode is available for the language you are coding
Expand Down
4 changes: 2 additions & 2 deletions addon/display/rulers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
var val = cm.getOption("rulers");
var cw = cm.defaultCharWidth();
var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left;
var bot = -cm.display.scroller.offsetHeight;
var minH = cm.display.scroller.offsetHeight + 30;
for (var i = 0; i < val.length; i++) {
var elt = document.createElement("div");
var col, cls = null;
Expand All @@ -42,7 +42,7 @@
cls = val[i].className;
}
elt.className = "CodeMirror-ruler" + (cls ? " " + cls : "");
elt.style.cssText = "left: " + (left + col * cw) + "px; top: -50px; bottom: " + bot + "px";
elt.style.cssText = "left: " + (left + col * cw) + "px; top: -50px; bottom: -20px; min-height: " + minH + "px";
cm.display.lineSpace.insertBefore(elt, cm.display.cursorDiv);
}
}
Expand Down
53 changes: 35 additions & 18 deletions addon/edit/closebrackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
var SPACE_CHAR_REGEX = /\s/;

var Pos = CodeMirror.Pos;

CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
if (old != CodeMirror.Init && old)
cm.removeKeyMap("autoCloseBrackets");
Expand All @@ -26,8 +28,8 @@
});

function charsAround(cm, pos) {
var str = cm.getRange(CodeMirror.Pos(pos.line, pos.ch - 1),
CodeMirror.Pos(pos.line, pos.ch + 1));
var str = cm.getRange(Pos(pos.line, pos.ch - 1),
Pos(pos.line, pos.ch + 1));
return str.length == 2 ? str : null;
}

Expand All @@ -44,7 +46,7 @@
}
for (var i = ranges.length - 1; i >= 0; i--) {
var cur = ranges[i].head;
cm.replaceRange("", CodeMirror.Pos(cur.line, cur.ch - 1), CodeMirror.Pos(cur.line, cur.ch + 1));
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
}
}
};
Expand All @@ -58,11 +60,18 @@
var range = ranges[i], cur = range.head, curType;
if (left == "'" && cm.getTokenTypeAt(cur) == "comment")
return CodeMirror.Pass;
var next = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
if (!range.empty())
curType = "surround";
else if (left == right && next == right)
curType = "skip";
else if (left == right && next == right) {
if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left)
curType = "skipThree";
else
curType = "skip";
} else if (left == right && cur.ch > 1 &&
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left &&
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left))
curType = "addFour";
else if (left == right && CodeMirror.isWordChar(next))
return CodeMirror.Pass;
else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next))
Expand All @@ -73,24 +82,32 @@
else if (type != curType) return CodeMirror.Pass;
}

if (type == "skip") {
cm.execCommand("goCharRight");
} else if (type == "surround") {
var sels = cm.getSelections();
for (var i = 0; i < sels.length; i++)
sels[i] = left + sels[i] + right;
cm.replaceSelections(sels, "around");
} else if (type == "both") {
cm.replaceSelection(left + right, null);
cm.execCommand("goCharLeft");
}
cm.operation(function() {
if (type == "skip") {
cm.execCommand("goCharRight");
} else if (type == "skipThree") {
for (var i = 0; i < 3; i++)
cm.execCommand("goCharRight");
} else if (type == "surround") {
var sels = cm.getSelections();
for (var i = 0; i < sels.length; i++)
sels[i] = left + sels[i] + right;
cm.replaceSelections(sels, "around");
} else if (type == "both") {
cm.replaceSelection(left + right, null);
cm.execCommand("goCharLeft");
} else if (type == "addFour") {
cm.replaceSelection(left + left + left + left, "before");
cm.execCommand("goCharRight");
}
});
};
if (left != right) map["'" + right + "'"] = function(cm) {
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (!range.empty() ||
cm.getRange(range.head, CodeMirror.Pos(range.head.line, range.head.ch + 1)) != right)
cm.getRange(range.head, Pos(range.head.line, range.head.ch + 1)) != right)
return CodeMirror.Pass;
}
cm.execCommand("goCharRight");
Expand Down
27 changes: 18 additions & 9 deletions addon/edit/matchbrackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));

var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
if (found == null) return null;
return {from: Pos(where.line, pos), to: found && found.pos,
match: found && found.ch == match.charAt(0), forward: dir > 0};
}

// bracketRegex is used to specify which type of bracket to scan
// should be a regexp, e.g. /[[\]]/
//
// Note: If "where" is on an open bracket, then this bracket is ignored.
//
// Returns false when no bracket was found, null when it reached
// maxScanLines and gave up
function scanForBracket(cm, where, dir, style, config) {
var maxScanLen = (config && config.maxScanLineLength) || 10000;
var maxScanLines = (config && config.maxScanLines) || 500;
var maxScanLines = (config && config.maxScanLines) || 1000;

var stack = [], re = /[(){}[\]]/;
var stack = [];
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
Expand All @@ -49,6 +58,7 @@
}
}
}
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
}

function matchBrackets(cm, autoclear, config) {
Expand All @@ -57,11 +67,10 @@
var marks = [], ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config);
if (match && cm.getLine(match.from.line).length <= maxHighlightLen &&
match.to && cm.getLine(match.to.line).length <= maxHighlightLen) {
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
if (match.to)
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
}
}
Expand Down Expand Up @@ -99,10 +108,10 @@
});

CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict){
return findMatchingBracket(this, pos, strict);
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){
return findMatchingBracket(this, pos, strict, config);
});
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style){
return scanForBracket(this, pos, dir, style);
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
return scanForBracket(this, pos, dir, style, config);
});
});
2 changes: 1 addition & 1 deletion addon/hint/css-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
result.push(name);
}

var st = token.state.state;
var st = inner.state.state;
if (st == "pseudo" || token.type == "variable-3") {
add(pseudoClasses);
} else if (st == "block" || st == "maybeprop") {
Expand Down
4 changes: 3 additions & 1 deletion addon/hint/show-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
pick: function(data, i) {
var completion = data.list[i];
if (completion.hint) completion.hint(this.cm, data, completion);
else this.cm.replaceRange(getText(completion), completion.from||data.from, completion.to||data.to);
else this.cm.replaceRange(getText(completion), completion.from || data.from,
completion.to || data.to, "complete");
CodeMirror.signal(data, "pick", completion);
this.close();
},
Expand Down Expand Up @@ -100,6 +101,7 @@
data = data_;
if (finished) return;
if (!data || !data.list.length) return done();
if (completion.widget) completion.widget.close();
completion.widget = new Widget(completion, data);
}

Expand Down
44 changes: 31 additions & 13 deletions addon/hint/xml-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,45 @@
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
if (inner.mode.name != "xml") return;
var result = [], replaceToken = false, prefix;
var isTag = token.string.charAt(0) == "<";
if (!inner.state.tagName || isTag) { // Tag completion
if (isTag) {
prefix = token.string.slice(1);
replaceToken = true;
}
var tag = /\btag\b/.test(token.type), tagName = tag && /^\w/.test(token.string), tagStart;
if (tagName) {
var before = cm.getLine(cur.line).slice(Math.max(0, token.start - 2), token.start);
var tagType = /<\/$/.test(before) ? "close" : /<$/.test(before) ? "open" : null;
if (tagType) tagStart = token.start - (tagType == "close" ? 2 : 1);
} else if (tag && token.string == "<") {
tagType = "open";
} else if (tag && token.string == "</") {
tagType = "close";
}
if (!tag && !inner.state.tagName || tagType) {
if (tagName)
prefix = token.string;
replaceToken = tagType;
var cx = inner.state.context, curTag = cx && tags[cx.tagName];
var childList = cx ? curTag && curTag.children : tags["!top"];
if (childList) {
if (childList && tagType != "close") {
for (var i = 0; i < childList.length; ++i) if (!prefix || childList[i].lastIndexOf(prefix, 0) == 0)
result.push("<" + childList[i]);
} else {
for (var name in tags) if (tags.hasOwnProperty(name) && name != "!top" && (!prefix || name.lastIndexOf(prefix, 0) == 0))
result.push("<" + name);
} else if (tagType != "close") {
for (var name in tags)
if (tags.hasOwnProperty(name) && name != "!top" && name != "!attrs" && (!prefix || name.lastIndexOf(prefix, 0) == 0))
result.push("<" + name);
}
if (cx && (!prefix || ("/" + cx.tagName).lastIndexOf(prefix, 0) == 0))
if (cx && (!prefix || tagType == "close" && cx.tagName.lastIndexOf(prefix, 0) == 0))
result.push("</" + cx.tagName + ">");
} else {
// Attribute completion
var curTag = tags[inner.state.tagName], attrs = curTag && curTag.attrs;
if (!attrs) return;
var globalAttrs = tags["!attrs"];
if (!attrs && !globalAttrs) return;
if (!attrs) {
attrs = globalAttrs;
} else if (globalAttrs) { // Combine tag-local and global attributes
var set = {};
for (var nm in globalAttrs) if (globalAttrs.hasOwnProperty(nm)) set[nm] = globalAttrs[nm];
for (var nm in attrs) if (attrs.hasOwnProperty(nm)) set[nm] = attrs[nm];
attrs = set;
}
if (token.type == "string" || token.string == "=") { // A value
var before = cm.getRange(Pos(cur.line, Math.max(0, cur.ch - 60)),
Pos(cur.line, token.type == "string" ? token.start : token.end));
Expand Down Expand Up @@ -66,7 +84,7 @@
}
return {
list: result,
from: replaceToken ? Pos(cur.line, token.start) : cur,
from: replaceToken ? Pos(cur.line, tagStart == null ? token.start : tagStart) : cur,
to: replaceToken ? Pos(cur.line, token.end) : cur
};
}
Expand Down
1 change: 1 addition & 0 deletions addon/lint/css-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

CodeMirror.registerHelper("lint", "css", function(text) {
var found = [];
if (!window.CSSLint) return found;
var results = CSSLint.verify(text), messages = results.messages, message = null;
for ( var i = 0; i < messages.length; i++) {
message = messages[i];
Expand Down
Loading