Merge pull request #101 from b3log/1.1.0

1.1.0
This commit is contained in:
Liang Ding 2014-10-27 16:30:30 +08:00
commit 94d918250a
294 changed files with 3143 additions and 1225 deletions

View File

@ -25,7 +25,8 @@ import (
) )
const ( const (
Ver = "1.0.1" // 当前 Wide 版本 Ver = "1.0.1" // Wide 版本
CodeMirrorVer = "4.7" // 编辑器版本
) )
// Wide 中唯一一个 init 函数. // Wide 中唯一一个 init 函数.
@ -146,7 +147,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(locale), "locale": locale, model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(locale), "locale": locale,
"session": wideSession, "latestSessionContent": userConf.LatestSessionContent, "session": wideSession, "latestSessionContent": userConf.LatestSessionContent,
"pathSeparator": conf.PathSeparator} "pathSeparator": conf.PathSeparator, "codeMirrorVer": CodeMirrorVer}
glog.V(3).Infof("User [%s] has [%d] sessions", username, len(wideSessions)) glog.V(3).Infof("User [%s] has [%d] sessions", username, len(wideSessions))

View File

@ -445,7 +445,10 @@ var editors = {
var rulers = []; var rulers = [];
rulers.push({color: "#ccc", column: 120, lineStyle: "dashed"}); rulers.push({color: "#ccc", column: 120, lineStyle: "dashed"});
var editor = CodeMirror.fromTextArea(document.getElementById("editor" + id), { var textArea = document.getElementById("editor" + id);
textArea.value = data.content;
var editor = CodeMirror.fromTextArea(textArea, {
lineNumbers: true, lineNumbers: true,
autofocus: true, autofocus: true,
autoCloseBrackets: true, autoCloseBrackets: true,
@ -505,7 +508,6 @@ var editors = {
}); });
editor.setSize('100%', $(".edit-panel").height() - $(".edit-panel .tabs").height()); editor.setSize('100%', $(".edit-panel").height() - $(".edit-panel .tabs").height());
editor.setValue(data.content);
editor.setOption("mode", data.mode); editor.setOption("mode", data.mode);
editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]); editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]);

View File

@ -1,115 +0,0 @@
// 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";
CodeMirror.modeInfo = [
{name: "APL", mime: "text/apl", mode: "apl"},
{name: "Asterisk", mime: "text/x-asterisk", mode: "asterisk"},
{name: "C", mime: "text/x-csrc", mode: "clike"},
{name: "C++", mime: "text/x-c++src", mode: "clike"},
{name: "Cobol", mime: "text/x-cobol", mode: "cobol"},
{name: "Java", mime: "text/x-java", mode: "clike"},
{name: "C#", mime: "text/x-csharp", mode: "clike"},
{name: "Scala", mime: "text/x-scala", mode: "clike"},
{name: "Clojure", mime: "text/x-clojure", mode: "clojure"},
{name: "CoffeeScript", mime: "text/x-coffeescript", mode: "coffeescript"},
{name: "Common Lisp", mime: "text/x-common-lisp", mode: "commonlisp"},
{name: "Cypher", mime: "application/x-cypher-query", mode: "cypher"},
{name: "CSS", mime: "text/css", mode: "css"},
{name: "D", mime: "text/x-d", mode: "d"},
{name: "diff", mime: "text/x-diff", mode: "diff"},
{name: "DTD", mime: "application/xml-dtd", mode: "dtd"},
{name: "Dylan", mime: "text/x-dylan", mode: "dylan"},
{name: "ECL", mime: "text/x-ecl", mode: "ecl"},
{name: "Eiffel", mime: "text/x-eiffel", mode: "eiffel"},
{name: "Erlang", mime: "text/x-erlang", mode: "erlang"},
{name: "Fortran", mime: "text/x-fortran", mode: "fortran"},
{name: "F#", mime: "text/x-fsharp", mode: "mllike"},
{name: "Gas", mime: "text/x-gas", mode: "gas"},
{name: "Gherkin", mime: "text/x-feature", mode: "gherkin"},
{name: "GitHub Flavored Markdown", mime: "text/x-gfm", mode: "gfm"},
{name: "Go", mime: "text/x-go", mode: "go"},
{name: "Groovy", mime: "text/x-groovy", mode: "groovy"},
{name: "HAML", mime: "text/x-haml", mode: "haml"},
{name: "Haskell", mime: "text/x-haskell", mode: "haskell"},
{name: "Haxe", mime: "text/x-haxe", mode: "haxe"},
{name: "ASP.NET", mime: "application/x-aspx", mode: "htmlembedded"},
{name: "Embedded Javascript", mime: "application/x-ejs", mode: "htmlembedded"},
{name: "JavaServer Pages", mime: "application/x-jsp", mode: "htmlembedded"},
{name: "HTML", mime: "text/html", mode: "htmlmixed"},
{name: "HTTP", mime: "message/http", mode: "http"},
{name: "Jade", mime: "text/x-jade", mode: "jade"},
{name: "JavaScript", mime: "text/javascript", mode: "javascript"},
{name: "JavaScript", mime: "application/javascript", mode: "javascript"},
{name: "JSON", mime: "application/x-json", mode: "javascript"},
{name: "JSON", mime: "application/json", mode: "javascript"},
{name: "JSON-LD", mime: "application/ld+json", mode: "javascript"},
{name: "TypeScript", mime: "application/typescript", mode: "javascript"},
{name: "Jinja2", mime: null, mode: "jinja2"},
{name: "Julia", mime: "text/x-julia", mode: "julia"},
{name: "Kotlin", mime: "text/x-kotlin", mode: "kotlin"},
{name: "LESS", mime: "text/x-less", mode: "css"},
{name: "LiveScript", mime: "text/x-livescript", mode: "livescript"},
{name: "Lua", mime: "text/x-lua", mode: "lua"},
{name: "Markdown (GitHub-flavour)", mime: "text/x-markdown", mode: "markdown"},
{name: "mIRC", mime: "text/mirc", mode: "mirc"},
{name: "Nginx", mime: "text/x-nginx-conf", mode: "nginx"},
{name: "NTriples", mime: "text/n-triples", mode: "ntriples"},
{name: "OCaml", mime: "text/x-ocaml", mode: "mllike"},
{name: "Octave", mime: "text/x-octave", mode: "octave"},
{name: "Pascal", mime: "text/x-pascal", mode: "pascal"},
{name: "PEG.js", mime: null, mode: "pegjs"},
{name: "Perl", mime: "text/x-perl", mode: "perl"},
{name: "PHP", mime: "text/x-php", mode: "php"},
{name: "PHP(HTML)", mime: "application/x-httpd-php", mode: "php"},
{name: "Pig", mime: "text/x-pig", mode: "pig"},
{name: "Plain Text", mime: "text/plain", mode: "null"},
{name: "Properties files", mime: "text/x-properties", mode: "properties"},
{name: "Python", mime: "text/x-python", mode: "python"},
{name: "Puppet", mime: "text/x-puppet", mode: "puppet"},
{name: "Cython", mime: "text/x-cython", mode: "python"},
{name: "R", mime: "text/x-rsrc", mode: "r"},
{name: "reStructuredText", mime: "text/x-rst", mode: "rst"},
{name: "Ruby", mime: "text/x-ruby", mode: "ruby"},
{name: "Rust", mime: "text/x-rustsrc", mode: "rust"},
{name: "Sass", mime: "text/x-sass", mode: "sass"},
{name: "Scheme", mime: "text/x-scheme", mode: "scheme"},
{name: "SCSS", mime: "text/x-scss", mode: "css"},
{name: "Shell", mime: "text/x-sh", mode: "shell"},
{name: "Sieve", mime: "application/sieve", mode: "sieve"},
{name: "Slim", mime: "text/x-slim", mode: "slim"},
{name: "Smalltalk", mime: "text/x-stsrc", mode: "smalltalk"},
{name: "Smarty", mime: "text/x-smarty", mode: "smarty"},
{name: "SmartyMixed", mime: "text/x-smarty", mode: "smartymixed"},
{name: "Solr", mime: "text/x-solr", mode: "solr"},
{name: "SPARQL", mime: "application/x-sparql-query", mode: "sparql"},
{name: "SQL", mime: "text/x-sql", mode: "sql"},
{name: "MariaDB", mime: "text/x-mariadb", mode: "sql"},
{name: "sTeX", mime: "text/x-stex", mode: "stex"},
{name: "LaTeX", mime: "text/x-latex", mode: "stex"},
{name: "SystemVerilog", mime: "text/x-systemverilog", mode: "verilog"},
{name: "Tcl", mime: "text/x-tcl", mode: "tcl"},
{name: "TiddlyWiki ", mime: "text/x-tiddlywiki", mode: "tiddlywiki"},
{name: "Tiki wiki", mime: "text/tiki", mode: "tiki"},
{name: "TOML", mime: "text/x-toml", mode: "toml"},
{name: "Turtle", mime: "text/turtle", mode: "turtle"},
{name: "VB.NET", mime: "text/x-vb", mode: "vb"},
{name: "VBScript", mime: "text/vbscript", mode: "vbscript"},
{name: "Velocity", mime: "text/velocity", mode: "velocity"},
{name: "Verilog", mime: "text/x-verilog", mode: "verilog"},
{name: "XML", mime: "application/xml", mode: "xml"},
{name: "XQuery", mime: "application/xquery", mode: "xquery"},
{name: "YAML", mime: "text/x-yaml", mode: "yaml"},
{name: "Z80", mime: "text/x-z80", mode: "z80"}
];
});

