9 changes: 9 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Alberto Pose
Albert Xing
Alexander Pavlov
Alexander Schepanovski
Alexander Shvets
Alexander Solovyov
Alexandre Bique
alexey-k
Expand Down Expand Up @@ -168,6 +169,7 @@ Jason Grout
Jason Johnston
Jason San Jose
Jason Siefken
Jaydeep Solanki
Jean Boussier
jeffkenton
Jeff Pickhardt
Expand Down Expand Up @@ -205,6 +207,7 @@ kubelsmieci
Lanny
Laszlo Vidacs
leaf corcoran
Leonid Khachaturov
Leonya Khachaturov
Liam Newman
LM
Expand Down Expand Up @@ -269,6 +272,7 @@ Niels van Groningen
Nikita Beloglazov
Nikita Vasilyev
Nikolay Kostov
nilp0inter
nlwillia
pablo
Page
Expand All @@ -291,14 +295,17 @@ Radek Piórkowski
Rahul
Randy Edmunds
Rasmus Erik Voel Jensen
Richard van der Meer
Richard Z.H. Wang
Roberto Abdelkader Martínez Pérez
robertop23
Robert Plummer
Ruslan Osmanov
Ryan Prior
sabaca
Samuel Ainsworth
sandeepshetty
Sander AKA Redsandro
santec
Sascha Peilicke
satchmorun
Expand Down Expand Up @@ -330,6 +337,7 @@ Thaddee Tyl
think
Thomas Dvornik
Thomas Schmid
Tim Alby
Tim Baumann
Timothy Farrell
Timothy Hatcher
Expand All @@ -349,6 +357,7 @@ Volker Mische
wenli
Wesley Wiser
William Jamieson
William Stein
Wojtek Ptak
Xavier Mendez
YNH Webdev
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ should be asked on the
- 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.

- CodeMirror does *not* follow JSHint or JSLint prescribed style.
Patches that try to 'fix' code to pass one of these linters will be
unceremoniously discarded.
11 changes: 11 additions & 0 deletions addon/comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@
!/comment/.test(self.getTokenTypeAt(Pos(end, close + 1))))
return false;

// Avoid killing block comments completely outside the selection.
// Positions of the last startString before the start of the selection, and the first endString after it.
var lastStart = startLine.lastIndexOf(startString, from.ch);
var firstEnd = lastStart == -1 ? -1 : startLine.slice(0, from.ch).indexOf(endString, lastStart + startString.length);
if (lastStart != -1 && firstEnd != -1) return false;
// Positions of the first endString after the end of the selection, and the last startString before it.
firstEnd = endLine.indexOf(endString, to.ch);
var almostLastStart = endLine.slice(to.ch).lastIndexOf(startString, firstEnd - to.ch);
lastStart = (firstEnd == -1 || almostLastStart == -1) ? -1 : to.ch + almostLastStart;
if (firstEnd != -1 && lastStart != -1) return false;

self.operation(function() {
self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.length, close) == pad ? pad.length : 0)),
Pos(end, close + endString.length));
Expand Down
25 changes: 20 additions & 5 deletions addon/edit/closebrackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@
return str.length == 2 ? str : null;
}

// Project the token type that will exists after the given char is
// typed, and use it to determine whether it would cause the start
// of a string token.
function enteringString(cm, pos, ch) {
var line = cm.getLine(pos.line);
var token = cm.getTokenAt(pos);
if (/\bstring2?\b/.test(token.type)) return false;
var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.slice(pos.ch), 4);
stream.pos = stream.start = token.start;
for (;;) {
var type1 = cm.getMode().token(stream, token.state);
if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1);
stream.start = stream.pos;
}
}

