12 changes: 12 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Ankit
Ankit Ahuja
Ansel Santosa
Anthony Dugois
anthonygego
Anthony Gégo
Anthony Grimes
Anton Kovalyov
AQNOUCH Mohammed
Expand Down Expand Up @@ -118,6 +120,7 @@ Daniel Parnell
Danny Yoo
darealshinji
Darius Roberts
Dave Brondsema
Dave Myers
David Barnett
David Mignot
Expand Down Expand Up @@ -248,6 +251,7 @@ Juho Vuori
Justin Hileman
jwallers@gmail.com
kaniga
karevn
Ken Newman
Ken Rockot
Kevin Earls
Expand Down Expand Up @@ -298,11 +302,13 @@ Martin Balek
Martín Gaitán
Martin Hasoň
Martin Hunt
Martin Zagora
Mason Malone
Mateusz Paprocki
Mathias Bynens
mats cronqvist
Matt Gaide
Matthew Bauer
Matthew Beale
Matthew Rathbone
Matthias Bussonnier
Expand All @@ -317,6 +323,7 @@ Max Kirsch
Max Schaefer
Max Xiantu
mbarkhau
melpon
Metatheos
Micah Dubinko
Michael
Expand Down Expand Up @@ -387,6 +394,7 @@ prasanthj
Prasanth J
Radek Piórkowski
Rahul
ramwin1
Randall Mason
Randy Burden
Randy Edmunds
Expand Down Expand Up @@ -435,9 +443,11 @@ Stanislav Oaserele
Stas Kobzar
Stefan Borsje
Steffen Beyer
Stephen Lavelle
Steve O'Hara
stoskov
Sungho Kim
sverweij
Taha Jahangir
Takuji Shimokawa
Tarmil
Expand All @@ -464,9 +474,11 @@ Triangle717
twifkak
Vestimir Markov
vf
Victor Bocharsky
Vincent Woo
Volker Mische
wenli
Wes Cossick
Wesley Wiser
Will Binns-Smith
William Jamieson
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ By contributing code to CodeMirror you
### Coding standards

- 2 spaces per indentation level, no tabs.
- Include semicolons after statements.

- Note that the linter (`bin/lint`) which is run after each commit
complains about unused variables and functions. Prefix their names
with an underscore to muffle it.
Expand Down
4 changes: 3 additions & 1 deletion addon/display/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
var elt = cm.state.placeholder = document.createElement("pre");
elt.style.cssText = "height: 0; overflow: visible";
elt.className = "CodeMirror-placeholder";
elt.appendChild(document.createTextNode(cm.getOption("placeholder")));
var placeHolder = cm.getOption("placeholder")
if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
elt.appendChild(placeHolder)
cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
}

Expand Down
10 changes: 10 additions & 0 deletions addon/edit/closebrackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
});
}

function contractSelection(sel) {
var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)),
head: new Pos(sel.head.line, sel.head.ch + (inverted ? 1 : -1))};
}

function handleChar(cm, ch) {
var conf = getConfig(cm);
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
Expand Down Expand Up @@ -145,6 +151,10 @@
for (var i = 0; i < sels.length; i++)
sels[i] = left + sels[i] + right;
cm.replaceSelections(sels, "around");
sels = cm.listSelections().slice();
for (var i = 0; i < sels.length; i++)
sels[i] = contractSelection(sels[i]);
cm.setSelections(sels);
} else if (type == "both") {
cm.replaceSelection(left + right, null);
cm.triggerElectric(left + right);
Expand Down
24 changes: 21 additions & 3 deletions addon/lint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
this.timeout = null;
this.hasGutter = hasGutter;
this.onMouseOver = function(e) { onMouseOver(cm, e); };
this.waitingFor = 0
}

function parseOptions(_cm, options) {
Expand Down Expand Up @@ -115,15 +116,32 @@
return tip;
}