View File

@ -109,7 +109,7 @@
CodeMirror.defineExtension("uncomment", function(from, to, options) { CodeMirror.defineExtension("uncomment", function(from, to, options) {
if (!options) options = noOptions; if (!options) options = noOptions;
var self = this, mode = self.getModeAt(from); var self = this, mode = self.getModeAt(from);
var end = Math.min(to.line, self.lastLine()), start = Math.min(from.line, end); 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 // Try finding line comments
var lineString = options.lineComment || mode.lineComment, lines = []; var lineString = options.lineComment || mode.lineComment, lines = [];

View File

@ -56,7 +56,10 @@
var inp = dialog.getElementsByTagName("input")[0], button; var inp = dialog.getElementsByTagName("input")[0], button;
if (inp) { if (inp) {
if (options.value) inp.value = options.value; if (options.value) {
inp.value = options.value;
inp.select();
}
if (options.onInput) if (options.onInput)
CodeMirror.on(inp, "input", function(e) { options.onInput(e, inp.value, close);}); CodeMirror.on(inp, "input", function(e) { options.onInput(e, inp.value, close);});
@ -129,8 +132,8 @@
CodeMirror.defineExtension("openNotification", function(template, options) { CodeMirror.defineExtension("openNotification", function(template, options) {
closeNotification(this, close); closeNotification(this, close);
var dialog = dialogDiv(this, template, options && options.bottom); var dialog = dialogDiv(this, template, options && options.bottom);
var duration = options && (options.duration === undefined ? 5000 : options.duration);
var closed = false, doneTimer; var closed = false, doneTimer;
var duration = options && typeof options.duration !== "undefined" ? options.duration : 5000;
function close() { function close() {
if (closed) return; if (closed) return;
@ -143,7 +146,10 @@
CodeMirror.e_preventDefault(e); CodeMirror.e_preventDefault(e);
close(); close();
}); });
if (duration) if (duration)
doneTimer = setTimeout(close, options.duration); doneTimer = setTimeout(close, duration);
return close;
}); });
}); });

View File

@ -78,24 +78,25 @@
for (var i = 0; i < ranges.length; i++) { for (var i = 0; i < ranges.length; i++) {
var range = ranges[i], cur = range.head, curType; var range = ranges[i], cur = range.head, curType;
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1)); var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
if (!range.empty()) if (!range.empty()) {
curType = "surround"; curType = "surround";
else if (left == right && next == right) { } else if (left == right && next == right) {
if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left) if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left)
curType = "skipThree"; curType = "skipThree";
else else
curType = "skip"; curType = "skip";
} else if (left == right && cur.ch > 1 && } else if (left == right && cur.ch > 1 &&
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left && 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)) (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left)) {
curType = "addFour"; curType = "addFour";
else if (left == '"' || left == "'") { } else if (left == '"' || left == "'") {
if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, left)) curType = "both"; if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, left)) curType = "both";
else return CodeMirror.Pass; else return CodeMirror.Pass;
} else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next)) } else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next)) {
curType = "both"; curType = "both";
else } else {
return CodeMirror.Pass; return CodeMirror.Pass;
}
if (!type) type = curType; if (!type) type = curType;
else if (type != curType) return CodeMirror.Pass; else if (type != curType) return CodeMirror.Pass;
} }

View File

@ -102,12 +102,26 @@
var pos = ranges[i].head, tok = cm.getTokenAt(pos); var pos = ranges[i].head, tok = cm.getTokenAt(pos);
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state; var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
if (tok.type == "string" || tok.string.charAt(0) != "<" || if (tok.type == "string" || tok.string.charAt(0) != "<" ||
tok.start != pos.ch - 1 || inner.mode.name != "xml" || tok.start != pos.ch - 1)
!state.context || !state.context.tagName || return CodeMirror.Pass;
// Kludge to get around the fact that we are not in XML mode
// when completing in JS/CSS snippet in htmlmixed mode. Does not
// work for other XML embedded languages (there is no general
// way to go from a mixed mode to its current XML state).
if (inner.mode.name != "xml") {
if (cm.getMode().name == "htmlmixed" && inner.mode.name == "javascript")
replacements[i] = "/script>";
else if (cm.getMode().name == "htmlmixed" && inner.mode.name == "css")
replacements[i] = "/style>";
else
return CodeMirror.Pass;
} else {
if (!state.context || !state.context.tagName ||
closingTagExists(cm, state.context.tagName, pos, state)) closingTagExists(cm, state.context.tagName, pos, state))
return CodeMirror.Pass; return CodeMirror.Pass;
replacements[i] = "/" + state.context.tagName + ">"; replacements[i] = "/" + state.context.tagName + ">";
} }
}
cm.replaceSelections(replacements); cm.replaceSelections(replacements);
ranges = cm.listSelections(); ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) for (var i = 0; i < ranges.length; i++)

View File

@ -11,7 +11,8 @@
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";
var listRE = /^(\s*)([*+-]|(\d+)\.)(\s+)/, var listRE = /^(\s*)([> ]+|[*+-]|(\d+)\.)(\s+)/,
emptyListRE = /^(\s*)([> ]+|[*+-]|(\d+)\.)(\s*)$/,
unorderedBullets = "*+-"; unorderedBullets = "*+-";
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) { CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
@ -19,19 +20,31 @@
var ranges = cm.listSelections(), replacements = []; var ranges = cm.listSelections(), replacements = [];
for (var i = 0; i < ranges.length; i++) { for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].head, match; var pos = ranges[i].head, match;
var inList = cm.getStateAfter(pos.line).list !== false; var eolState = cm.getStateAfter(pos.line);
var inList = eolState.list !== false;
var inQuote = eolState.quote !== false;
if (!ranges[i].empty() || !inList || !(match = cm.getLine(pos.line).match(listRE))) { if (!ranges[i].empty() || (!inList && !inQuote) || !(match = cm.getLine(pos.line).match(listRE))) {
cm.execCommand("newlineAndIndent"); cm.execCommand("newlineAndIndent");
return; return;
} }
if (cm.getLine(pos.line).match(emptyListRE)) {
cm.replaceRange("", {
line: pos.line, ch: 0
}, {
line: pos.line, ch: pos.ch + 1
});
replacements[i] = "\n";
} else {
var indent = match[1], after = match[4]; var indent = match[1], after = match[4];
var bullet = unorderedBullets.indexOf(match[2]) >= 0 var bullet = unorderedBullets.indexOf(match[2]) >= 0 || match[2].indexOf(">") >= 0
? match[2] ? match[2]
: (parseInt(match[3], 10) + 1) + "."; : (parseInt(match[3], 10) + 1) + ".";
replacements[i] = "\n" + indent + bullet + after; replacements[i] = "\n" + indent + bullet + after;
} }
}
cm.replaceSelections(replacements); cm.replaceSelections(replacements);
}; };

View File

