2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/node_modules
/npm-debug.log
test.html
/test*.html
.tern-*
*~
*.swp
Expand Down
9 changes: 9 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Alexander Solovyov
Alexandre Bique
alexey-k
Alex Piggott
Aliaksei Chapyzhenka
Amsul
amuntean
Amy
Expand Down Expand Up @@ -82,6 +83,7 @@ Chris Granger
Chris Houseknecht
Chris Morgan
Christian Oyarzun
Christian Petrov
Christopher Brown
ciaranj
CodeAnimal
Expand Down Expand Up @@ -111,6 +113,7 @@ Deep Thought
Devon Carew
dignifiedquire
Dimage Sapelkin
Dmitry Kiselyov
domagoj412
Dominator008
Domizio Demichelis
Expand Down Expand Up @@ -149,6 +152,7 @@ Gautam Mehta
gekkoe
Gerard Braad
Gergely Hegykozi
Giovanni Calò
Glenn Jorde
Glenn Ruehle
Golevka
Expand Down Expand Up @@ -235,6 +239,7 @@ Konstantin Lopuhin
koops
ks-ifware
kubelsmieci
KwanEsq
Lanfei
Lanny
Laszlo Vidacs
Expand Down Expand Up @@ -289,6 +294,7 @@ Michael Lehenbauer
Michael Zhou
Mighty Guava
Miguel Castillo
mihailik
Mike
Mike Brevoort
Mike Diaz
Expand All @@ -306,6 +312,7 @@ Nathan Williams
ndr
nerbert
nextrevision
ngn
nguillaumin
Ng Zhi An
Nicholas Bollweg
Expand Down Expand Up @@ -344,6 +351,7 @@ Randall Mason
Randy Burden
Randy Edmunds
Rasmus Erik Voel Jensen
Ray Ratchup
Richard van der Meer
Richard Z.H. Wang
Robert Crossfield
Expand Down Expand Up @@ -423,5 +431,6 @@ YNH Webdev
Yunchi Luo
Yuvi Panda
Zachary Dremann
Zhang Hao
zziuni
魏鹏刚
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CodeMirror
[![Build Status](https://travis-ci.org/codemirror/CodeMirror.svg)](https://travis-ci.org/codemirror/CodeMirror)
[![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror)
[![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror)
[Funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png)](https://marijnhaverbeke.nl/fund/)

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
10 changes: 6 additions & 4 deletions addon/edit/closebrackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
mod(CodeMirror);
})(function(CodeMirror) {
var DEFAULT_BRACKETS = "()[]{}''\"\"";
var DEFAULT_TRIPLES = "'\"";
var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
var SPACE_CHAR_REGEX = /\s/;

Expand All @@ -19,13 +20,14 @@
if (old != CodeMirror.Init && old)
cm.removeKeyMap("autoCloseBrackets");
if (!val) return;
var pairs = DEFAULT_BRACKETS, explode = DEFAULT_EXPLODE_ON_ENTER;
var pairs = DEFAULT_BRACKETS, triples = DEFAULT_TRIPLES, explode = DEFAULT_EXPLODE_ON_ENTER;
if (typeof val == "string") pairs = val;
else if (typeof val == "object") {
if (val.pairs != null) pairs = val.pairs;
if (val.triples != null) triples = val.triples;
if (val.explode != null) explode = val.explode;
}
var map = buildKeymap(pairs);
var map = buildKeymap(pairs, triples);
if (explode) map.Enter = buildExplodeHandler(explode);
cm.addKeyMap(map);
});
Expand All @@ -52,7 +54,7 @@
}
}

function buildKeymap(pairs) {
function buildKeymap(pairs, triples) {
var map = {
name : "autoCloseBrackets",
Backspace: function(cm) {
Expand Down Expand Up @@ -85,7 +87,7 @@
curType = "skipThree";
else
curType = "skip";
} else if (left == right && cur.ch > 1 &&
} else if (left == right && cur.ch > 1 && triples.indexOf(left) >= 0 &&
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";
Expand Down
2 changes: 1 addition & 1 deletion addon/edit/closetag.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

function autoCloseSlash(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
autoCloseCurrent(cm, true);
return autoCloseCurrent(cm, true);
}

CodeMirror.commands.closeTag = function(cm) { return autoCloseCurrent(cm); };
Expand Down
16 changes: 12 additions & 4 deletions addon/fold/foldgutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,26 @@
}

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

function onChange(cm) {
var state = cm.state.foldGutter, opts = cm.state.foldGutter.options;
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
state.from = state.to = 0;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, opts.foldOnChangeTimeSpan || 600);
}

function onViewportChange(cm) {
var state = cm.state.foldGutter, opts = cm.state.foldGutter.options;
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function() {
var vp = cm.getViewport();
Expand All @@ -129,7 +135,9 @@
}

function onFold(cm, from) {
var state = cm.state.foldGutter, line = from.line;
var state = cm.state.foldGutter;
if (!state) return;
var line = from.line;
if (line >= state.from && line < state.to)
updateFoldInfo(cm, line, line + 1);
}
Expand Down
23 changes: 14 additions & 9 deletions addon/hint/show-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
return cm.showHint(newOpts);
};

var asyncRunID = 0;
function retrieveHints(getter, cm, options, then) {
if (getter.async) {
var id = ++asyncRunID;
getter(cm, function(hints) {
if (asyncRunID == id) then(hints);
}, options);
} else {
then(getter(cm, options));
}
}

CodeMirror.defineExtension("showHint", function(options) {
// We want a single cursor position.
if (this.listSelections().length > 1 || this.somethingSelected()) return;
Expand All @@ -34,10 +46,7 @@
if (!getHints) return;

CodeMirror.signal(this, "startCompletion", this);
if (getHints.async)
getHints(this, function(hints) { completion.showHints(hints); }, completion.options);
else
return completion.showHints(getHints(this, completion.options));
return retrieveHints(getHints, this, completion.options, function(hints) { completion.showHints(hints); });
});

function Completion(cm, options) {
Expand Down Expand Up @@ -102,11 +111,7 @@
function update() {
if (finished) return;
CodeMirror.signal(data, "update");
var getHints = completion.options.hint;
if (getHints.async)
getHints(completion.cm, finishUpdate, completion.options);
else
finishUpdate(getHints(completion.cm, completion.options));
retrieveHints(completion.options.hint, completion.cm, completion.options, finishUpdate);
}
function finishUpdate(data_) {
data = data_;
Expand Down
Loading