function lintAsync(cm, getAnnotations, passOptions) {
var state = cm.state.lint
var id = ++state.waitingFor
function abort() {
id = -1
cm.off("change", abort)
}
cm.on("change", abort)
getAnnotations(cm.getValue(), function(annotations, arg2) {
cm.off("change", abort)
if (state.waitingFor != id) return
if (arg2 && annotations instanceof CodeMirror) annotations = arg2
updateLinting(cm, annotations)
}, passOptions, cm);
}

function startLinting(cm) {
var state = cm.state.lint, options = state.options;
var passOptions = options.options || options; // Support deprecated passing of `options` property in options
var getAnnotations = options.getAnnotations || cm.getHelper(CodeMirror.Pos(0, 0), "lint");
if (!getAnnotations) return;
if (options.async || getAnnotations.async)
getAnnotations(cm.getValue(), updateLinting, passOptions, cm);
else
if (options.async || getAnnotations.async) {
lintAsync(cm, getAnnotations, passOptions)
} else {
updateLinting(cm, getAnnotations(cm.getValue(), passOptions, cm));
}
}

function updateLinting(cm, annotationsNotSorted) {
Expand Down
43 changes: 29 additions & 14 deletions addon/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,19 @@
if (state.query) return findNext(cm, rev);
var q = cm.getSelection() || state.lastQuery;
if (persistent && cm.openDialog) {
var hiding = null
persistentDialog(cm, queryDialog, q, function(query, event) {
CodeMirror.e_stop(event);
if (!query) return;
if (query != state.queryText) startSearch(cm, state, query);
findNext(cm, event.shiftKey);
if (hiding) hiding.style.opacity = 1
findNext(cm, event.shiftKey, function(_, to) {
var dialog
if (to.line < 3 && document.querySelector &&
(dialog = cm.display.wrapper.querySelector(".CodeMirror-dialog")) &&
dialog.getBoundingClientRect().bottom - 4 > cm.cursorCoords(to, "window").top)
(hiding = dialog).style.opacity = .4
})
});
} else {
dialog(cm, queryDialog, "Search for:", q, function(query) {
Expand All @@ -134,7 +142,7 @@
}
}

function findNext(cm, rev) {cm.operation(function() {
function findNext(cm, rev, callback) {cm.operation(function() {
var state = getSearchState(cm);
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
if (!cursor.find(rev)) {
Expand All @@ -144,6 +152,7 @@
cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
state.posFrom = cursor.from(); state.posTo = cursor.to();
if (callback) callback(cursor.from(), cursor.to())
});}

function clearSearch(cm) {cm.operation(function() {
Expand All @@ -156,27 +165,32 @@
});}

var replaceQueryDialog =
'Replace: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
' <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
var replacementQueryDialog = 'With: <input type="text" style="width: 10em" class="CodeMirror-search-field"/>';
var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>All</button> <button>Stop</button>";

function replaceAll(cm, query, text) {
cm.operation(function() {
for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
if (typeof query != "string") {
var match = cm.getRange(cursor.from(), cursor.to()).match(query);
cursor.replace(text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
} else cursor.replace(text);
}
});
}

function replace(cm, all) {
if (cm.getOption("readOnly")) return;
var query = cm.getSelection() || getSearchState(cm).lastQuery;
dialog(cm, replaceQueryDialog, "Replace:", query, function(query) {
var dialogText = all ? "Replace all:" : "Replace:"
dialog(cm, dialogText + replaceQueryDialog, dialogText, query, function(query) {
if (!query) return;
query = parseQuery(query);
dialog(cm, replacementQueryDialog, "Replace with:", "", function(text) {
text = parseString(text)
if (all) {
cm.operation(function() {
for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
if (typeof query != "string") {
var match = cm.getRange(cursor.from(), cursor.to()).match(query);
cursor.replace(text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
} else cursor.replace(text);
}
});
replaceAll(cm, query, text)
} else {
clearSearch(cm);
var cursor = getSearchCursor(cm, query, cm.getCursor());
Expand All @@ -190,7 +204,8 @@
cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
confirmDialog(cm, doReplaceConfirm, "Replace?",
[function() {doReplace(match);}, advance]);
[function() {doReplace(match);}, advance,
function() {replaceAll(cm, query, text)}]);
};
var doReplace = function(match) {
cursor.replace(typeof query == "string" ? text :
Expand Down
3 changes: 2 additions & 1 deletion demo/sublime.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ <h2>Sublime Text bindings demo</h2>
autoCloseBrackets: true,
matchBrackets: true,
showCursorWhenSelecting: true,
theme: "monokai"
theme: "monokai",
tabSize: 2
});
</script>

Expand Down
4 changes: 4 additions & 0 deletions doc/compress.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h2>Script compression helper</h2>
<input type="hidden" id="download" name="download" value="codemirror-compressed.js"/>
<p>Version: <select id="version" onchange="setVersion(this);" style="padding: 1px;">
<option value="http://codemirror.net/">HEAD</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=5.7.0;f=">5.7</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=5.6.0;f=">5.6</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=5.5.0;f=">5.5</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=5.4.0;f=">5.4</option>
Expand Down Expand Up @@ -161,10 +162,12 @@ <h2>Script compression helper</h2>
<option value="http://codemirror.net/mode/mirc/mirc.js">mirc.js</option>
<option value="http://codemirror.net/mode/mllike/mllike.js">mllike.js</option>
<option value="http://codemirror.net/mode/modelica/modelica.js">modelica.js</option>
<option value="http://codemirror.net/mode/mscgen/mscgen.js">mscgen.js</option>
<option value="http://codemirror.net/mode/mumps/mumps.js">mumps.js</option>
<option value="http://codemirror.net/mode/nginx/nginx.js">nginx.js</option>
<option value="http://codemirror.net/mode/ntriples/ntriples.js">ntriples.js</option>
<option value="http://codemirror.net/mode/octave/octave.js">octave.js</option>
<option value="http://codemirror.net/mode/oz/oz.js">oz.js</option>
<option value="http://codemirror.net/mode/pascal/pascal.js">pascal.js</option>
<option value="http://codemirror.net/mode/pegjs/pegjs.js">pegjs.js</option>
<option value="http://codemirror.net/mode/perl/perl.js">perl.js</option>
Expand Down Expand Up @@ -211,6 +214,7 @@ <h2>Script compression helper</h2>
<option value="http://codemirror.net/mode/velocity/velocity.js">velocity.js</option>
<option value="http://codemirror.net/mode/verilog/verilog.js">verilog.js</option>
<option value="http://codemirror.net/mode/vhdl/vhdl.js">vhdl.js</option>
<option value="http://codemirror.net/mode/vue/vue.js">vue.js</option>
<option value="http://codemirror.net/mode/xml/xml.js">xml.js</option>
<option value="http://codemirror.net/mode/xquery/xquery.js">xquery.js</option>
<option value="http://codemirror.net/mode/yaml/yaml.js">yaml.js</option>
Expand Down
46 changes: 24 additions & 22 deletions doc/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<section class=first id=overview>
<h2 style="position: relative">
User manual and reference guide
<span style="color: #888; font-size: 1rem; position: absolute; right: 0; bottom: 0">version 5.6.0</span>
<span style="color: #888; font-size: 1rem; position: absolute; right: 0; bottom: 0">version 5.7.0</span>
</h2>

<p>CodeMirror is a code-editor component that can be embedded in
Expand Down Expand Up @@ -100,7 +100,7 @@ <h2>Basic Usage</h2>
easy way to combine scripts.) For example:</p>

<pre data-lang="text/html">&lt;script src="lib/codemirror.js">&lt;/script>
&lt;link rel="stylesheet" href="../lib/codemirror.css">
&lt;link rel="stylesheet" href="lib/codemirror.css">
&lt;script src="mode/javascript/javascript.js">&lt;/script></pre>

<p>(Alternatively, use a module loader. <a href="#modloader">More
Expand Down Expand Up @@ -2439,7 +2439,7 @@ <h2 id="addons">Addons</h2>
running <a href="../addon/runmode/runmode-standalone.js">stand-alone</a>
(without including all of CodeMirror) and
for <a href="../addon/runmode/runmode.node.js">running under
node.js</a>.</dd>
node.js</a> (see <code>bin/source-highlight</code> for an example of using the latter).</dd>

<dt id="addon_colorize"><a href="../addon/runmode/colorize.js"><code>runmode/colorize.js</code></a></dt>
<dd>Provides a convenient way to syntax-highlight code snippets
Expand Down Expand Up @@ -2678,23 +2678,24 @@ <h2 id="addons">Addons</h2>
<a href="../addon/lint/coffeescript-lint.js"><code>coffeescript-lint.js</code></a>,
and <a href="../addon/lint/css-lint.js"><code>css-lint.js</code></a>
in the same directory). Defines a <code>lint</code> option that
can be set to a warning source (for
example <code>CodeMirror.lint.javascript</code>), or
to <code>true</code>, in which
case <a href="#getHelper"><code>getHelper</code></a> with
type <code>"lint"</code> is used to determined a validator
function. Such a function should, when given a document string,
an options object, and an editor instance, return an array of <code>{message,
severity, from, to}</code> objects representing problems. When
the function has an <code>async</code> property with a truthy
value, it will be called with an additional second argument,
which is a callback to pass the array to. Depends
on <code>addon/lint/lint.css</code>. A demo can be
can be set to an annotation source (for
example <code>CodeMirror.lint.javascript</code>), to an options
object (in which case the <code>getAnnotations</code> field is
used as annotation source), or simply to <code>true</code>. When
no annotation source is
specified, <a href="#getHelper"><code>getHelper</code></a> with
type <code>"lint"</code> is used to find an annotation function.
An annotation source function should, when given a document
string, an options object, and an editor instance, return an
array of <code>{message, severity, from, to}</code> objects
representing problems. When the function has
an <code>async</code> property with a truthy value, it will be
called with an additional second argument, which is a callback
to pass the array to. By default, the linter will run
(debounced) whenever the document is changed. You can pass
a <code>lintOnChange: false</code> option to disable that.
Depends on <code>addon/lint/lint.css</code>. A demo can be
found <a href="../demo/lint.html">here</a>.</dd>
<dd>Linting on every change can be disabled by setting
the <code>lintOnChange</code> option to <code>false</code>. One
can then perform the lint operation explicitly using the
editor's <code>performLint</code> method.</dd>

<dt id="addon_mark-selection"><a href="../addon/selection/mark-selection.js"><code>selection/mark-selection.js</code></a></dt>
<dd>Causes the selected text to be marked with the CSS class
Expand Down Expand Up @@ -2762,9 +2763,10 @@ <h2 id="addons">Addons</h2>

<dt id="addon_placeholder"><a href="../addon/display/placeholder.js"><code>display/placeholder.js</code></a></dt>
<dd>Adds a <code>placeholder</code> option that can be used to
make text appear in the editor when it is empty and not focused.
Also gives the editor a <code>CodeMirror-empty</code> CSS class
whenever it doesn't contain any text.
make content appear in the editor when it is empty and not
focused. It can hold either a string or a DOM node. Also gives
the editor a <code>CodeMirror-empty</code> CSS class whenever it
doesn't contain any text.
See <a href="../demo/placeholder.html">the demo</a>.</dd>

<dt id="addon_fullscreen"><a href="../addon/display/fullscreen.js"><code>display/fullscreen.js</code></a></dt>
Expand Down
Loading