@ -3,9 +3,9 @@
(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror", "./xml-hint"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror", "./xml-hint"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function(CodeMirror) {

View File

@ -32,7 +32,7 @@
cursor: pointer; cursor: pointer;
} }
.CodeMirror-hint-active { li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;
} }

View File

@ -12,6 +12,7 @@
"use strict"; "use strict";
var tables; var tables;
var defaultTable;
var keywords; var keywords;
var CONS = { var CONS = {
QUERY_DIV: ";", QUERY_DIV: ";",
@ -43,19 +44,56 @@
} }
} }
function columnCompletion(result, editor) { function nameCompletion(result, editor) {
var cur = editor.getCursor(); var cur = editor.getCursor();
var token = editor.getTokenAt(cur); var token = editor.getTokenAt(cur);
var useBacktick = (token.string.charAt(0) == "`");
var string = token.string.substr(1); var string = token.string.substr(1);
var prevCur = Pos(cur.line, token.start); var prevToken = editor.getTokenAt(Pos(cur.line, token.start));
var table = editor.getTokenAt(prevCur).string; if (token.string.charAt(0) == "." || prevToken.string == "."){
//Suggest colunm names
if (prevToken.string == ".") {
var prevToken = editor.getTokenAt(Pos(cur.line, token.start - 1));
}
var table = prevToken.string;
//Check if backtick is used in table name. If yes, use it for columns too.
var useBacktickTable = false;
if (table.match(/`/g)) {
useBacktickTable = true;
table = table.replace(/`/g, "");
}
//Check if table is available. If not, find table by Alias
if (!tables.hasOwnProperty(table)) if (!tables.hasOwnProperty(table))
table = findTableByAlias(table, editor); table = findTableByAlias(table, editor);
var columns = tables[table]; var columns = tables[table];
if (!columns) return; if (!columns) return;
if (useBacktick) {
addMatches(result, string, columns, function(w) {return "`" + w + "`";});
}
else if(useBacktickTable) {
addMatches(result, string, columns, function(w) {return ".`" + w + "`";});
}
else {
addMatches(result, string, columns, function(w) {return "." + w;}); addMatches(result, string, columns, function(w) {return "." + w;});
} }
}
else {
//Suggest table names or colums in defaultTable
while (token.start && string.charAt(0) == ".") {
token = editor.getTokenAt(Pos(cur.line, token.start - 1));
string = token.string + string;
}
if (useBacktick) {
addMatches(result, string, tables, function(w) {return "`" + w + "`";});
addMatches(result, string, defaultTable, function(w) {return "`" + w + "`";});
}
else {
addMatches(result, string, tables, function(w) {return w;});
addMatches(result, string, defaultTable, function(w) {return w;});
}
}
}
function eachWord(lineText, f) { function eachWord(lineText, f) {
if (!lineText) return; if (!lineText) return;
@ -128,11 +166,14 @@
CodeMirror.registerHelper("hint", "sql", function(editor, options) { CodeMirror.registerHelper("hint", "sql", function(editor, options) {
tables = (options && options.tables) || {}; tables = (options && options.tables) || {};
var defaultTableName = options && options.defaultTable;
defaultTable = (defaultTableName && tables[defaultTableName] || []);
keywords = keywords || getKeywords(editor); keywords = keywords || getKeywords(editor);
var cur = editor.getCursor(); var cur = editor.getCursor();
var result = []; var result = [];
var token = editor.getTokenAt(cur), start, end, search; var token = editor.getTokenAt(cur), start, end, search;
if (token.string.match(/^[.\w@]\w*$/)) { if (token.string.match(/^[.`\w@]\w*$/)) {
search = token.string; search = token.string;
start = token.start; start = token.start;
end = token.end; end = token.end;
@ -140,18 +181,11 @@
start = end = cur.ch; start = end = cur.ch;
search = ""; search = "";
} }
if (search.charAt(0) == ".") { if (search.charAt(0) == "." || search.charAt(0) == "`") {
columnCompletion(result, editor); nameCompletion(result, editor);
if (!result.length) {
while (start && search.charAt(0) == ".") {
token = editor.getTokenAt(Pos(cur.line, token.start - 1));
start = token.start;
search = token.string + search;
}
addMatches(result, search, tables, function(w) {return w;});
}
} else { } else {
addMatches(result, search, tables, function(w) {return w;}); addMatches(result, search, tables, function(w) {return w;});
addMatches(result, search, defaultTable, function(w) {return w;});
addMatches(result, search, keywords, function(w) {return w.toUpperCase();}); addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
} }

View File

@ -118,10 +118,11 @@
function startLinting(cm) { function startLinting(cm) {
var state = cm.state.lint, options = state.options; var state = cm.state.lint, options = state.options;
var passOptions = options.options || options; // Support deprecated passing of `options` property in options
if (options.async) if (options.async)
options.getAnnotations(cm, updateLinting, options); options.getAnnotations(cm.getValue(), updateLinting, passOptions, cm);
else else
updateLinting(cm, options.getAnnotations(cm.getValue(), options.options)); updateLinting(cm, options.getAnnotations(cm.getValue(), passOptions, cm));
} }
function updateLinting(cm, annotationsNotSorted) { function updateLinting(cm, annotationsNotSorted) {
@ -170,22 +171,16 @@
showTooltipFor(e, annotationTooltip(ann), target); showTooltipFor(e, annotationTooltip(ann), target);
} }
// When the mouseover fires, the cursor might not actually be over
// the character itself yet. These pairs of x,y offsets are used to
// probe a few nearby points when no suitable marked range is found.
var nearby = [0, 0, 0, 5, 0, -5, 5, 0, -5, 0];
function onMouseOver(cm, e) { function onMouseOver(cm, e) {
if (!/\bCodeMirror-lint-mark-/.test((e.target || e.srcElement).className)) return; var target = e.target || e.srcElement;
for (var i = 0; i < nearby.length; i += 2) { if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
var spans = cm.findMarksAt(cm.coordsChar({left: e.clientX + nearby[i], var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
top: e.clientY + nearby[i + 1]}, "client")); var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
for (var j = 0; j < spans.length; ++j) { for (var i = 0; i < spans.length; ++i) {
var span = spans[j], ann = span.__annotation; var ann = spans[i].__annotation;
if (ann) return popupSpanTooltip(ann, e); if (ann) return popupSpanTooltip(ann, e);
} }
} }
}
CodeMirror.defineOption("lint", false, function(cm, val, old) { CodeMirror.defineOption("lint", false, function(cm, val, old) {
if (old && old != CodeMirror.Init) { if (old && old != CodeMirror.Init) {

View File

@ -1,17 +1,17 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // 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";
// declare global: diff_match_patch, DIFF_INSERT, DIFF_DELETE, DIFF_EQUAL // declare global: diff_match_patch, DIFF_INSERT, DIFF_DELETE, DIFF_EQUAL
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("diff_match_patch"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "diff_match_patch"], mod);
else // Plain browser env
mod(CodeMirror, diff_match_patch);
})(function(CodeMirror, diff_match_patch) {
"use strict";
var Pos = CodeMirror.Pos; var Pos = CodeMirror.Pos;
var svgNS = "http://www.w3.org/2000/svg"; var svgNS = "http://www.w3.org/2000/svg";

View File

@ -0,0 +1,210 @@
// 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";
CodeMirror.defineSimpleMode = function(name, states, props) {
CodeMirror.defineMode(name, function(config) {
return CodeMirror.simpleMode(config, states, props);
});
};
CodeMirror.simpleMode = function(config, states) {
ensureState(states, "start");
var states_ = {}, meta = states.meta || {}, hasIndentation = false;
for (var state in states) if (state != meta && states.hasOwnProperty(state)) {
var list = states_[state] = [], orig = states[state];
for (var i = 0; i < orig.length; i++) {
var data = orig[i];
list.push(new Rule(data, states));
if (data.indent || data.dedent) hasIndentation = true;
}
}
var mode = {
startState: function() {
return {state: "start", pending: null,
local: null, localState: null,
indent: hasIndentation ? [] : null};
},
copyState: function(state) {
var s = {state: state.state, pending: state.pending,
local: state.local, localState: null,
indent: state.indent && state.indent.slice(0)};
if (state.localState)
s.localState = CodeMirror.copyState(state.local.mode, state.localState);
if (state.stack)
s.stack = state.stack.slice(0);
for (var pers = state.persistentStates; pers; pers = pers.next)
s.persistentStates = {mode: pers.mode,
spec: pers.spec,
state: pers.state == state.localState ? s.localState : CodeMirror.copyState(pers.mode, pers.state),
next: s.persistentStates};
return s;
},
token: tokenFunction(states_, config),
innerMode: function(state) { return state.local && {mode: state.local.mode, state: state.localState}; },
indent: indentFunction(states_, meta)
};
if (meta) for (var prop in meta) if (meta.hasOwnProperty(prop))
mode[prop] = meta[prop];
return mode;
};
function ensureState(states, name) {
if (!states.hasOwnProperty(name))
throw new Error("Undefined state " + name + "in simple mode");
}
function toRegex(val, caret) {
if (!val) return /(?:)/;
var flags = "";
if (val instanceof RegExp) {
if (val.ignoreCase) flags = "i";
val = val.source;
} else {
val = String(val);
}
return new RegExp((caret === false ? "" : "^") + "(?:" + val + ")", flags);
}
function asToken(val) {
if (!val) return null;
if (typeof val == "string") return val.replace(/\./g, " ");
var result = [];
for (var i = 0; i < val.length; i++)
result.push(val[i] && val[i].replace(/\./g, " "));
return result;
}
function Rule(data, states) {
if (data.next || data.push) ensureState(states, data.next || data.push);
this.regex = toRegex(data.regex);
this.token = asToken(data.token);
this.data = data;
}
function tokenFunction(states, config) {
return function(stream, state) {
if (state.pending) {
var pend = state.pending.shift();
if (state.pending.length == 0) state.pending = null;
stream.pos += pend.text.length;
return pend.token;
}
if (state.local) {
if (state.local.end && stream.match(state.local.end)) {
var tok = state.local.endToken || null;
state.local = state.localState = null;
return tok;
} else {
var tok = state.local.mode.token(stream, state.localState), m;
if (state.local.endScan && (m = state.local.endScan.exec(stream.current())))
stream.pos = stream.start + m.index;
return tok;
}
}
var curState = states[state.state];
for (var i = 0; i < curState.length; i++) {
var rule = curState[i];
var matches = stream.match(rule.regex);
if (matches) {
if (rule.data.next) {
state.state = rule.data.next;
} else if (rule.data.push) {
(state.stack || (state.stack = [])).push(state.state);
state.state = rule.data.push;
} else if (rule.data.pop && state.stack && state.stack.length) {
state.state = state.stack.pop();
}
if (rule.data.mode)
enterLocalMode(config, state, rule.data.mode, rule.token);
if (rule.data.indent)
state.indent.push(stream.indentation() + config.indentUnit);
if (rule.data.dedent)
state.indent.pop();
if (matches.length > 2) {
state.pending = [];
for (var j = 2; j < matches.length; j++)
if (matches[j])
state.pending.push({text: matches[j], token: rule.token[j - 1]});
stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0));
return rule.token[0];
} else if (rule.token && rule.token.join) {
return rule.token[0];
} else {
return rule.token;
}
}
}
stream.next();
return null;
};
}
function cmp(a, b) {
if (a === b) return true;
if (!a || typeof a != "object" || !b || typeof b != "object") return false;
var props = 0;
for (var prop in a) if (a.hasOwnProperty(prop)) {
if (!b.hasOwnProperty(prop) || !cmp(a[prop], b[prop])) return false;
props++;
}
for (var prop in b) if (b.hasOwnProperty(prop)) props--;
return props == 0;
}
function enterLocalMode(config, state, spec, token) {
var pers;
if (spec.persistent) for (var p = state.persistentStates; p && !pers; p = p.next)
if (spec.spec ? cmp(spec.spec, p.spec) : spec.mode == p.mode) pers = p;
var mode = pers ? pers.mode : spec.mode || CodeMirror.getMode(config, spec.spec);
var lState = pers ? pers.state : CodeMirror.startState(mode);
if (spec.persistent && !pers)
state.persistentStates = {mode: mode, spec: spec.spec, state: lState, next: state.persistentStates};
state.localState = lState;
state.local = {mode: mode,
end: spec.end && toRegex(spec.end),
endScan: spec.end && spec.forceEnd !== false && toRegex(spec.end, false),
endToken: token && token.join ? token[token.length - 1] : token};
}
function indexOf(val, arr) {
for (var i = 0; i < arr.length; i++) if (arr[i] === val) return true;
}
function indentFunction(states, meta) {
return function(state, textAfter, line) {
if (state.local && state.local.mode.indent)
return state.local.mode.indent(state.localState, textAfter, line);
if (state.indent == null || state.local || meta.dontIndentStates && indexOf(state.state, meta.dontIndentStates) > -1)
return CodeMirror.Pass;
var pos = state.indent.length - 1, rules = states[state.state];
scan: for (;;) {
for (var i = 0; i < rules.length; i++) {
var rule = rules[i], m = rule.regex.exec(textAfter);
if (m && m[0]) {
if (rule.data.dedent && rule.data.dedentIfLineStart !== false) pos--;
if (rule.next || rule.push) rules = states[rule.next || rule.push];
textAfter = textAfter.slice(m[0].length);
continue scan;
}
}
break;
}
return pos < 0 ? 0 : state.indent[pos];
};
}
});

View File

@ -74,7 +74,11 @@ CodeMirror.startState = function (mode, a1, a2) {
}; };
var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {}; var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
CodeMirror.defineMode = function (name, mode) { modes[name] = mode; }; CodeMirror.defineMode = function (name, mode) {
if (arguments.length > 2)
mode.dependencies = Array.prototype.slice.call(arguments, 2);
modes[name] = mode;
};
CodeMirror.defineMIME = function (mime, spec) { mimeModes[mime] = spec; }; CodeMirror.defineMIME = function (mime, spec) { mimeModes[mime] = spec; };
CodeMirror.resolveMode = function(spec) { CodeMirror.resolveMode = function(spec) {
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) { if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {

View File

@ -74,10 +74,8 @@ exports.startState = function(mode, a1, a2) {
var modes = exports.modes = {}, mimeModes = exports.mimeModes = {}; var modes = exports.modes = {}, mimeModes = exports.mimeModes = {};
exports.defineMode = function(name, mode) { exports.defineMode = function(name, mode) {
if (arguments.length > 2) { if (arguments.length > 2)
mode.dependencies = []; mode.dependencies = Array.prototype.slice.call(arguments, 2);
for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
}
modes[name] = mode; modes[name] = mode;
}; };
exports.defineMIME = function(mime, spec) { mimeModes[mime] = spec; }; exports.defineMIME = function(mime, spec) { mimeModes[mime] = spec; };

View File

@ -8,12 +8,15 @@
// document. // document.
// //
// The option can be set to true to simply enable it, or to a // The option can be set to true to simply enable it, or to a
// {minChars, style, showToken} object to explicitly configure it. // {minChars, style, wordsOnly, showToken, delay} object to explicitly
// minChars is the minimum amount of characters that should be // configure it. minChars is the minimum amount of characters that should be
// selected for the behavior to occur, and style is the token style to // selected for the behavior to occur, and style is the token style to
// apply to the matches. This will be prefixed by "cm-" to create an // apply to the matches. This will be prefixed by "cm-" to create an
// actual CSS class name. showToken, when enabled, will cause the // actual CSS class name. If wordsOnly is enabled, the matches will be
// current token to be highlighted when nothing is selected. // highlighted only if the selected text is a word. showToken, when enabled,
// will cause the current token to be highlighted when nothing is selected.
// delay is used to specify how much time to wait, in milliseconds, before
// highlighting the matches.
(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
@ -28,6 +31,7 @@
var DEFAULT_MIN_CHARS = 2; var DEFAULT_MIN_CHARS = 2;
var DEFAULT_TOKEN_STYLE = "matchhighlight"; var DEFAULT_TOKEN_STYLE = "matchhighlight";
var DEFAULT_DELAY = 100; var DEFAULT_DELAY = 100;
var DEFAULT_WORDS_ONLY = false;
function State(options) { function State(options) {
if (typeof options == "object") { if (typeof options == "object") {
@ -35,10 +39,12 @@
this.style = options.style; this.style = options.style;
this.showToken = options.showToken; this.showToken = options.showToken;
this.delay = options.delay; this.delay = options.delay;
this.wordsOnly = options.wordsOnly;
} }
if (this.style == null) this.style = DEFAULT_TOKEN_STYLE; if (this.style == null) this.style = DEFAULT_TOKEN_STYLE;
if (this.minChars == null) this.minChars = DEFAULT_MIN_CHARS; if (this.minChars == null) this.minChars = DEFAULT_MIN_CHARS;
if (this.delay == null) this.delay = DEFAULT_DELAY; if (this.delay == null) this.delay = DEFAULT_DELAY;
if (this.wordsOnly == null) this.wordsOnly = DEFAULT_WORDS_ONLY;
this.overlay = this.timeout = null; this.overlay = this.timeout = null;
} }
@ -81,12 +87,30 @@
} }
var from = cm.getCursor("from"), to = cm.getCursor("to"); var from = cm.getCursor("from"), to = cm.getCursor("to");
if (from.line != to.line) return; if (from.line != to.line) return;
if (state.wordsOnly && !isWord(cm, from, to)) return;
var selection = cm.getRange(from, to).replace(/^\s+|\s+$/g, ""); var selection = cm.getRange(from, to).replace(/^\s+|\s+$/g, "");
if (selection.length >= state.minChars) if (selection.length >= state.minChars)
cm.addOverlay(state.overlay = makeOverlay(selection, false, state.style)); cm.addOverlay(state.overlay = makeOverlay(selection, false, state.style));
}); });
} }
function isWord(cm, from, to) {
var str = cm.getRange(from, to);
if (str.match(/^\w+$/) !== null) {
if (from.ch > 0) {
var pos = {line: from.line, ch: from.ch - 1};
var chr = cm.getRange(pos, from);
if (chr.match(/\W/) === null) return false;
}
if (to.ch < cm.getLine(from.line).length) {
var pos = {line: to.line, ch: to.ch + 1};
var chr = cm.getRange(to, pos);
if (chr.match(/\W/) === null) return false;
}
return true;
} else return false;
}
function boundariesAround(stream, re) { function boundariesAround(stream, re) {
return (!stream.start || !re.test(stream.string.charAt(stream.start - 1))) && return (!stream.start || !re.test(stream.string.charAt(stream.start - 1))) &&
(stream.pos == stream.string.length || !re.test(stream.string.charAt(stream.pos))); (stream.pos == stream.string.length || !re.test(stream.string.charAt(stream.pos)));

View File

@ -57,6 +57,10 @@
border: 0; border: 0;
background: #7e7; background: #7e7;
} }
.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursors {
z-index: 1;
}
.cm-animate-fat-cursor { .cm-animate-fat-cursor {
width: auto; width: auto;
border: 0; border: 0;
@ -83,7 +87,7 @@
/* Can style cursor different in overwrite (non-insert) mode */ /* Can style cursor different in overwrite (non-insert) mode */
div.CodeMirror-overwrite div.CodeMirror-cursor {} div.CodeMirror-overwrite div.CodeMirror-cursor {}
.cm-tab { display: inline-block; } .cm-tab { display: inline-block; text-decoration: inherit; }
.CodeMirror-ruler { .CodeMirror-ruler {
border-left: 1px solid #ccc; border-left: 1px solid #ccc;
@ -213,6 +217,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
.CodeMirror-lines { .CodeMirror-lines {
cursor: text; cursor: text;
min-height: 1px; /* prevents collapsing before first draw */
} }
.CodeMirror pre { .CodeMirror pre {
/* Reset some styles that the rest of the page might have set */ /* Reset some styles that the rest of the page might have set */
@ -272,7 +277,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
div.CodeMirror-cursors { div.CodeMirror-cursors {
visibility: hidden; visibility: hidden;
position: relative; position: relative;
z-index: 1; z-index: 3;
} }
.CodeMirror-focused div.CodeMirror-cursors { .CodeMirror-focused div.CodeMirror-cursors {
visibility: visible; visibility: visible;
@ -299,3 +304,6 @@ div.CodeMirror-cursors {
visibility: hidden; visibility: hidden;
} }
} }
/* Help users use markselection to safely style text background */
span.CodeMirror-selectedtext { background: none; }

View File

@ -61,7 +61,7 @@
function CodeMirror(place, options) { function CodeMirror(place, options) {
if (!(this instanceof CodeMirror)) return new CodeMirror(place, options); if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
this.options = options = options || {}; this.options = options = options ? copyObj(options) : {};
// Determine effective options based on given values and defaults. // Determine effective options based on given values and defaults.
copyObj(defaults, options, false); copyObj(defaults, options, false);
setGuttersForLineNumbers(options); setGuttersForLineNumbers(options);
@ -96,21 +96,20 @@
registerEventHandlers(this); registerEventHandlers(this);
ensureGlobalHandlers(); ensureGlobalHandlers();
var cm = this; startOperation(this);
runInOp(this, function() { this.curOp.forceUpdate = true;
cm.curOp.forceUpdate = true; attachDoc(this, doc);
attachDoc(cm, doc);
if ((options.autofocus && !mobile) || activeElt() == display.input) if ((options.autofocus && !mobile) || activeElt() == display.input)
setTimeout(bind(onFocus, cm), 20); setTimeout(bind(onFocus, this), 20);
else else
onBlur(cm); onBlur(this);
for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt)) for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
optionHandlers[opt](cm, options[opt], Init); optionHandlers[opt](this, options[opt], Init);
maybeUpdateLineNumberWidth(cm); maybeUpdateLineNumberWidth(this);
for (var i = 0; i < initHooks.length; ++i) initHooks[i](cm); for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
}); endOperation(this);
} }
// DISPLAY CONSTRUCTOR // DISPLAY CONSTRUCTOR
@ -723,9 +722,10 @@
// view, so that we don't interleave reading and writing to the DOM. // view, so that we don't interleave reading and writing to the DOM.
function getDimensions(cm) { function getDimensions(cm) {
var d = cm.display, left = {}, width = {}; var d = cm.display, left = {}, width = {};
var gutterLeft = d.gutters.clientLeft;
for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) { for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
left[cm.options.gutters[i]] = n.offsetLeft; left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
width[cm.options.gutters[i]] = n.offsetWidth; width[cm.options.gutters[i]] = n.clientWidth;
} }
return {fixedPos: compensateForHScroll(d), return {fixedPos: compensateForHScroll(d),
gutterTotalWidth: d.gutters.offsetWidth, gutterTotalWidth: d.gutters.offsetWidth,
@ -1646,7 +1646,7 @@
var rect; var rect;
if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates. if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
for (;;) { for (var i = 0; i < 4; i++) { // Retry a maximum of 4 times when nonsense rectangles are returned
while (start && isExtendingChar(prepared.line.text.charAt(mStart + start))) --start; while (start && isExtendingChar(prepared.line.text.charAt(mStart + start))) --start;
while (mStart + end < mEnd && isExtendingChar(prepared.line.text.charAt(mStart + end))) ++end; while (mStart + end < mEnd && isExtendingChar(prepared.line.text.charAt(mStart + end))) ++end;
if (ie && ie_version < 9 && start == 0 && end == mEnd - mStart) { if (ie && ie_version < 9 && start == 0 && end == mEnd - mStart) {
@ -1665,6 +1665,7 @@
start = start - 1; start = start - 1;
collapse = "right"; collapse = "right";
} }
if (ie && ie_version < 11) rect = maybeUpdateRectForZooming(cm.display.measure, rect);
} else { // If it is a widget, simply get the box for the whole widget. } else { // If it is a widget, simply get the box for the whole widget.
if (start > 0) collapse = bias = "right"; if (start > 0) collapse = bias = "right";
var rects; var rects;
@ -1681,8 +1682,6 @@
rect = nullRect; rect = nullRect;
} }
if (ie && ie_version < 11) rect = maybeUpdateRectForZooming(cm.display.measure, rect);
var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top; var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
var mid = (rtop + rbot) / 2; var mid = (rtop + rbot) / 2;
var heights = prepared.view.measure.heights; var heights = prepared.view.measure.heights;
@ -2090,11 +2089,11 @@
display.wheelStartX = display.wheelStartY = null; display.wheelStartX = display.wheelStartY = null;
// Propagate the scroll position to the actual DOM scroller // Propagate the scroll position to the actual DOM scroller
if (op.scrollTop != null && display.scroller.scrollTop != op.scrollTop) { if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
var top = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop)); var top = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop));
display.scroller.scrollTop = display.scrollbarV.scrollTop = doc.scrollTop = top; display.scroller.scrollTop = display.scrollbarV.scrollTop = doc.scrollTop = top;
} }
if (op.scrollLeft != null && display.scroller.scrollLeft != op.scrollLeft) { if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
var left = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft)); var left = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft));
display.scroller.scrollLeft = display.scrollbarH.scrollLeft = doc.scrollLeft = left; display.scroller.scrollLeft = display.scrollbarH.scrollLeft = doc.scrollLeft = left;
alignHorizontally(cm); alignHorizontally(cm);
@ -2457,16 +2456,16 @@
cm.options.smartIndent && range.head.ch < 100 && cm.options.smartIndent && range.head.ch < 100 &&
(!i || doc.sel.ranges[i - 1].head.line != range.head.line)) { (!i || doc.sel.ranges[i - 1].head.line != range.head.line)) {
var mode = cm.getModeAt(range.head); var mode = cm.getModeAt(range.head);
var end = changeEnd(changeEvent);
if (mode.electricChars) { if (mode.electricChars) {
for (var j = 0; j < mode.electricChars.length; j++) for (var j = 0; j < mode.electricChars.length; j++)
if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
indentLine(cm, range.head.line, "smart"); indentLine(cm, end.line, "smart");
break; break;
} }
} else if (mode.electricInput) { } else if (mode.electricInput) {
var end = changeEnd(changeEvent);
if (mode.electricInput.test(getLine(doc, end.line).text.slice(0, end.ch))) if (mode.electricInput.test(getLine(doc, end.line).text.slice(0, end.ch)))
indentLine(cm, range.head.line, "smart"); indentLine(cm, end.line, "smart");
} }
} }
} }
@ -2528,7 +2527,7 @@
var pos = posFromMouse(cm, e); var pos = posFromMouse(cm, e);
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return; if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
e_preventDefault(e); e_preventDefault(e);
var word = findWordAt(cm, pos); var word = cm.findWordAt(pos);
extendSelection(cm.doc, word.anchor, word.head); extendSelection(cm.doc, word.anchor, word.head);
})); }));
else else
@ -2807,7 +2806,7 @@
start = posFromMouse(cm, e, true, true); start = posFromMouse(cm, e, true, true);
ourIndex = -1; ourIndex = -1;
} else if (type == "double") { } else if (type == "double") {
var word = findWordAt(cm, start); var word = cm.findWordAt(start);
if (cm.display.shift || doc.extend) if (cm.display.shift || doc.extend)
ourRange = extendRange(doc, ourRange, word.anchor, word.head); ourRange = extendRange(doc, ourRange, word.anchor, word.head);
else else
@ -2861,7 +2860,7 @@
var anchor = oldRange.anchor, head = pos; var anchor = oldRange.anchor, head = pos;
if (type != "single") { if (type != "single") {
if (type == "double") if (type == "double")
var range = findWordAt(cm, pos); var range = cm.findWordAt(pos);
else else
var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0))); var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
if (cmp(range.anchor, anchor) > 0) { if (cmp(range.anchor, anchor) > 0) {
@ -3721,7 +3720,7 @@
// measured, the position of something may 'drift' during drawing). // measured, the position of something may 'drift' during drawing).
function scrollPosIntoView(cm, pos, end, margin) { function scrollPosIntoView(cm, pos, end, margin) {
if (margin == null) margin = 0; if (margin == null) margin = 0;
for (;;) { for (var limit = 0; limit < 5; limit++) {
var changed = false, coords = cursorCoords(cm, pos); var changed = false, coords = cursorCoords(cm, pos);
var endCoords = !end || end == pos ? coords : cursorCoords(cm, end); var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left), var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
@ -3770,7 +3769,7 @@
var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft; var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
var screenw = display.scroller.clientWidth - scrollerCutOff - display.gutters.offsetWidth; var screenw = display.scroller.clientWidth - scrollerCutOff - display.gutters.offsetWidth;
var tooWide = x2 - x1 > screenw; var tooWide = x2 - x1 > screenw;
if (tooWide) x2 = y1 + screen; if (tooWide) x2 = x1 + screenw;
if (x1 < 10) if (x1 < 10)
result.scrollLeft = 0; result.scrollLeft = 0;
else if (x1 < screenleft) else if (x1 < screenleft)
@ -3999,24 +3998,6 @@
return target; return target;
} }
// Find the word at the given position (as returned by coordsChar).
function findWordAt(cm, pos) {
var doc = cm.doc, line = getLine(doc, pos.line).text;
var start = pos.ch, end = pos.ch;
if (line) {
var helper = cm.getHelper(pos, "wordChars");
if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
var startChar = line.charAt(start);
var check = isWordChar(startChar, helper)
? function(ch) { return isWordChar(ch, helper); }
: /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
: function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
while (start > 0 && check(line.charAt(start - 1))) --start;
while (end < line.length && check(line.charAt(end))) ++end;
}
return new Range(Pos(pos.line, start), Pos(pos.line, end));
}
// EDITOR METHODS // EDITOR METHODS
// The publicly visible API. Note that methodOp(f) means // The publicly visible API. Note that methodOp(f) means
@ -4358,6 +4339,24 @@
doc.sel.ranges[i].goalColumn = goals[i]; doc.sel.ranges[i].goalColumn = goals[i];
}), }),
// Find the word at the given position (as returned by coordsChar).
findWordAt: function(pos) {
var doc = this.doc, line = getLine(doc, pos.line).text;
var start = pos.ch, end = pos.ch;
if (line) {
var helper = this.getHelper(pos, "wordChars");
if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
var startChar = line.charAt(start);
var check = isWordChar(startChar, helper)
? function(ch) { return isWordChar(ch, helper); }
: /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
: function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
while (start > 0 && check(line.charAt(start - 1))) --start;
while (end < line.length && check(line.charAt(end))) ++end;
}
return new Range(Pos(pos.line, start), Pos(pos.line, end));
},
toggleOverwrite: function(value) { toggleOverwrite: function(value) {
if (value != null && value == this.state.overwrite) return; if (value != null && value == this.state.overwrite) return;
if (this.state.overwrite = !this.state.overwrite) if (this.state.overwrite = !this.state.overwrite)
@ -4444,6 +4443,7 @@
clearCaches(this); clearCaches(this);
resetInput(this); resetInput(this);
this.scrollTo(doc.scrollLeft, doc.scrollTop); this.scrollTo(doc.scrollLeft, doc.scrollTop);
this.curOp.forceScroll = true;
signalLater(this, "swapDoc", this, old); signalLater(this, "swapDoc", this, old);
return old; return old;
}), }),
@ -4570,10 +4570,8 @@
// load a mode. (Preferred mechanism is the require/define calls.) // load a mode. (Preferred mechanism is the require/define calls.)
CodeMirror.defineMode = function(name, mode) { CodeMirror.defineMode = function(name, mode) {
if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name; if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
if (arguments.length > 2) { if (arguments.length > 2)
mode.dependencies = []; mode.dependencies = Array.prototype.slice.call(arguments, 2);
for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
}
modes[name] = mode; modes[name] = mode;
}; };
@ -4865,7 +4863,7 @@
// are simply ignored. // are simply ignored.
keyMap.pcDefault = { keyMap.pcDefault = {
"Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo", "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
"Ctrl-Home": "goDocStart", "Ctrl-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd", "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
"Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd", "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
"Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find", "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
"Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll", "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
@ -4880,7 +4878,7 @@
"Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find", "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
"Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll", "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
"Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight", "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
"Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
fallthrough: ["basic", "emacsy"] fallthrough: ["basic", "emacsy"]
}; };
// Very basic readline/emacs-style bindings, which are standard on Mac. // Very basic readline/emacs-style bindings, which are standard on Mac.
@ -4988,6 +4986,7 @@
cm.save = save; cm.save = save;
cm.getTextArea = function() { return textarea; }; cm.getTextArea = function() { return textarea; };
cm.toTextArea = function() { cm.toTextArea = function() {
cm.toTextArea = isNaN; // Prevent this from being ran twice
save(); save();
textarea.parentNode.removeChild(cm.getWrapperElement()); textarea.parentNode.removeChild(cm.getWrapperElement());
textarea.style.display = ""; textarea.style.display = "";
@ -7295,7 +7294,7 @@
return function(){return f.apply(null, args);}; return function(){return f.apply(null, args);};
} }
var nonASCIISingleCaseWordChar = /[\u00df\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/; var nonASCIISingleCaseWordChar = /[\u00df\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
var isWordCharBasic = CodeMirror.isWordChar = function(ch) { var isWordCharBasic = CodeMirror.isWordChar = function(ch) {
return /\w/.test(ch) || ch > "\x80" && return /\w/.test(ch) || ch > "\x80" &&
(ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)); (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
@ -7462,7 +7461,7 @@
if (badBidiRects != null) return badBidiRects; if (badBidiRects != null) return badBidiRects;
var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA")); var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
var r0 = range(txt, 0, 1).getBoundingClientRect(); var r0 = range(txt, 0, 1).getBoundingClientRect();
if (r0.left == r0.right) return false; if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780)
var r1 = range(txt, 1, 2).getBoundingClientRect(); var r1 = range(txt, 1, 2).getBoundingClientRect();
return badBidiRects = (r1.right - r0.right < 3); return badBidiRects = (r1.right - r0.right < 3);
} }
@ -7825,7 +7824,7 @@
// THE END // THE END
CodeMirror.version = "4.5.0"; CodeMirror.version = "4.7.0";
return CodeMirror; return CodeMirror;
}); });

