Skip to content

Commit 59e746c

Browse files
committed
CodeMirror 5.43.0
0 parents  commit 59e746c

File tree

175 files changed

+34530
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+34530
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (C) 2017 by Marijn Haverbeke <[email protected]> and others
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# CodeMirror
2+
3+
[![Build Status](https://travis-ci.org/codemirror/CodeMirror.svg)](https://travis-ci.org/codemirror/CodeMirror)
4+
[![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror)
5+
[![Join the chat at https://gitter.im/codemirror/CodeMirror](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/codemirror/CodeMirror)
6+
7+
CodeMirror is a versatile text editor implemented in JavaScript for
8+
the browser. It is specialized for editing code, and comes with over
9+
100 language modes and various addons that implement more advanced
10+
editing functionality. Every language comes with fully-featured code
11+
and syntax highlighting to help with reading and editing complex code.
12+
13+
A rich programming API and a CSS theming system are available for
14+
customizing CodeMirror to fit your application, and extending it with
15+
new functionality.
16+
17+
You can find more information (and the
18+
[manual](https://codemirror.net/doc/manual.html)) on the [project
19+
page](https://codemirror.net). For questions and discussion, use the
20+
[discussion forum](https://discuss.codemirror.net/).
21+
22+
See
23+
[CONTRIBUTING.md](https://github.com/codemirror/CodeMirror/blob/master/CONTRIBUTING.md)
24+
for contributing guidelines.
25+
26+
The CodeMirror community aims to be welcoming to everybody. We use the
27+
[Contributor Covenant
28+
(1.1)](http://contributor-covenant.org/version/1/1/0/) as our code of
29+
conduct.
30+
31+
### Installation
32+
33+
Either get the [zip file](https://codemirror.net/codemirror.zip) with
34+
the latest version, or make sure you have [Node](https://nodejs.org/)
35+
installed and run:
36+
37+
npm install codemirror
38+
39+
**NOTE**: This is the source repository for the library, and not the
40+
distribution channel. Cloning it is not the recommended way to install
41+
the library, and will in fact not work unless you also run the build
42+
step.
43+
44+
### Quickstart
45+
46+
To build the project, make sure you have Node.js installed (at least version 6)
47+
and then `npm install`. To run, just open `index.html` in your
48+
browser (you don't need to run a webserver). Run the tests with `npm test`.
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: https://codemirror.net/LICENSE
3+
4+
(function(mod) {
5+
if (typeof exports == "object" && typeof module == "object") // CommonJS
6+
mod(require("../../lib/codemirror"));
7+
else if (typeof define == "function" && define.amd) // AMD
8+
define(["../../lib/codemirror"], mod);
9+
else // Plain browser env
10+
mod(CodeMirror);
11+
})(function(CodeMirror) {
12+
"use strict";
13+
14+
var noOptions = {};
15+
var nonWS = /[^\s\u00a0]/;
16+
var Pos = CodeMirror.Pos;
17+
18+
function firstNonWS(str) {
19+
var found = str.search(nonWS);
20+
return found == -1 ? 0 : found;
21+
}
22+
23+
CodeMirror.commands.toggleComment = function(cm) {
24+
cm.toggleComment();
25+
};
26+
27+
CodeMirror.defineExtension("toggleComment", function(options) {
28+
if (!options) options = noOptions;
29+
var cm = this;
30+
var minLine = Infinity, ranges = this.listSelections(), mode = null;
31+
for (var i = ranges.length - 1; i >= 0; i--) {
32+
var from = ranges[i].from(), to = ranges[i].to();
33+
if (from.line >= minLine) continue;
34+
if (to.line >= minLine) to = Pos(minLine, 0);
35+
minLine = from.line;
36+
if (mode == null) {
37+
if (cm.uncomment(from, to, options)) mode = "un";
38+
else { cm.lineComment(from, to, options); mode = "line"; }
39+
} else if (mode == "un") {
40+
cm.uncomment(from, to, options);
41+
} else {
42+
cm.lineComment(from, to, options);
43+
}
44+
}
45+
});
46+
47+
// Rough heuristic to try and detect lines that are part of multi-line string
48+
function probablyInsideString(cm, pos, line) {
49+
return /\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"\`]/.test(line)
50+
}
51+
52+
function getMode(cm, pos) {
53+
var mode = cm.getMode()
54+
return mode.useInnerComments === false || !mode.innerMode ? mode : cm.getModeAt(pos)
55+
}
56+
57+
CodeMirror.defineExtension("lineComment", function(from, to, options) {
58+
if (!options) options = noOptions;
59+
var self = this, mode = getMode(self, from);
60+
var firstLine = self.getLine(from.line);
61+
if (firstLine == null || probablyInsideString(self, from, firstLine)) return;
62+
63+
var commentString = options.lineComment || mode.lineComment;
64+
if (!commentString) {
65+
if (options.blockCommentStart || mode.blockCommentStart) {
66+
options.fullLines = true;
67+
self.blockComment(from, to, options);
68+
}
69+
return;
70+
}
71+
72+
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1);
73+
var pad = options.padding == null ? " " : options.padding;
74+
var blankLines = options.commentBlankLines || from.line == to.line;
75+
76+
self.operation(function() {
77+
if (options.indent) {
78+
var baseString = null;
79+
for (var i = from.line; i < end; ++i) {
80+
var line = self.getLine(i);
81+
var whitespace = line.slice(0, firstNonWS(line));
82+
if (baseString == null || baseString.length > whitespace.length) {
83+
baseString = whitespace;
84+
}
85+
}
86+
for (var i = from.line; i < end; ++i) {
87+
var line = self.getLine(i), cut = baseString.length;
88+
if (!blankLines && !nonWS.test(line)) continue;
89+
if (line.slice(0, cut) != baseString) cut = firstNonWS(line);
90+
self.replaceRange(baseString + commentString + pad, Pos(i, 0), Pos(i, cut));
91+
}
92+
} else {
93+
for (var i = from.line; i < end; ++i) {
94+
if (blankLines || nonWS.test(self.getLine(i)))
95+
self.replaceRange(commentString + pad, Pos(i, 0));
96+
}
97+
}
98+
});
99+
});
100+
101+
CodeMirror.defineExtension("blockComment", function(from, to, options) {
102+
if (!options) options = noOptions;
103+
var self = this, mode = getMode(self, from);
104+
var startString = options.blockCommentStart || mode.blockCommentStart;
105+
var endString = options.blockCommentEnd || mode.blockCommentEnd;
106+
if (!startString || !endString) {
107+
if ((options.lineComment || mode.lineComment) && options.fullLines != false)
108+
self.lineComment(from, to, options);
109+
return;
110+
}
111+
if (/\bcomment\b/.test(self.getTokenTypeAt(Pos(from.line, 0)))) return
112+
113+
var end = Math.min(to.line, self.lastLine());
114+
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end;
115+
116+
var pad = options.padding == null ? " " : options.padding;
117+
if (from.line > end) return;
118+
119+
self.operation(function() {
120+
if (options.fullLines != false) {
121+
var lastLineHasText = nonWS.test(self.getLine(end));
122+
self.replaceRange(pad + endString, Pos(end));
123+
self.replaceRange(startString + pad, Pos(from.line, 0));
124+
var lead = options.blockCommentLead || mode.blockCommentLead;
125+
if (lead != null) for (var i = from.line + 1; i <= end; ++i)
126+
if (i != end || lastLineHasText)
127+
self.replaceRange(lead + pad, Pos(i, 0));
128+
} else {
129+
self.replaceRange(endString, to);
130+
self.replaceRange(startString, from);
131+
}
132+
});
133+
});
134+
135+
CodeMirror.defineExtension("uncomment", function(from, to, options) {
136+
if (!options) options = noOptions;
137+
var self = this, mode = getMode(self, from);
138+
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end);
139+
140+
// Try finding line comments
141+
var lineString = options.lineComment || mode.lineComment, lines = [];
142+
var pad = options.padding == null ? " " : options.padding, didSomething;
143+
lineComment: {
144+
if (!lineString) break lineComment;
145+
for (var i = start; i <= end; ++i) {
146+
var line = self.getLine(i);
147+
var found = line.indexOf(lineString);
148+
if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1;
149+
if (found == -1 && nonWS.test(line)) break lineComment;
150+
if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment;
151+
lines.push(line);
152+
}
153+
self.operation(function() {
154+
for (var i = start; i <= end; ++i) {
155+
var line = lines[i - start];
156+
var pos = line.indexOf(lineString), endPos = pos + lineString.length;
157+
if (pos < 0) continue;
158+
if (line.slice(endPos, endPos + pad.length) == pad) endPos += pad.length;
159+
didSomething = true;
160+
self.replaceRange("", Pos(i, pos), Pos(i, endPos));
161+
}
162+
});
163+
if (didSomething) return true;
164+
}
165+
166+
// Try block comments
167+
var startString = options.blockCommentStart || mode.blockCommentStart;
168+
var endString = options.blockCommentEnd || mode.blockCommentEnd;
169+
if (!startString || !endString) return false;
170+
var lead = options.blockCommentLead || mode.blockCommentLead;
171+
var startLine = self.getLine(start), open = startLine.indexOf(startString)
172+
if (open == -1) return false
173+
var endLine = end == start ? startLine : self.getLine(end)
174+
var close = endLine.indexOf(endString, end == start ? open + startString.length : 0);
175+
var insideStart = Pos(start, open + 1), insideEnd = Pos(end, close + 1)
176+
if (close == -1 ||
177+
!/comment/.test(self.getTokenTypeAt(insideStart)) ||
178+
!/comment/.test(self.getTokenTypeAt(insideEnd)) ||
179+
self.getRange(insideStart, insideEnd, "\n").indexOf(endString) > -1)
180+
return false;
181+
182+
// Avoid killing block comments completely outside the selection.
183+
// Positions of the last startString before the start of the selection, and the first endString after it.
184+
var lastStart = startLine.lastIndexOf(startString, from.ch);
185+
var firstEnd = lastStart == -1 ? -1 : startLine.slice(0, from.ch).indexOf(endString, lastStart + startString.length);
186+
if (lastStart != -1 && firstEnd != -1 && firstEnd + endString.length != from.ch) return false;
187+
// Positions of the first endString after the end of the selection, and the last startString before it.
188+
firstEnd = endLine.indexOf(endString, to.ch);
189+
var almostLastStart = endLine.slice(to.ch).lastIndexOf(startString, firstEnd - to.ch);
190+
lastStart = (firstEnd == -1 || almostLastStart == -1) ? -1 : to.ch + almostLastStart;
191+
if (firstEnd != -1 && lastStart != -1 && lastStart != to.ch) return false;
192+
193+
self.operation(function() {
194+
self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.length, close) == pad ? pad.length : 0)),
195+
Pos(end, close + endString.length));
196+
var openEnd = open + startString.length;
197+
if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd += pad.length;
198+
self.replaceRange("", Pos(start, open), Pos(start, openEnd));
199+
if (lead) for (var i = start + 1; i <= end; ++i) {
200+
var line = self.getLine(i), found = line.indexOf(lead);
201+
if (found == -1 || nonWS.test(line.slice(0, found))) continue;
202+
var foundEnd = found + lead.length;
203+
if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd += pad.length;
204+
self.replaceRange("", Pos(i, found), Pos(i, foundEnd));
205+
}
206+
});
207+
return true;
208+
});
209+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: https://codemirror.net/LICENSE
3+
4+
(function(mod) {
5+
if (typeof exports == "object" && typeof module == "object") // CommonJS
6+
mod(require("../../lib/codemirror"));
7+
else if (typeof define == "function" && define.amd) // AMD
8+
define(["../../lib/codemirror"], mod);
9+
else // Plain browser env
10+
mod(CodeMirror);
11+
})(function(CodeMirror) {
12+
function continueComment(cm) {
13+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
14+
var ranges = cm.listSelections(), mode, inserts = [];
15+
for (var i = 0; i < ranges.length; i++) {
16+
var pos = ranges[i].head
17+
if (!/\bcomment\b/.test(cm.getTokenTypeAt(pos))) return CodeMirror.Pass;
18+
var modeHere = cm.getModeAt(pos)
19+
if (!mode) mode = modeHere;
20+
else if (mode != modeHere) return CodeMirror.Pass;
21+
22+
var insert = null;
23+
if (mode.blockCommentStart && mode.blockCommentContinue) {
24+
var line = cm.getLine(pos.line).slice(0, pos.ch)
25+
var end = line.lastIndexOf(mode.blockCommentEnd), found
26+
if (end != -1 && end == pos.ch - mode.blockCommentEnd.length) {
27+
// Comment ended, don't continue it
28+
} else if ((found = line.lastIndexOf(mode.blockCommentStart)) > -1 && found > end) {
29+
insert = line.slice(0, found)
30+
if (/\S/.test(insert)) {
31+
insert = ""
32+
for (var j = 0; j < found; ++j) insert += " "
33+
}
34+
} else if ((found = line.indexOf(mode.blockCommentContinue)) > -1 && !/\S/.test(line.slice(0, found))) {
35+
insert = line.slice(0, found)
36+
}
37+
if (insert != null) insert += mode.blockCommentContinue
38+
}
39+
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
40+
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
41+
if (found > -1) {
42+
insert = line.slice(0, found);
43+
if (/\S/.test(insert)) insert = null;
44+
else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
45+
}
46+
}
47+
if (insert == null) return CodeMirror.Pass;
48+
inserts[i] = "\n" + insert;
49+
}
50+
51+
cm.operation(function() {
52+
for (var i = ranges.length - 1; i >= 0; i--)
53+
cm.replaceRange(inserts[i], ranges[i].from(), ranges[i].to(), "+insert");
54+
});
55+
}
56+
57+
function continueLineCommentEnabled(cm) {
58+
var opt = cm.getOption("continueComments");
59+
if (opt && typeof opt == "object")
60+
return opt.continueLineComment !== false;
61+
return true;
62+
}
63+
64+
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
65+
if (prev && prev != CodeMirror.Init)
66+
cm.removeKeyMap("continueComment");
67+
if (val) {
68+
var key = "Enter";
69+
if (typeof val == "string")
70+
key = val;
71+
else if (typeof val == "object" && val.key)
72+
key = val.key;
73+
var map = {name: "continueComment"};
74+
map[key] = continueComment;
75+
cm.addKeyMap(map);
76+
}
77+
});
78+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.CodeMirror-dialog {
2+
position: absolute;
3+
left: 0; right: 0;
4+
background: inherit;
5+
z-index: 15;
6+
padding: .1em .8em;
7+
overflow: hidden;
8+
color: inherit;
9+
}
10+
11+
.CodeMirror-dialog-top {
12+
border-bottom: 1px solid #eee;
13+
top: 0;
14+
}
15+
16+
.CodeMirror-dialog-bottom {
17+
border-top: 1px solid #eee;
18+
bottom: 0;
19+
}
20+
21+
.CodeMirror-dialog input {
22+
border: none;
23+
outline: none;
24+
background: transparent;
25+
width: 20em;
26+
color: inherit;
27+
font-family: monospace;
28+
}
29+
30+
.CodeMirror-dialog button {
31+
font-size: 70%;
32+
}

0 commit comments

Comments
 (0)