-
Notifications
You must be signed in to change notification settings - Fork 78
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
5575bba
commit 3c1ac07
Showing
71 changed files
with
12,670 additions
and
34 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,19 @@ | ||
Copyright (C) 2015 by Marijn Haverbeke <marijnh@gmail.com> 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,183 @@ | ||
// CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
// Distributed under an MIT license: http://codemirror.net/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; | ||
|
||
function firstNonWS(str) { | ||
var found = str.search(nonWS); | ||
return found == -1 ? 0 : found; | ||
} | ||
|
||
CodeMirror.commands.toggleComment = function(cm) { | ||
var minLine = Infinity, ranges = cm.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)) mode = "un"; | ||
else { cm.lineComment(from, to); mode = "line"; } | ||
} else if (mode == "un") { | ||
cm.uncomment(from, to); | ||
} else { | ||
cm.lineComment(from, to); | ||
} | ||
} | ||
}; | ||
|
||
CodeMirror.defineExtension("lineComment", function(from, to, options) { | ||
if (!options) options = noOptions; | ||
var self = this, mode = self.getModeAt(from); | ||
var commentString = options.lineComment || mode.lineComment; | ||
if (!commentString) { | ||
if (options.blockCommentStart || mode.blockCommentStart) { | ||
options.fullLines = true; | ||
self.blockComment(from, to, options); | ||
} | ||
return; | ||
} | ||
var firstLine = self.getLine(from.line); | ||
if (firstLine == null) 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 = firstLine.slice(0, firstNonWS(firstLine)); | ||
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 = self.getModeAt(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; | ||
} | ||
|
||
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 { | ||
self.replaceRange(endString, to); | ||
self.replaceRange(startString, from); | ||
} | ||
}); | ||
}); | ||
|
||
CodeMirror.defineExtension("uncomment", function(from, to, options) { | ||
if (!options) options = noOptions; | ||
var self = this, mode = self.getModeAt(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 && (i != end || i == start) && 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), endLine = end == start ? startLine : self.getLine(end); | ||
var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endString); | ||
if (close == -1 && start != end) { | ||
endLine = self.getLine(--end); | ||
close = endLine.lastIndexOf(endString); | ||
} | ||
if (open == -1 || close == -1 || | ||
!/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) || | ||
!/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 && 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; | ||
}); | ||
}); |
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,85 @@ | ||
// CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
// Distributed under an MIT license: http://codemirror.net/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) { | ||
var modes = ["clike", "css", "javascript"]; | ||
|
||
for (var i = 0; i < modes.length; ++i) | ||
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "}); | ||
|
||
function continueComment(cm) { | ||
if (cm.getOption("disableInput")) return CodeMirror.Pass; | ||
var ranges = cm.listSelections(), mode, inserts = []; | ||
for (var i = 0; i < ranges.length; i++) { | ||
var pos = ranges[i].head, token = cm.getTokenAt(pos); | ||
if (token.type != "comment") return CodeMirror.Pass; | ||
var modeHere = CodeMirror.innerMode(cm.getMode(), token.state).mode; | ||
if (!mode) mode = modeHere; | ||
else if (mode != modeHere) return CodeMirror.Pass; | ||
|
||
var insert = null; | ||
if (mode.blockCommentStart && mode.blockCommentContinue) { | ||
var end = token.string.indexOf(mode.blockCommentEnd); | ||
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found; | ||
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length && pos.ch >= end) { | ||
// Comment ended, don't continue it | ||
} else if (token.string.indexOf(mode.blockCommentStart) == 0) { | ||
insert = full.slice(0, token.start); | ||
if (!/^\s*$/.test(insert)) { | ||
insert = ""; | ||
for (var j = 0; j < token.start; ++j) insert += " "; | ||
} | ||
} else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 && | ||
found + mode.blockCommentContinue.length > token.start && | ||
/^\s*$/.test(full.slice(0, found))) { | ||
insert = full.slice(0, found); | ||
} | ||
if (insert != null) insert += mode.blockCommentContinue; | ||
} | ||
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) { | ||
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment); | ||
if (found > -1) { | ||
insert = line.slice(0, found); | ||
if (/\S/.test(insert)) insert = null; | ||
else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0]; | ||
} | ||
} | ||
if (insert == null) return CodeMirror.Pass; | ||
inserts[i] = "\n" + insert; | ||
} | ||
|
||
cm.operation(function() { | ||
for (var i = ranges.length - 1; i >= 0; i--) | ||
cm.replaceRange(inserts[i], ranges[i].from(), ranges[i].to(), "+insert"); | ||
}); | ||
} | ||
|
||
function continueLineCommentEnabled(cm) { | ||
var opt = cm.getOption("continueComments"); | ||
if (opt && typeof opt == "object") | ||
return opt.continueLineComment !== false; | ||
return true; | ||
} | ||
|
||
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) { | ||
if (prev && prev != CodeMirror.Init) | ||
cm.removeKeyMap("continueComment"); | ||
if (val) { | ||
var key = "Enter"; | ||
if (typeof val == "string") | ||
key = val; | ||
else if (typeof val == "object" && val.key) | ||
key = val.key; | ||
var map = {name: "continueComment"}; | ||
map[key] = continueComment; | ||
cm.addKeyMap(map); | ||
} | ||
}); | ||
}); |
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,32 @@ | ||
.CodeMirror-dialog { | ||
position: absolute; | ||
left: 0; right: 0; | ||
background: inherit; | ||
z-index: 15; | ||
padding: .1em .8em; | ||
overflow: hidden; | ||
color: inherit; | ||
} | ||
|
||
.CodeMirror-dialog-top { | ||
border-bottom: 1px solid #eee; | ||
top: 0; | ||
} | ||
|
||
.CodeMirror-dialog-bottom { | ||
border-top: 1px solid #eee; | ||
bottom: 0; | ||
} | ||
|
||
.CodeMirror-dialog input { | ||
border: none; | ||
outline: none; | ||
background: transparent; | ||
width: 20em; | ||
color: inherit; | ||
font-family: monospace; | ||
} | ||
|
||
.CodeMirror-dialog button { | ||
font-size: 70%; | ||
} |
Oops, something went wrong.