-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2aca26b
commit 29db89d
Showing
582 changed files
with
112,754 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.txt text eol=lf | ||
*.js text eol=lf | ||
*.html text eol=lf | ||
*.md text eol=lf | ||
*.json text eol=lf | ||
*.yml text eol=lf | ||
*.css text eol=lf | ||
*.svg text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/node_modules | ||
/demo | ||
/doc | ||
/test | ||
/test*.html | ||
/index.html | ||
/mode/*/*test.js | ||
/mode/*/*.html | ||
/mode/index.html | ||
.* | ||
/bin/authors.sh | ||
/bin/lint | ||
/bin/release | ||
/bin/upload-release.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (C) 2017 by Marijn Haverbeke <marijn@haverbeke.berlin> 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 | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# CodeMirror 5 | ||
|
||
**NOTE:** [CodeMirror 6](https://codemirror.net/) exists, and is more mobile-friendly, more accessible, better designed, and much more actively maintained. | ||
|
||
[![Build Status](https://github.com/codemirror/codemirror5/workflows/main/badge.svg)](https://github.com/codemirror/codemirror5/actions) | ||
|
||
CodeMirror is a versatile text editor implemented in JavaScript for | ||
the browser. It is specialized for editing code, and comes with over | ||
100 language modes and various addons that implement more advanced | ||
editing functionality. Every language comes with fully-featured code | ||
and syntax highlighting to help with reading and editing complex code. | ||
|
||
A rich programming API and a CSS theming system are available for | ||
customizing CodeMirror to fit your application, and extending it with | ||
new functionality. | ||
|
||
You can find more information (and the | ||
[manual](https://codemirror.net/5/doc/manual.html)) on the [project | ||
page](https://codemirror.net/5/). For questions and discussion, use the | ||
[discussion forum](https://discuss.codemirror.net/). | ||
|
||
See | ||
[CONTRIBUTING.md](https://github.com/codemirror/CodeMirror/blob/master/CONTRIBUTING.md) | ||
for contributing guidelines. | ||
|
||
The CodeMirror community aims to be welcoming to everybody. We use the | ||
[Contributor Covenant | ||
(1.1)](http://contributor-covenant.org/version/1/1/0/) as our code of | ||
conduct. | ||
|
||
### Installation | ||
|
||
Either get the [zip file](https://codemirror.net/5/codemirror.zip) with | ||
the latest version, or make sure you have [Node](https://nodejs.org/) | ||
installed and run: | ||
|
||
npm install codemirror@5 | ||
|
||
**NOTE**: This is the source repository for the library, and not the | ||
distribution channel. Cloning it is not the recommended way to install | ||
the library, and will in fact not work unless you also run the build | ||
step. | ||
|
||
### Quickstart | ||
|
||
To build the project, make sure you have Node.js installed (at least version 6) | ||
and then `npm install`. To run, just open `index.html` in your | ||
browser (you don't need to run a webserver). Run the tests with `npm test`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
// CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
// Distributed under an MIT license: https://codemirror.net/5/LICENSE | ||
|
||
(function(mod) { | ||
if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
mod(require("../../lib/codemirror")); | ||
else if (typeof define == "function" && define.amd) // AMD | ||
define(["../../lib/codemirror"], mod); | ||
else // Plain browser env | ||
mod(CodeMirror); | ||
})(function(CodeMirror) { | ||
"use strict"; | ||
|
||
var noOptions = {}; | ||
var nonWS = /[^\s\u00a0]/; | ||
var Pos = CodeMirror.Pos, cmp = CodeMirror.cmpPos; | ||
|
||
function firstNonWS(str) { | ||
var found = str.search(nonWS); | ||
return found == -1 ? 0 : found; | ||
} | ||
|
||
CodeMirror.commands.toggleComment = function(cm) { | ||
cm.toggleComment(); | ||
}; | ||
|
||
CodeMirror.defineExtension("toggleComment", function(options) { | ||
if (!options) options = noOptions; | ||
var cm = this; | ||
var minLine = Infinity, ranges = this.listSelections(), mode = null; | ||
for (var i = ranges.length - 1; i >= 0; i--) { | ||
var from = ranges[i].from(), to = ranges[i].to(); | ||
if (from.line >= minLine) continue; | ||
if (to.line >= minLine) to = Pos(minLine, 0); | ||
minLine = from.line; | ||
if (mode == null) { | ||
if (cm.uncomment(from, to, options)) mode = "un"; | ||
else { cm.lineComment(from, to, options); mode = "line"; } | ||
} else if (mode == "un") { | ||
cm.uncomment(from, to, options); | ||
} else { | ||
cm.lineComment(from, to, options); | ||
} | ||
} | ||
}); | ||
|
||
// Rough heuristic to try and detect lines that are part of multi-line string | ||
function probablyInsideString(cm, pos, line) { | ||
return /\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"\`]/.test(line) | ||
} | ||
|
||
function getMode(cm, pos) { | ||
var mode = cm.getMode() | ||
return mode.useInnerComments === false || !mode.innerMode ? mode : cm.getModeAt(pos) | ||
} | ||
|
||
CodeMirror.defineExtension("lineComment", function(from, to, options) { | ||
if (!options) options = noOptions; | ||
var self = this, mode = getMode(self, from); | ||
var firstLine = self.getLine(from.line); | ||
if (firstLine == null || probablyInsideString(self, from, firstLine)) return; | ||
|
||
var commentString = options.lineComment || mode.lineComment; | ||
if (!commentString) { | ||
if (options.blockCommentStart || mode.blockCommentStart) { | ||
options.fullLines = true; | ||
self.blockComment(from, to, options); | ||
} | ||
return; | ||
} | ||
|
||
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1); | ||
var pad = options.padding == null ? " " : options.padding; | ||
var blankLines = options.commentBlankLines || from.line == to.line; | ||
|
||
self.operation(function() { | ||
if (options.indent) { | ||
var baseString = null; | ||
for (var i = from.line; i < end; ++i) { | ||
var line = self.getLine(i); | ||
var whitespace = line.search(nonWS) === -1 ? line : line.slice(0, firstNonWS(line)); | ||
if (baseString == null || baseString.length > whitespace.length) { | ||
baseString = whitespace; | ||
} | ||
} | ||
for (var i = from.line; i < end; ++i) { | ||
var line = self.getLine(i), cut = baseString.length; | ||
if (!blankLines && !nonWS.test(line)) continue; | ||
if (line.slice(0, cut) != baseString) cut = firstNonWS(line); | ||
self.replaceRange(baseString + commentString + pad, Pos(i, 0), Pos(i, cut)); | ||
} | ||
} else { | ||
for (var i = from.line; i < end; ++i) { | ||
if (blankLines || nonWS.test(self.getLine(i))) | ||
self.replaceRange(commentString + pad, Pos(i, 0)); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
CodeMirror.defineExtension("blockComment", function(from, to, options) { | ||
if (!options) options = noOptions; | ||
var self = this, mode = getMode(self, from); | ||
var startString = options.blockCommentStart || mode.blockCommentStart; | ||
var endString = options.blockCommentEnd || mode.blockCommentEnd; | ||
if (!startString || !endString) { | ||
if ((options.lineComment || mode.lineComment) && options.fullLines != false) | ||
self.lineComment(from, to, options); | ||
return; | ||
} | ||
if (/\bcomment\b/.test(self.getTokenTypeAt(Pos(from.line, 0)))) return | ||
|
||
var end = Math.min(to.line, self.lastLine()); | ||
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end; | ||
|
||
var pad = options.padding == null ? " " : options.padding; | ||
if (from.line > end) return; | ||
|
||
self.operation(function() { | ||
if (options.fullLines != false) { | ||
var lastLineHasText = nonWS.test(self.getLine(end)); | ||
self.replaceRange(pad + endString, Pos(end)); | ||
self.replaceRange(startString + pad, Pos(from.line, 0)); | ||
var lead = options.blockCommentLead || mode.blockCommentLead; | ||
if (lead != null) for (var i = from.line + 1; i <= end; ++i) | ||
if (i != end || lastLineHasText) | ||
self.replaceRange(lead + pad, Pos(i, 0)); | ||
} else { | ||
var atCursor = cmp(self.getCursor("to"), to) == 0, empty = !self.somethingSelected() | ||
self.replaceRange(endString, to); | ||
if (atCursor) self.setSelection(empty ? to : self.getCursor("from"), to) | ||
self.replaceRange(startString, from); | ||
} | ||
}); | ||
}); | ||
|
||
CodeMirror.defineExtension("uncomment", function(from, to, options) { | ||
if (!options) options = noOptions; | ||
var self = this, mode = getMode(self, from); | ||
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end); | ||
|
||
// Try finding line comments | ||
var lineString = options.lineComment || mode.lineComment, lines = []; | ||
var pad = options.padding == null ? " " : options.padding, didSomething; | ||
lineComment: { | ||
if (!lineString) break lineComment; | ||
for (var i = start; i <= end; ++i) { | ||
var line = self.getLine(i); | ||
var found = line.indexOf(lineString); | ||
if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1; | ||
if (found == -1 && nonWS.test(line)) break lineComment; | ||
if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment; | ||
lines.push(line); | ||
} | ||
self.operation(function() { | ||
for (var i = start; i <= end; ++i) { | ||
var line = lines[i - start]; | ||
var pos = line.indexOf(lineString), endPos = pos + lineString.length; | ||
if (pos < 0) continue; | ||
if (line.slice(endPos, endPos + pad.length) == pad) endPos += pad.length; | ||
didSomething = true; | ||
self.replaceRange("", Pos(i, pos), Pos(i, endPos)); | ||
} | ||
}); | ||
if (didSomething) return true; | ||
} | ||
|
||
// Try block comments | ||
var startString = options.blockCommentStart || mode.blockCommentStart; | ||
var endString = options.blockCommentEnd || mode.blockCommentEnd; | ||
if (!startString || !endString) return false; | ||
var lead = options.blockCommentLead || mode.blockCommentLead; | ||
var startLine = self.getLine(start), open = startLine.indexOf(startString) | ||
if (open == -1) return false | ||
var endLine = end == start ? startLine : self.getLine(end) | ||
var close = endLine.indexOf(endString, end == start ? open + startString.length : 0); | ||
var insideStart = Pos(start, open + 1), insideEnd = Pos(end, close + 1) | ||
if (close == -1 || | ||
!/comment/.test(self.getTokenTypeAt(insideStart)) || | ||
!/comment/.test(self.getTokenTypeAt(insideEnd)) || | ||
self.getRange(insideStart, insideEnd, "\n").indexOf(endString) > -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 && firstEnd + endString.length != from.ch) 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 && lastStart != to.ch) 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)); | ||
var openEnd = open + startString.length; | ||
if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd += pad.length; | ||
self.replaceRange("", Pos(start, open), Pos(start, openEnd)); | ||
if (lead) for (var i = start + 1; i <= end; ++i) { | ||
var line = self.getLine(i), found = line.indexOf(lead); | ||
if (found == -1 || nonWS.test(line.slice(0, found))) continue; | ||
var foundEnd = found + lead.length; | ||
if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd += pad.length; | ||
self.replaceRange("", Pos(i, found), Pos(i, foundEnd)); | ||
} | ||
}); | ||
return true; | ||
}); | ||
}); |
Oops, something went wrong.