function buildKeymap(pairs) {
var map = {
name : "autoCloseBrackets",
Expand All @@ -61,8 +77,6 @@
var ranges = cm.listSelections(), type, next;
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i], cur = range.head, curType;
if (left == "'" && cm.getTokenTypeAt(cur) == "comment")
return CodeMirror.Pass;
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
if (!range.empty())
curType = "surround";
Expand All @@ -75,9 +89,10 @@
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))
else if (left == '"' || left == "'") {
if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, left)) curType = "both";
else return CodeMirror.Pass;
} else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next))
curType = "both";
else
return CodeMirror.Pass;
Expand Down
4 changes: 2 additions & 2 deletions addon/hint/show-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@
(completion.options.container || document.body).appendChild(hints);
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
if (overlapY > 0) {
var height = box.bottom - box.top, curTop = box.top - (pos.bottom - pos.top);
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
if (curTop - height > 0) { // Fits above cursor
hints.style.top = (top = curTop - height) + "px";
hints.style.top = (top = pos.top - height) + "px";
below = false;
} else if (height > winH) {
hints.style.height = (winH - 5) + "px";
Expand Down
5 changes: 2 additions & 3 deletions addon/lint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
})(function(CodeMirror) {
"use strict";
var GUTTER_ID = "CodeMirror-lint-markers";
var SEVERITIES = /^(?:error|warning)$/;

function showTooltip(e, content) {
var tt = document.createElement("div");
Expand Down Expand Up @@ -110,7 +109,7 @@

function annotationTooltip(ann) {
var severity = ann.severity;
if (!SEVERITIES.test(severity)) severity = "error";
if (!severity) severity = "error";
var tip = document.createElement("div");
tip.className = "CodeMirror-lint-message-" + severity;
tip.appendChild(document.createTextNode(ann.message));
Expand Down Expand Up @@ -141,7 +140,7 @@
for (var i = 0; i < anns.length; ++i) {
var ann = anns[i];
var severity = ann.severity;
if (!SEVERITIES.test(severity)) severity = "error";
if (!severity) severity = "error";
maxSeverity = getMaxSeverity(maxSeverity, severity);

if (options.formatAnnotation) ann = options.formatAnnotation(ann);
Expand Down
1 change: 1 addition & 0 deletions addon/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
var replacementQueryDialog = 'With: <input type="text" style="width: 10em"/>';
var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
function replace(cm, all) {
if (cm.getOption("readOnly")) return;
dialog(cm, replaceQueryDialog, "Replace:", cm.getSelection(), function(query) {
if (!query) return;
query = parseQuery(query);
Expand Down
2 changes: 1 addition & 1 deletion addon/search/searchcursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
var from = Pos(pos.line, cut);
for (var ln = pos.line + 1, i = 1; i < last; ++i, ++ln)
if (target[i] != fold(doc.getLine(ln))) return;
if (doc.getLine(ln).slice(0, origTarget[last].length) != target[last]) return;
if (fold(doc.getLine(ln).slice(0, origTarget[last].length)) != target[last]) return;
return {from: from, to: Pos(ln, origTarget[last].length)};
}
};
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CodeMirror",
"version":"4.3.0",
"name": "codemirror",
"version":"4.4.0",
"main": ["lib/codemirror.js", "lib/codemirror.css"],
"ignore": [
"**/.*",
Expand Down
32 changes: 20 additions & 12 deletions demo/vim.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,32 @@ <h2>Vim bindings demo</h2>
return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
}
</textarea></form>
<div id="command-display" style="width: 300px; height: 30px;"></div>

<form><textarea id="code2" name="code2">
I am another file! You can yank from my neighbor and paste here.
</textarea></form>
<div style="font-size: 13px; width: 300px; height: 30px;">Key buffer: <span id="command-display"></span></div>

<p>The vim keybindings are enabled by
including <a href="../keymap/vim.js">keymap/vim.js</a> and setting
the <code>vimMode</code> option to <code>true</code>. This will also
automatically change the <code>keyMap</code> option to <code>"vim"</code>.</p>

<p><strong>Features</strong></p>

<ul>
<li>All common motions and operators, including text objects</li>
<li>Operator motion orthogonality</li>
<li>Visual mode - characterwise, linewise, partial support for blockwise</li>
<li>Full macro support (q, @)</li>
<li>Incremental highlighted search (/, ?, #, *, g#, g*)</li>
<li>Search/replace with confirm (:substitute, :%s)</li>
<li>Search history</li>
<li>Jump lists (Ctrl-o, Ctrl-i)</li>
<li>Key/command mapping with API (:map, :nmap, :vmap)</li>
<li>Sort (:sort)</li>
<li>Marks (`, ')</li>
<li>:global</li>
<li>Insert mode behaves identical to base CodeMirror</li>
<li>Cross-buffer yank/paste</li>
</ul>

<p>Note that while the vim mode tries to emulate the most useful features of
vim as faithfully as possible, it does not strive to become a complete vim
implementation</p>
Expand All @@ -69,13 +84,6 @@ <h2>Vim bindings demo</h2>
matchBrackets: true,
showCursorWhenSelecting: true
});
var editor2 = CodeMirror.fromTextArea(document.getElementById("code2"), {
lineNumbers: true,
mode: "text/x-csrc",
vimMode: true,
matchBrackets: true,
showCursorWhenSelecting: true
});
var commandDisplay = document.getElementById('command-display');
var keys = '';
CodeMirror.on(editor, 'vim-keypress', function(key) {
Expand Down
2 changes: 2 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=4.4.0;f=">4.4</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=4.3.0;f=">4.3</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=4.2.1;f=">4.2</option>
<option value="http://marijnhaverbeke.nl/git/codemirror?a=blob_plain;hb=4.2.0;f=">4.2</option>
Expand Down Expand Up @@ -123,6 +124,7 @@ <h2>Script compression helper</h2>
<option value="http://codemirror.net/mode/javascript/javascript.js">javascript.js</option>
<option value="http://codemirror.net/mode/jinja2/jinja2.js">jinja2.js</option>
<option value="http://codemirror.net/mode/julia/julia.js">julia.js</option>
<option value="http://codemirror.net/mode/kotlin/kotlin.js">kotlin.js</option>
<option value="http://codemirror.net/mode/livescript/livescript.js">livescript.js</option>
<option value="http://codemirror.net/mode/lua/lua.js">lua.js</option>
<option value="http://codemirror.net/mode/markdown/markdown.js">markdown.js</option>
Expand Down
20 changes: 13 additions & 7 deletions doc/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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 4.3.0</span>
<span style="color: #888; font-size: 1rem; position: absolute; right: 0; bottom: 0">version 4.4.0</span>
</h2>

<p>CodeMirror is a code-editor component that can be embedded in
Expand Down Expand Up @@ -797,9 +797,15 @@ <h2>Commands</h2>
<dt class=command id=command_deleteLine><code><strong>deleteLine</strong></code><span class=keybinding>Ctrl-D (PC), Cmd-D (Mac)</span></dt>
<dd>Deletes the whole line under the cursor, including newline at the end.</dd>

<dt class=command id=command_delLineLeft><code><strong>delLineLeft</strong></code><span class=keybinding>Cmd-Backspace (Mac)</span></dt>
<dt class=command id=command_delLineLeft><code><strong>delLineLeft</strong></code></dt>
<dd>Delete the part of the line before the cursor.</dd>

<dt class=command id=command_delWrappedLineLeft><code><strong>delWrappedLineLeft</strong></code><span class=keybinding>Cmd-Backspace (Mac)</span></dt>
<dd>Delete the part of the line from the left side of the visual line the cursor is on to the cursor.</dd>

<dt class=command id=command_delWrappedLineRight><code><strong>delWrappedLineRight</strong></code><span class=keybinding>Cmd-Delete (Mac)</span></dt>
<dd>Delete the part of the line from the cursor to the right side of the visual line the cursor is on.</dd>

<dt class=command id=command_undo><code><strong>undo</strong></code><span class=keybinding>Ctrl-Z (PC), Cmd-Z (Mac)</span></dt>
<dd>Undo the last change.</dd>

Expand All @@ -815,28 +821,28 @@ <h2>Commands</h2>
<dd>Redo the last change to the selection, or the last text change if
no selection changes remain.</dd>

<dt class=command id=command_goDocStart><code><strong>goDocStart</strong></code><span class=keybinding>Ctrl-Up (PC), Cmd-Up (Mac)</span></dt>
<dt class=command id=command_goDocStart><code><strong>goDocStart</strong></code><span class=keybinding>Ctrl-Up (PC), Cmd-Up (Mac), Cmd-Home (Mac)</span></dt>
<dd>Move the cursor to the start of the document.</dd>

<dt class=command id=command_goDocEnd><code><strong>goDocEnd</strong></code><span class=keybinding>Ctrl-Down (PC), Cmd-End (Mac), Cmd-Down (Mac)</span></dt>
<dd>Move the cursor to the end of the document.</dd>

<dt class=command id=command_goLineStart><code><strong>goLineStart</strong></code><span class=keybinding>Alt-Left (PC), Cmd-Left (Mac), Ctrl-A (Mac)</span></dt>
<dt class=command id=command_goLineStart><code><strong>goLineStart</strong></code><span class=keybinding>Alt-Left (PC), Ctrl-A (Mac)</span></dt>
<dd>Move the cursor to the start of the line.</dd>

<dt class=command id=command_goLineStartSmart><code><strong>goLineStartSmart</strong></code><span class=keybinding>Home</span></dt>
<dd>Move to the start of the text on the line, or if we are
already there, to the actual start of the line (including
whitespace).</dd>

<dt class=command id=command_goLineEnd><code><strong>goLineEnd</strong></code><span class=keybinding>Alt-Right (PC), Cmd-Right (Mac), Ctrl-E (Mac)</span></dt>
<dt class=command id=command_goLineEnd><code><strong>goLineEnd</strong></code><span class=keybinding>Alt-Right (PC), Ctrl-E (Mac)</span></dt>
<dd>Move the cursor to the end of the line.</dd>

<dt class=command id=command_goLineLeft><code><strong>goLineLeft</strong></code></dt>
<dt class=command id=command_goLineLeft><code><strong>goLineLeft</strong></code><span class=keybinding>Cmd-Left (Mac)</span></dt>
<dd>Move the cursor to the left side of the visual line it is on. If
this line is wrapped, that may not be the start of the line.</dd>

<dt class=command id=command_goLineRight><code><strong>goLineRight</strong></code></dt>
<dt class=command id=command_goLineRight><code><strong>goLineRight</strong></code><span class=keybinding>Cmd-Right (Mac)</span></dt>
<dd>Move the cursor to the right side of the visual line it is on.</dd>

<dt class=command id=command_goLineUp><code><strong>goLineUp</strong></code><span class=keybinding>Up, Ctrl-P (Mac)</span></dt>
Expand Down
2 changes: 2 additions & 0 deletions doc/realworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h2>CodeMirror real-world uses</h2>
<li><a href="http://cargocollective.com/">Cargo Collective</a> (creative publishing platform)</li>
<li><a href="https://developers.google.com/chrome-developer-tools/">Chrome DevTools</a></li>
<li><a href="http://clickhelp.co/">ClickHelp</a> (technical writing tool)</li>
<li><a href="http://codeworld.info/">CodeWorld</a> (Haskell playground)</li>
<li><a href="http://complete-ly.appspot.com/playground/code.playground.html">Complete.ly playground</a></li>
<li><a href="http://www.crossui.com/">CrossUI</a> (cross-platform UI builder)</li>
<li><a href="http://rsnous.com/cruncher/">Cruncher</a> (notepad with calculation features)</li>
Expand Down Expand Up @@ -123,6 +124,7 @@ <h2>CodeMirror real-world uses</h2>
<li><a href="http://www.quivive-file-manager.com">Quivive File Manager</a></li>
<li><a href="http://rascalmicro.com/docs/basic-tutorial-getting-started.html">Rascal</a> (tiny computer)</li>
<li><a href="https://www.realtime.io/">RealTime.io</a> (Internet-of-Things infrastructure)</li>
<li><a href="https://cloud.sagemath.com/">SageMathCloud</a> (interactive mathematical software environment)</li>
<li><a href="https://chrome.google.com/webstore/detail/servephp/mnpikomdchjhkhbhmbboehfdjkobbfpo">ServePHP</a> (PHP code testing in Chrome dev tools)</li>
<li><a href="https://www.shadertoy.com/">Shadertoy</a> (shader sharing)</li>
<li><a href="http://www.sketchpatch.net/labs/livecodelabIntro.html">sketchPatch Livecodelab</a></li>
Expand Down
14 changes: 14 additions & 0 deletions doc/releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ <h2>Release notes and version history</h2>

<h2 id="v4">Version 4.x</h2>

<p class="rel">21-07-2014: <a href="http://codemirror.net/codemirror-4.4.zip">Version 4.4</a>:</p>

<ul class="rel-note">
<li><strong>Note:</strong> Some events might now fire in slightly
different order (<code>"change"</code> is still guaranteed to fire
before <code>"cursorActivity"</code>)</li>
<li>Nested operations in multiple editors are now synced (complete
at same time, reducing DOM reflows)</li>
<li>Visual block mode for <a href="../demo/vim.html">vim</a> (&lt;C-v>) is nearly complete</li>
<li>New mode: <a href="../mode/kotlin/index.html">Kotlin</a></li>
<li>Better multi-selection paste for text copied from multiple CodeMirror selections</li>
<li>Full <a href="https://github.com/marijnh/CodeMirror/compare/4.3.0...4.4.0">list of patches</a>.</li>
</ul>

<p class="rel">23-06-2014: <a href="http://codemirror.net/codemirror-4.3.zip">Version 4.3</a>:</p>

<ul class="rel-note">
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2>This is CodeMirror</h2>
</script>
<div style="position: relative; margin: 1em 0;">
<a class="bigbutton left" href="http://codemirror.net/codemirror.zip">DOWNLOAD LATEST RELEASE</a>
<div><strong>version 4.3</strong> (<a href="doc/releases.html">Release notes</a>)</div>
<div><strong>version 4.4</strong> (<a href="doc/releases.html">Release notes</a>)</div>
<div>or use the <a href="doc/compress.html">minification helper</a></div>
<div style="position: absolute; top: 0; right: 0; text-align: right">
<span class="bigbutton right" onclick="document.getElementById('paypal').submit();">DONATE WITH PAYPAL</span>
Expand Down
Loading