View File

@ -12,12 +12,12 @@
.CodeMirror { border: 2px inset #dee; } .CodeMirror { border: 2px inset #dee; }
</style> </style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -12,12 +12,12 @@
.cm-s-default span.cm-arrow { color: red; } .cm-s-default span.cm-arrow { color: red; }
</style> </style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -20,7 +20,8 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
blockKeywords = parserConfig.blockKeywords || {}, blockKeywords = parserConfig.blockKeywords || {},
atoms = parserConfig.atoms || {}, atoms = parserConfig.atoms || {},
hooks = parserConfig.hooks || {}, hooks = parserConfig.hooks || {},
multiLineStrings = parserConfig.multiLineStrings; multiLineStrings = parserConfig.multiLineStrings,
indentStatements = parserConfig.indentStatements !== false;
var isOperatorChar = /[+\-*&%=<>!?|\/]/; var isOperatorChar = /[+\-*&%=<>!?|\/]/;
var curPunc; var curPunc;
@ -57,7 +58,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
stream.eatWhile(isOperatorChar); stream.eatWhile(isOperatorChar);
return "operator"; return "operator";
} }
stream.eatWhile(/[\w\$_]/); stream.eatWhile(/[\w\$_\xa1-\uffff]/);
var cur = stream.current(); var cur = stream.current();
if (keywords.propertyIsEnumerable(cur)) { if (keywords.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
@ -151,7 +152,9 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
while (ctx.type == "statement") ctx = popContext(state); while (ctx.type == "statement") ctx = popContext(state);
} }
else if (curPunc == ctx.type) popContext(state); else if (curPunc == ctx.type) popContext(state);
else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement")) else if (indentStatements &&
(((ctx.type == "}" || ctx.type == "top") && curPunc != ';') ||
(ctx.type == "statement" && curPunc == "newstatement")))
pushContext(state, stream.column(), "statement"); pushContext(state, stream.column(), "statement");
state.startOfLine = false; state.startOfLine = false;
return style; return style;
@ -298,6 +301,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
}, },
modeProps: {fold: ["brace", "include"]} modeProps: {fold: ["brace", "include"]}
}); });
def("text/x-java", { def("text/x-java", {
name: "clike", name: "clike",
keywords: words("abstract assert boolean break byte case catch char class const continue default " + keywords: words("abstract assert boolean break byte case catch char class const continue default " +
@ -315,6 +319,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
}, },
modeProps: {fold: ["brace", "import"]} modeProps: {fold: ["brace", "import"]}
}); });
def("text/x-csharp", { def("text/x-csharp", {
name: "clike", name: "clike",
keywords: words("abstract as base break case catch checked class const continue" + keywords: words("abstract as base break case catch checked class const continue" +
@ -341,6 +346,19 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
} }
} }
}); });
function tokenTripleString(stream, state) {
var escaped = false;
while (!stream.eol()) {
if (!escaped && stream.match('"""')) {
state.tokenize = null;
break;
}
escaped = stream.next() != "\\" && !escaped;
}
return "string";
}
def("text/x-scala", { def("text/x-scala", {
name: "clike", name: "clike",
keywords: words( keywords: words(
@ -366,19 +384,24 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
"Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " + "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
"Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " + "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
"StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void" "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
), ),
multiLineStrings: true, multiLineStrings: true,
blockKeywords: words("catch class do else finally for forSome if match switch try while"), blockKeywords: words("catch class do else finally for forSome if match switch try while"),
atoms: words("true false null"), atoms: words("true false null"),
indentStatements: false,
hooks: { hooks: {
"@": function(stream) { "@": function(stream) {
stream.eatWhile(/[\w\$_]/); stream.eatWhile(/[\w\$_]/);
return "meta"; return "meta";
},
'"': function(stream, state) {
if (!stream.match('""')) return false;
state.tokenize = tokenTripleString;
return state.tokenize(stream, state);
} }
} }
}); });
def(["x-shader/x-vertex", "x-shader/x-fragment"], { def(["x-shader/x-vertex", "x-shader/x-fragment"], {
name: "clike", name: "clike",
keywords: words("float int bool void " + keywords: words("float int bool void " +

View File

@ -12,12 +12,12 @@
<script src="clike.js"></script> <script src="clike.js"></script>
<style>.CodeMirror {border: 2px inset #dee;}</style> <style>.CodeMirror {border: 2px inset #dee;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>
@ -169,6 +169,21 @@ public class Class<T, V> implements MyInterface {
member = value; member = value;
} }
} }
</textarea></div>
<h2>Scala example</h2>
<div><textarea id="scala-code">
object FilterTest extends App {
def filter(xs: List[Int], threshold: Int) = {
def process(ys: List[Int]): List[Int] =
if (ys.isEmpty) ys
else if (ys.head < threshold) ys.head :: process(ys.tail)
else process(ys.tail)
process(xs)
}
println(filter(List(1, 9, 2, 8, 3, 7, 4), 5))
}
</textarea></div> </textarea></div>
<script> <script>
@ -187,6 +202,11 @@ public class Class<T, V> implements MyInterface {
matchBrackets: true, matchBrackets: true,
mode: "text/x-java" mode: "text/x-java"
}); });
var scalaEditor = CodeMirror.fromTextArea(document.getElementById("scala-code"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/x-scala"
});
var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault; var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault;
CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete"; CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete";
</script> </script>
@ -198,7 +218,8 @@ public class Class<T, V> implements MyInterface {
directives are recognized.</p> directives are recognized.</p>
<p><strong>MIME types defined:</strong> <code>text/x-csrc</code> <p><strong>MIME types defined:</strong> <code>text/x-csrc</code>
(C code), <code>text/x-c++src</code> (C++ (C), <code>text/x-c++src</code> (C++), <code>text/x-java</code>
code), <code>text/x-java</code> (Java (Java), <code>text/x-csharp</code> (C#),
code), <code>text/x-csharp</code> (C#).</p> <code>text/x-scala</code> (Scala), <code>text/x-vertex</code>
and <code>x-shader/x-fragment</code> (shader programs).</p>
</article> </article>

View File

@ -10,12 +10,12 @@
<script src="../../addon/edit/matchbrackets.js"></script> <script src="../../addon/edit/matchbrackets.js"></script>
<script src="clike.js"></script> <script src="clike.js"></script>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -18,7 +18,7 @@
CodeMirror.defineMode("clojure", function (options) { CodeMirror.defineMode("clojure", function (options) {
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", CHARACTER = "string-2", var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", CHARACTER = "string-2",
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD = "keyword"; ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD = "keyword", VAR = "variable";
var INDENT_WORD_SKIP = options.indentUnit || 2; var INDENT_WORD_SKIP = options.indentUnit || 2;
var NORMAL_INDENT_UNIT = options.indentUnit || 2; var NORMAL_INDENT_UNIT = options.indentUnit || 2;
@ -59,7 +59,7 @@ CodeMirror.defineMode("clojure", function (options) {
sign: /[+-]/, sign: /[+-]/,
exponent: /e/i, exponent: /e/i,
keyword_char: /[^\s\(\[\;\)\]]/, keyword_char: /[^\s\(\[\;\)\]]/,
symbol: /[\w*+!\-\._?:<>\/]/ symbol: /[\w*+!\-\._?:<>\/\xa1-\uffff]/
}; };
function stateStack(indent, type, prev) { // represents a state stack object function stateStack(indent, type, prev) { // represents a state stack object
@ -220,7 +220,9 @@ CodeMirror.defineMode("clojure", function (options) {
returnType = BUILTIN; returnType = BUILTIN;
} else if (atoms && atoms.propertyIsEnumerable(stream.current())) { } else if (atoms && atoms.propertyIsEnumerable(stream.current())) {
returnType = ATOM; returnType = ATOM;
} else returnType = null; } else {
returnType = VAR;
}
} }
} }

View File

@ -9,12 +9,12 @@
<script src="clojure.js"></script> <script src="clojure.js"></script>
<style>.CodeMirror {background: #f8f8f8;}</style> <style>.CodeMirror {background: #f8f8f8;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -39,12 +39,12 @@
.CodeMirror-activeline-background {background: #555555 !important;} .CodeMirror-activeline-background {background: #555555 !important;}
</style> </style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -22,7 +22,7 @@ CodeMirror.defineMode("coffeescript", function(conf) {
return new RegExp("^((" + words.join(")|(") + "))\\b"); return new RegExp("^((" + words.join(")|(") + "))\\b");
} }
var operators = /^(?:->|=>|\+[+=]?|-[\-=]?|\*[\*=]?|\/[\/=]?|[=!]=|<[><]?=?|>>?=?|%=?|&=?|\|=?|\^=?|\~|!|\?)/; var operators = /^(?:->|=>|\+[+=]?|-[\-=]?|\*[\*=]?|\/[\/=]?|[=!]=|<[><]?=?|>>?=?|%=?|&=?|\|=?|\^=?|\~|!|\?|(or|and|\|\||&&|\?)=)/;
var delimiters = /^(?:[()\[\]{},:`=;]|\.\.?\.?)/; var delimiters = /^(?:[()\[\]{},:`=;]|\.\.?\.?)/;
var identifiers = /^[_A-Za-z$][_A-Za-z$0-9]*/; var identifiers = /^[_A-Za-z$][_A-Za-z$0-9]*/;
var properties = /^(@|this\.)[_A-Za-z$][_A-Za-z$0-9]*/; var properties = /^(@|this\.)[_A-Za-z$][_A-Za-z$0-9]*/;
@ -34,7 +34,7 @@ CodeMirror.defineMode("coffeescript", function(conf) {
"switch", "try", "catch", "finally", "class"]; "switch", "try", "catch", "finally", "class"];
var commonKeywords = ["break", "by", "continue", "debugger", "delete", var commonKeywords = ["break", "by", "continue", "debugger", "delete",
"do", "in", "of", "new", "return", "then", "do", "in", "of", "new", "return", "then",
"this", "throw", "when", "until"]; "this", "@", "throw", "when", "until", "extends"];
var keywords = wordRegexp(indentKeywords.concat(commonKeywords)); var keywords = wordRegexp(indentKeywords.concat(commonKeywords));
@ -217,7 +217,7 @@ CodeMirror.defineMode("coffeescript", function(conf) {
type = type || "coffee"; type = type || "coffee";
var offset = 0, align = false, alignOffset = null; var offset = 0, align = false, alignOffset = null;
for (var scope = state.scope; scope; scope = scope.prev) { for (var scope = state.scope; scope; scope = scope.prev) {
if (scope.type === "coffee") { if (scope.type === "coffee" || scope.type == "}") {
offset = scope.offset + conf.indentUnit; offset = scope.offset + conf.indentUnit;
break; break;
} }
@ -278,7 +278,7 @@ CodeMirror.defineMode("coffeescript", function(conf) {
// Handle scope changes. // Handle scope changes.
if (current === "return") { if (current === "return") {
state.dedent += 1; state.dedent = true;
} }
if (((current === "->" || current === "=>") && if (((current === "->" || current === "=>") &&
!state.lambda && !state.lambda &&
@ -310,9 +310,10 @@ CodeMirror.defineMode("coffeescript", function(conf) {
if (state.scope.type == current) if (state.scope.type == current)
state.scope = state.scope.prev; state.scope = state.scope.prev;
} }
if (state.dedent > 0 && stream.eol() && state.scope.type == "coffee") { if (state.dedent && stream.eol()) {
if (state.scope.prev) state.scope = state.scope.prev; if (state.scope.type == "coffee" && state.scope.prev)
state.dedent -= 1; state.scope = state.scope.prev;
state.dedent = false;
} }
return style; return style;

View File

@ -9,12 +9,12 @@
<script src="coffeescript.js"></script> <script src="coffeescript.js"></script>
<style>.CodeMirror {border-top: 1px solid silver; border-bottom: 1px solid silver;}</style> <style>.CodeMirror {border-top: 1px solid silver; border-bottom: 1px solid silver;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -9,12 +9,12 @@
<script src="commonlisp.js"></script> <script src="commonlisp.js"></script>
<style>.CodeMirror {background: #f8f8f8;}</style> <style>.CodeMirror {background: #f8f8f8;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -9,12 +9,12 @@
<script src="css.js"></script> <script src="css.js"></script>
<style>.CodeMirror {background: #f8f8f8;}</style> <style>.CodeMirror {background: #f8f8f8;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -10,12 +10,12 @@
<script src="css.js"></script> <script src="css.js"></script>
<style>.CodeMirror {border: 1px solid #ddd; line-height: 1.2;}</style> <style>.CodeMirror {border: 1px solid #ddd; line-height: 1.2;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -9,12 +9,12 @@
<script src="css.js"></script> <script src="css.js"></script>
<style>.CodeMirror {background: #f8f8f8;}</style> <style>.CodeMirror {background: #f8f8f8;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -15,12 +15,12 @@
} }
</style> </style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -60,7 +60,7 @@ CodeMirror.defineMode("d", function(config, parserConfig) {
stream.eatWhile(isOperatorChar); stream.eatWhile(isOperatorChar);
return "operator"; return "operator";
} }
stream.eatWhile(/[\w\$_]/); stream.eatWhile(/[\w\$_\xa1-\uffff]/);
var cur = stream.current(); var cur = stream.current();
if (keywords.propertyIsEnumerable(cur)) { if (keywords.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";

View File

@ -10,12 +10,12 @@
<script src="d.js"></script> <script src="d.js"></script>
<style>.CodeMirror {border: 2px inset #dee;}</style> <style>.CodeMirror {border: 2px inset #dee;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -15,12 +15,12 @@
span.cm-error.cm-tag { background-color: #2b2; } span.cm-error.cm-tag { background-color: #2b2; }
</style> </style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -12,12 +12,12 @@
<script src="django.js"></script> <script src="django.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

View File

@ -4,7 +4,7 @@
/* /*
DTD mode DTD mode
Ported to CodeMirror by Peter Kroon <plakroon@gmail.com> Ported to CodeMirror by Peter Kroon <plakroon@gmail.com>
Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues Report bugs/issues here: https://github.com/codemirror/CodeMirror/issues
GitHub: @peterkroon GitHub: @peterkroon
*/ */

View File

@ -9,12 +9,12 @@
<script src="dtd.js"></script> <script src="dtd.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<div id=nav> <div id=nav>
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul> <ul>
<li><a href="../../index.html">Home</a> <li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a> <li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/marijnh/codemirror">Code</a> <li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul> </ul>
<ul> <ul>
<li><a href="../index.html">Language modes</a> <li><a href="../index.html">Language modes</a>

Some files were not shown because too many files have changed in this diff Show More