зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1026811 - Update to CodeMirror 4.2.0. r=robcee
This commit is contained in:
Родитель
f535e3d2d1
Коммит
7f6ce77b60
|
@ -36,16 +36,16 @@ browser.jar:
|
|||
content/browser/devtools/fontinspector/font-inspector.css (fontinspector/font-inspector.css)
|
||||
content/browser/devtools/codemirror/codemirror.js (sourceeditor/codemirror/codemirror.js)
|
||||
content/browser/devtools/codemirror/codemirror.css (sourceeditor/codemirror/codemirror.css)
|
||||
content/browser/devtools/codemirror/javascript.js (sourceeditor/codemirror/javascript.js)
|
||||
content/browser/devtools/codemirror/xml.js (sourceeditor/codemirror/xml.js)
|
||||
content/browser/devtools/codemirror/css.js (sourceeditor/codemirror/css.js)
|
||||
content/browser/devtools/codemirror/htmlmixed.js (sourceeditor/codemirror/htmlmixed.js)
|
||||
content/browser/devtools/codemirror/clike.js (sourceeditor/codemirror/clike.js)
|
||||
content/browser/devtools/codemirror/activeline.js (sourceeditor/codemirror/activeline.js)
|
||||
content/browser/devtools/codemirror/trailingspace.js (sourceeditor/codemirror/trailingspace.js)
|
||||
content/browser/devtools/codemirror/matchbrackets.js (sourceeditor/codemirror/matchbrackets.js)
|
||||
content/browser/devtools/codemirror/closebrackets.js (sourceeditor/codemirror/closebrackets.js)
|
||||
content/browser/devtools/codemirror/comment.js (sourceeditor/codemirror/comment.js)
|
||||
content/browser/devtools/codemirror/javascript.js (sourceeditor/codemirror/mode/javascript.js)
|
||||
content/browser/devtools/codemirror/xml.js (sourceeditor/codemirror/mode/xml.js)
|
||||
content/browser/devtools/codemirror/css.js (sourceeditor/codemirror/mode/css.js)
|
||||
content/browser/devtools/codemirror/htmlmixed.js (sourceeditor/codemirror/mode/htmlmixed.js)
|
||||
content/browser/devtools/codemirror/clike.js (sourceeditor/codemirror/mode/clike.js)
|
||||
content/browser/devtools/codemirror/activeline.js (sourceeditor/codemirror/selection/active-line.js)
|
||||
content/browser/devtools/codemirror/trailingspace.js (sourceeditor/codemirror/edit/trailingspace.js)
|
||||
content/browser/devtools/codemirror/matchbrackets.js (sourceeditor/codemirror/edit/matchbrackets.js)
|
||||
content/browser/devtools/codemirror/closebrackets.js (sourceeditor/codemirror/edit/closebrackets.js)
|
||||
content/browser/devtools/codemirror/comment.js (sourceeditor/codemirror/comment/comment.js)
|
||||
content/browser/devtools/codemirror/searchcursor.js (sourceeditor/codemirror/search/searchcursor.js)
|
||||
content/browser/devtools/codemirror/search.js (sourceeditor/codemirror/search/search.js)
|
||||
content/browser/devtools/codemirror/dialog.js (sourceeditor/codemirror/dialog/dialog.js)
|
||||
|
@ -58,8 +58,8 @@ browser.jar:
|
|||
content/browser/devtools/codemirror/comment-fold.js (sourceeditor/codemirror/fold/comment-fold.js)
|
||||
content/browser/devtools/codemirror/xml-fold.js (sourceeditor/codemirror/fold/xml-fold.js)
|
||||
content/browser/devtools/codemirror/foldgutter.js (sourceeditor/codemirror/fold/foldgutter.js)
|
||||
content/browser/devtools/codemirror/tern.js (sourceeditor/codemirror/tern.js)
|
||||
content/browser/devtools/codemirror/show-hint.js (sourceeditor/codemirror/show-hint.js)
|
||||
content/browser/devtools/codemirror/tern.js (sourceeditor/codemirror/tern/tern.js)
|
||||
content/browser/devtools/codemirror/show-hint.js (sourceeditor/codemirror/hint/show-hint.js)
|
||||
content/browser/devtools/codemirror/mozilla.css (sourceeditor/codemirror/mozilla.css)
|
||||
content/browser/devtools/debugger.xul (debugger/debugger.xul)
|
||||
content/browser/devtools/debugger.css (debugger/debugger.css)
|
||||
|
|
|
@ -5,7 +5,7 @@ code, and optionally help with indentation.
|
|||
|
||||
# Upgrade
|
||||
|
||||
Currently used version is 4.0.3. To upgrade, download a new version of
|
||||
Currently used version is 4.2.0. To upgrade, download a new version of
|
||||
CodeMirror from the project's page [1] and replace all JavaScript and
|
||||
CSS files inside the codemirror directory [2].
|
||||
|
||||
|
@ -46,29 +46,36 @@ in the LICENSE file:
|
|||
|
||||
* codemirror.css
|
||||
* codemirror.js
|
||||
* comment.js
|
||||
* comment/comment.js
|
||||
* comment/continue-comment.js
|
||||
* activeline.js
|
||||
* dialog/dialog.css
|
||||
* dialog/dialog.js
|
||||
* keymap/emacs.js
|
||||
* keymap/sublime.js
|
||||
* keymap/vim.js
|
||||
* edit/closebrackets.js
|
||||
* edit/closetag.js
|
||||
* edit/continuelist.js
|
||||
* edit/matchbrackets.js
|
||||
* edit/matchtags.js
|
||||
* edit/trailingspace.js
|
||||
* fold/foldcode.js
|
||||
* fold/brace-fold.js
|
||||
* fold/comment-fold.js
|
||||
* fold/xml-fold.js
|
||||
* fold/foldgutter.js
|
||||
* xml.js
|
||||
* css.js
|
||||
* javascript.js
|
||||
* clike.js
|
||||
* htmlmixed.js
|
||||
* matchbrackets.js
|
||||
* closebrackets.js
|
||||
* trailingspace.js
|
||||
* hint/show-hint.js
|
||||
* keymap/emacs.js
|
||||
* keymap/sublime.js
|
||||
* keymap/vim.js
|
||||
* mode/xml.js
|
||||
* mode/css.js
|
||||
* mode/javascript.js
|
||||
* mode/clike.js
|
||||
* mode/htmlmixed.js
|
||||
* search/match-highlighter.js
|
||||
* search/search.js
|
||||
* search/searchcursor.js
|
||||
* tern/tern.js
|
||||
* tern/tern.css
|
||||
* test/codemirror.html
|
||||
* test/cm_comment_test.js
|
||||
* test/cm_doc_test.js
|
||||
|
|
|
@ -70,11 +70,12 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {}
|
|||
.cm-s-default .cm-atom {color: #219;}
|
||||
.cm-s-default .cm-number {color: #164;}
|
||||
.cm-s-default .cm-def {color: #00f;}
|
||||
.cm-s-default .cm-variable {color: black;}
|
||||
.cm-s-default .cm-variable,
|
||||
.cm-s-default .cm-punctuation,
|
||||
.cm-s-default .cm-property,
|
||||
.cm-s-default .cm-operator {}
|
||||
.cm-s-default .cm-variable-2 {color: #05a;}
|
||||
.cm-s-default .cm-variable-3 {color: #085;}
|
||||
.cm-s-default .cm-property {color: black;}
|
||||
.cm-s-default .cm-operator {color: black;}
|
||||
.cm-s-default .cm-comment {color: #a50;}
|
||||
.cm-s-default .cm-string {color: #a11;}
|
||||
.cm-s-default .cm-string-2 {color: #f50;}
|
||||
|
@ -250,6 +251,7 @@ div.CodeMirror-cursors {
|
|||
|
||||
.CodeMirror-selected { background: #d9d9d9; }
|
||||
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
||||
.CodeMirror-crosshair { cursor: crosshair; }
|
||||
|
||||
.cm-searching {
|
||||
background: #ffa;
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,3 +1,6 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
// Open simple dialogs on top of an editor. Relies on dialog.css.
|
||||
|
||||
(function(mod) {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
||||
|
@ -10,6 +13,8 @@
|
|||
var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
|
||||
var SPACE_CHAR_REGEX = /\s/;
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
|
||||
if (old != CodeMirror.Init && old)
|
||||
cm.removeKeyMap("autoCloseBrackets");
|
||||
|
@ -26,8 +31,8 @@
|
|||
});
|
||||
|
||||
function charsAround(cm, pos) {
|
||||
var str = cm.getRange(CodeMirror.Pos(pos.line, pos.ch - 1),
|
||||
CodeMirror.Pos(pos.line, pos.ch + 1));
|
||||
var str = cm.getRange(Pos(pos.line, pos.ch - 1),
|
||||
Pos(pos.line, pos.ch + 1));
|
||||
return str.length == 2 ? str : null;
|
||||
}
|
||||
|
||||
|
@ -44,7 +49,7 @@
|
|||
}
|
||||
for (var i = ranges.length - 1; i >= 0; i--) {
|
||||
var cur = ranges[i].head;
|
||||
cm.replaceRange("", CodeMirror.Pos(cur.line, cur.ch - 1), CodeMirror.Pos(cur.line, cur.ch + 1));
|
||||
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -58,11 +63,18 @@
|
|||
var range = ranges[i], cur = range.head, curType;
|
||||
if (left == "'" && cm.getTokenTypeAt(cur) == "comment")
|
||||
return CodeMirror.Pass;
|
||||
var next = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
|
||||
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
|
||||
if (!range.empty())
|
||||
curType = "surround";
|
||||
else if (left == right && next == right)
|
||||
curType = "skip";
|
||||
else if (left == right && next == right) {
|
||||
if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left)
|
||||
curType = "skipThree";
|
||||
else
|
||||
curType = "skip";
|
||||
} else if (left == right && cur.ch > 1 &&
|
||||
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left &&
|
||||
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left))
|
||||
curType = "addFour";
|
||||
else if (left == right && CodeMirror.isWordChar(next))
|
||||
return CodeMirror.Pass;
|
||||
else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next))
|
||||
|
@ -73,24 +85,32 @@
|
|||
else if (type != curType) return CodeMirror.Pass;
|
||||
}
|
||||
|
||||
if (type == "skip") {
|
||||
cm.execCommand("goCharRight");
|
||||
} else if (type == "surround") {
|
||||
var sels = cm.getSelections();
|
||||
for (var i = 0; i < sels.length; i++)
|
||||
sels[i] = left + sels[i] + right;
|
||||
cm.replaceSelections(sels, "around");
|
||||
} else if (type == "both") {
|
||||
cm.replaceSelection(left + right, null);
|
||||
cm.execCommand("goCharLeft");
|
||||
}
|
||||
cm.operation(function() {
|
||||
if (type == "skip") {
|
||||
cm.execCommand("goCharRight");
|
||||
} else if (type == "skipThree") {
|
||||
for (var i = 0; i < 3; i++)
|
||||
cm.execCommand("goCharRight");
|
||||
} else if (type == "surround") {
|
||||
var sels = cm.getSelections();
|
||||
for (var i = 0; i < sels.length; i++)
|
||||
sels[i] = left + sels[i] + right;
|
||||
cm.replaceSelections(sels, "around");
|
||||
} else if (type == "both") {
|
||||
cm.replaceSelection(left + right, null);
|
||||
cm.execCommand("goCharLeft");
|
||||
} else if (type == "addFour") {
|
||||
cm.replaceSelection(left + left + left + left, "before");
|
||||
cm.execCommand("goCharRight");
|
||||
}
|
||||
});
|
||||
};
|
||||
if (left != right) map["'" + right + "'"] = function(cm) {
|
||||
var ranges = cm.listSelections();
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
var range = ranges[i];
|
||||
if (!range.empty() ||
|
||||
cm.getRange(range.head, CodeMirror.Pos(range.head.line, range.head.ch + 1)) != right)
|
||||
cm.getRange(range.head, Pos(range.head.line, range.head.ch + 1)) != right)
|
||||
return CodeMirror.Pass;
|
||||
}
|
||||
cm.execCommand("goCharRight");
|
|
@ -0,0 +1,141 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
/**
|
||||
* Tag-closer extension for CodeMirror.
|
||||
*
|
||||
* This extension adds an "autoCloseTags" option that can be set to
|
||||
* either true to get the default behavior, or an object to further
|
||||
* configure its behavior.
|
||||
*
|
||||
* These are supported options:
|
||||
*
|
||||
* `whenClosing` (default true)
|
||||
* Whether to autoclose when the '/' of a closing tag is typed.
|
||||
* `whenOpening` (default true)
|
||||
* Whether to autoclose the tag when the final '>' of an opening
|
||||
* tag is typed.
|
||||
* `dontCloseTags` (default is empty tags for HTML, none for XML)
|
||||
* An array of tag names that should not be autoclosed.
|
||||
* `indentTags` (default is block tags for HTML, none for XML)
|
||||
* An array of tag names that should, when opened, cause a
|
||||
* blank line to be added inside the tag, and the blank line and
|
||||
* closing line to be indented.
|
||||
*
|
||||
* See demos/closetag.html for a usage example.
|
||||
*/
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
|
||||
if (old != CodeMirror.Init && old)
|
||||
cm.removeKeyMap("autoCloseTags");
|
||||
if (!val) return;
|
||||
var map = {name: "autoCloseTags"};
|
||||
if (typeof val != "object" || val.whenClosing)
|
||||
map["'/'"] = function(cm) { return autoCloseSlash(cm); };
|
||||
if (typeof val != "object" || val.whenOpening)
|
||||
map["'>'"] = function(cm) { return autoCloseGT(cm); };
|
||||
cm.addKeyMap(map);
|
||||
});
|
||||
|
||||
var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param",
|
||||
"source", "track", "wbr"];
|
||||
var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4",
|
||||
"h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
|
||||
|
||||
function autoCloseGT(cm) {
|
||||
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
||||
var ranges = cm.listSelections(), replacements = [];
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
if (!ranges[i].empty()) return CodeMirror.Pass;
|
||||
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
||||
if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
|
||||
|
||||
var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
|
||||
var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
|
||||
var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
|
||||
|
||||
var tagName = state.tagName;
|
||||
if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
|
||||
var lowerTagName = tagName.toLowerCase();
|
||||
// Don't process the '>' at the end of an end-tag or self-closing tag
|
||||
if (!tagName ||
|
||||
tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) ||
|
||||
tok.type == "tag" && state.type == "closeTag" ||
|
||||
tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
|
||||
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 ||
|
||||
closingTagExists(cm, tagName, pos, state, true))
|
||||
return CodeMirror.Pass;
|
||||
|
||||
var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
|
||||
replacements[i] = {indent: indent,
|
||||
text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">",
|
||||
newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1)};
|
||||
}
|
||||
|
||||
for (var i = ranges.length - 1; i >= 0; i--) {
|
||||
var info = replacements[i];
|
||||
cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert");
|
||||
var sel = cm.listSelections().slice(0);
|
||||
sel[i] = {head: info.newPos, anchor: info.newPos};
|
||||
cm.setSelections(sel);
|
||||
if (info.indent) {
|
||||
cm.indentLine(info.newPos.line, null, true);
|
||||
cm.indentLine(info.newPos.line + 1, null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function autoCloseSlash(cm) {
|
||||
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
||||
var ranges = cm.listSelections(), replacements = [];
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
if (!ranges[i].empty()) return CodeMirror.Pass;
|
||||
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
||||
if (tok.type == "string" || tok.string.charAt(0) != "<" ||
|
||||
tok.start != pos.ch - 1 || inner.mode.name != "xml" ||
|
||||
!state.context || !state.context.tagName ||
|
||||
closingTagExists(cm, state.context.tagName, pos, state))
|
||||
return CodeMirror.Pass;
|
||||
replacements[i] = "/" + state.context.tagName + ">";
|
||||
}
|
||||
cm.replaceSelections(replacements);
|
||||
}
|
||||
|
||||
function indexOf(collection, elt) {
|
||||
if (collection.indexOf) return collection.indexOf(elt);
|
||||
for (var i = 0, e = collection.length; i < e; ++i)
|
||||
if (collection[i] == elt) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// If xml-fold is loaded, we use its functionality to try and verify
|
||||
// whether a given tag is actually unclosed.
|
||||
function closingTagExists(cm, tagName, pos, state, newTag) {
|
||||
if (!CodeMirror.scanForClosingTag) return false;
|
||||
var end = Math.min(cm.lastLine() + 1, pos.line + 500);
|
||||
var nextClose = CodeMirror.scanForClosingTag(cm, pos, null, end);
|
||||
if (!nextClose || nextClose.tag != tagName) return false;
|
||||
var cx = state.context;
|
||||
// If the immediate wrapping context contains onCx instances of
|
||||
// the same tag, a closing tag only exists if there are at least
|
||||
// that many closing tags of that type following.
|
||||
for (var onCx = newTag ? 1 : 0; cx && cx.tagName == tagName; cx = cx.prev) ++onCx;
|
||||
pos = nextClose.to;
|
||||
for (var i = 1; i < onCx; i++) {
|
||||
var next = CodeMirror.scanForClosingTag(cm, pos, null, end);
|
||||
if (!next || next.tag != tagName) return false;
|
||||
pos = next.to;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// 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 listRE = /^(\s*)([*+-]|(\d+)\.)(\s*)/,
|
||||
unorderedBullets = "*+-";
|
||||
|
||||
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
|
||||
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
||||
var ranges = cm.listSelections(), replacements = [];
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
var pos = ranges[i].head, match;
|
||||
var inList = cm.getStateAfter(pos.line).list !== false;
|
||||
|
||||
if (!ranges[i].empty() || !inList || !(match = cm.getLine(pos.line).match(listRE))) {
|
||||
cm.execCommand("newlineAndIndent");
|
||||
return;
|
||||
}
|
||||
var indent = match[1], after = match[4];
|
||||
var bullet = unorderedBullets.indexOf(match[2]) >= 0
|
||||
? match[2]
|
||||
: (parseInt(match[3], 10) + 1) + ".";
|
||||
|
||||
replacements[i] = "\n" + indent + bullet + after;
|
||||
}
|
||||
|
||||
cm.replaceSelections(replacements);
|
||||
};
|
||||
});
|
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
||||
|
@ -22,15 +25,24 @@
|
|||
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
|
||||
|
||||
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
|
||||
if (found == null) return null;
|
||||
return {from: Pos(where.line, pos), to: found && found.pos,
|
||||
match: found && found.ch == match.charAt(0), forward: dir > 0};
|
||||
}
|
||||
|
||||
// bracketRegex is used to specify which type of bracket to scan
|
||||
// should be a regexp, e.g. /[[\]]/
|
||||
//
|
||||
// Note: If "where" is on an open bracket, then this bracket is ignored.
|
||||
//
|
||||
// Returns false when no bracket was found, null when it reached
|
||||
// maxScanLines and gave up
|
||||
function scanForBracket(cm, where, dir, style, config) {
|
||||
var maxScanLen = (config && config.maxScanLineLength) || 10000;
|
||||
var maxScanLines = (config && config.maxScanLines) || 500;
|
||||
var maxScanLines = (config && config.maxScanLines) || 1000;
|
||||
|
||||
var stack = [], re = /[(){}[\]]/;
|
||||
var stack = [];
|
||||
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
|
||||
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
|
||||
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
|
||||
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
|
||||
|
@ -49,6 +61,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
|
||||
}
|
||||
|
||||
function matchBrackets(cm, autoclear, config) {
|
||||
|
@ -57,11 +70,10 @@
|
|||
var marks = [], ranges = cm.listSelections();
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config);
|
||||
if (match && cm.getLine(match.from.line).length <= maxHighlightLen &&
|
||||
match.to && cm.getLine(match.to.line).length <= maxHighlightLen) {
|
||||
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
|
||||
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
|
||||
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
|
||||
if (match.to)
|
||||
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
|
||||
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
|
||||
}
|
||||
}
|
||||
|
@ -99,10 +111,10 @@
|
|||
});
|
||||
|
||||
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
|
||||
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict){
|
||||
return findMatchingBracket(this, pos, strict);
|
||||
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){
|
||||
return findMatchingBracket(this, pos, strict, config);
|
||||
});
|
||||
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style){
|
||||
return scanForBracket(this, pos, dir, style);
|
||||
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
|
||||
return scanForBracket(this, pos, dir, style, config);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,66 @@
|
|||
// 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"), require("../fold/xml-fold"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
|
||||
if (old && old != CodeMirror.Init) {
|
||||
cm.off("cursorActivity", doMatchTags);
|
||||
cm.off("viewportChange", maybeUpdateMatch);
|
||||
clear(cm);
|
||||
}
|
||||
if (val) {
|
||||
cm.state.matchBothTags = typeof val == "object" && val.bothTags;
|
||||
cm.on("cursorActivity", doMatchTags);
|
||||
cm.on("viewportChange", maybeUpdateMatch);
|
||||
doMatchTags(cm);
|
||||
}
|
||||
});
|
||||
|
||||
function clear(cm) {
|
||||
if (cm.state.tagHit) cm.state.tagHit.clear();
|
||||
if (cm.state.tagOther) cm.state.tagOther.clear();
|
||||
cm.state.tagHit = cm.state.tagOther = null;
|
||||
}
|
||||
|
||||
function doMatchTags(cm) {
|
||||
cm.state.failedTagMatch = false;
|
||||
cm.operation(function() {
|
||||
clear(cm);
|
||||
if (cm.somethingSelected()) return;
|
||||
var cur = cm.getCursor(), range = cm.getViewport();
|
||||
range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
|
||||
var match = CodeMirror.findMatchingTag(cm, cur, range);
|
||||
if (!match) return;
|
||||
if (cm.state.matchBothTags) {
|
||||
var hit = match.at == "open" ? match.open : match.close;
|
||||
if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, {className: "CodeMirror-matchingtag"});
|
||||
}
|
||||
var other = match.at == "close" ? match.open : match.close;
|
||||
if (other)
|
||||
cm.state.tagOther = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
|
||||
else
|
||||
cm.state.failedTagMatch = true;
|
||||
});
|
||||
}
|
||||
|
||||
function maybeUpdateMatch(cm) {
|
||||
if (cm.state.failedTagMatch) doMatchTags(cm);
|
||||
}
|
||||
|
||||
CodeMirror.commands.toMatchingTag = function(cm) {
|
||||
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
|
||||
if (found) {
|
||||
var other = found.at == "close" ? found.open : found.close;
|
||||
if (other) cm.extendSelection(other.to, other.from);
|
||||
}
|
||||
};
|
||||
});
|
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
|
@ -1,3 +1,16 @@
|
|||
// 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.registerHelper("fold", "brace", function(cm, start) {
|
||||
var line = start.line, lineText = cm.getLine(line);
|
||||
var startCh, tokenType;
|
||||
|
@ -45,7 +58,6 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
|
|||
return {from: CodeMirror.Pos(line, startCh),
|
||||
to: CodeMirror.Pos(end, endCh)};
|
||||
});
|
||||
CodeMirror.braceRangeFinder = CodeMirror.fold.brace; // deprecated
|
||||
|
||||
CodeMirror.registerHelper("fold", "import", function(cm, start) {
|
||||
function hasImport(line) {
|
||||
|
@ -70,7 +82,6 @@ CodeMirror.registerHelper("fold", "import", function(cm, start) {
|
|||
}
|
||||
return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
|
||||
});
|
||||
CodeMirror.importRangeFinder = CodeMirror.fold["import"]; // deprecated
|
||||
|
||||
CodeMirror.registerHelper("fold", "include", function(cm, start) {
|
||||
function hasInclude(line) {
|
||||
|
@ -90,4 +101,5 @@ CodeMirror.registerHelper("fold", "include", function(cm, start) {
|
|||
return {from: CodeMirror.Pos(start, has + 1),
|
||||
to: cm.clipPos(CodeMirror.Pos(end))};
|
||||
});
|
||||
CodeMirror.includeRangeFinder = CodeMirror.fold.include; // deprecated
|
||||
|
||||
});
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
// 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.registerGlobalHelper("fold", "comment", function(mode) {
|
||||
return mode.blockCommentStart && mode.blockCommentEnd;
|
||||
}, function(cm, start) {
|
||||
|
@ -40,3 +53,5 @@ CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
|
|||
return {from: CodeMirror.Pos(line, startCh),
|
||||
to: CodeMirror.Pos(end, endCh)};
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
(function() {
|
||||
// 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";
|
||||
|
||||
function doFold(cm, pos, options, force) {
|
||||
var finder = options && (options.call ? options : options.rangeFinder);
|
||||
if (!finder) finder = CodeMirror.fold.auto;
|
||||
if (options && options.call) {
|
||||
var finder = options;
|
||||
options = null;
|
||||
} else {
|
||||
var finder = getOption(cm, options, "rangeFinder");
|
||||
}
|
||||
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
|
||||
var minSize = options && options.minFoldSize || 0;
|
||||
var minSize = getOption(cm, options, "minFoldSize");
|
||||
|
||||
function getRange(allowFolded) {
|
||||
var range = finder(cm, pos);
|
||||
|
@ -22,14 +36,17 @@
|
|||
}
|
||||
|
||||
var range = getRange(true);
|
||||
if (options && options.scanUp) while (!range && pos.line > cm.firstLine()) {
|
||||
if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
|
||||
pos = CodeMirror.Pos(pos.line - 1, 0);
|
||||
range = getRange(false);
|
||||
}
|
||||
if (!range || range.cleared || force === "unfold") return;
|
||||
|
||||
var myWidget = makeWidget(options);
|
||||
CodeMirror.on(myWidget, "mousedown", function() { myRange.clear(); });
|
||||
var myWidget = makeWidget(cm, options);
|
||||
CodeMirror.on(myWidget, "mousedown", function(e) {
|
||||
myRange.clear();
|
||||
CodeMirror.e_preventDefault(e);
|
||||
});
|
||||
var myRange = cm.markText(range.from, range.to, {
|
||||
replacedWith: myWidget,
|
||||
clearOnEnter: true,
|
||||
|
@ -41,8 +58,8 @@
|
|||
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
|
||||
}
|
||||
|
||||
function makeWidget(options) {
|
||||
var widget = (options && options.widget) || "\u2194";
|
||||
function makeWidget(cm, options) {
|
||||
var widget = getOption(cm, options, "widget");
|
||||
if (typeof widget == "string") {
|
||||
var text = document.createTextNode(widget);
|
||||
widget = document.createElement("span");
|
||||
|
@ -62,9 +79,33 @@
|
|||
doFold(this, pos, options, force);
|
||||
});
|
||||
|
||||
CodeMirror.commands.fold = function(cm) {
|
||||
CodeMirror.defineExtension("isFolded", function(pos) {
|
||||
var marks = this.findMarksAt(pos);
|
||||
for (var i = 0; i < marks.length; ++i)
|
||||
if (marks[i].__isFold) return true;
|
||||
});
|
||||
|
||||
CodeMirror.commands.toggleFold = function(cm) {
|
||||
cm.foldCode(cm.getCursor());
|
||||
};
|
||||
CodeMirror.commands.fold = function(cm) {
|
||||
cm.foldCode(cm.getCursor(), null, "fold");
|
||||
};
|
||||
CodeMirror.commands.unfold = function(cm) {
|
||||
cm.foldCode(cm.getCursor(), null, "unfold");
|
||||
};
|
||||
CodeMirror.commands.foldAll = function(cm) {
|
||||
cm.operation(function() {
|
||||
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
|
||||
cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
|
||||
});
|
||||
};
|
||||
CodeMirror.commands.unfoldAll = function(cm) {
|
||||
cm.operation(function() {
|
||||
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
|
||||
cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
|
||||
});
|
||||
};
|
||||
|
||||
CodeMirror.registerHelper("fold", "combine", function() {
|
||||
var funcs = Array.prototype.slice.call(arguments, 0);
|
||||
|
@ -83,4 +124,22 @@
|
|||
if (cur) return cur;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
var defaultOptions = {
|
||||
rangeFinder: CodeMirror.fold.auto,
|
||||
widget: "\u2194",
|
||||
minFoldSize: 0,
|
||||
scanUp: false
|
||||
};
|
||||
|
||||
CodeMirror.defineOption("foldOptions", null);
|
||||
|
||||
function getOption(cm, options, name) {
|
||||
if (options && options[name] !== undefined)
|
||||
return options[name];
|
||||
var editorOptions = cm.options.foldOptions;
|
||||
if (editorOptions && editorOptions[name] !== undefined)
|
||||
return editorOptions[name];
|
||||
return defaultOptions[name];
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
.CodeMirror-foldmarker {
|
||||
color: blue;
|
||||
text-shadow: #b9f 1px 1px 2px, #b9f -1px -1px 2px, #b9f 1px -1px 2px, #b9f -1px 1px 2px;
|
||||
font-family: arial;
|
||||
line-height: .3;
|
||||
cursor: pointer;
|
||||
}
|
||||
.CodeMirror-foldgutter {
|
||||
width: .7em;
|
||||
}
|
||||
.CodeMirror-foldgutter-open,
|
||||
.CodeMirror-foldgutter-folded {
|
||||
color: #555;
|
||||
cursor: pointer;
|
||||
}
|
||||
.CodeMirror-foldgutter-open:after {
|
||||
content: "\25BE";
|
||||
}
|
||||
.CodeMirror-foldgutter-folded:after {
|
||||
content: "\25B8";
|
||||
}
|
|
@ -1,4 +1,14 @@
|
|||
(function() {
|
||||
// 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"), require("./foldcode"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror", "./foldcode"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineOption("foldGutter", false, function(cm, val, old) {
|
||||
|
@ -121,4 +131,4 @@
|
|||
if (line >= state.from && line < state.to)
|
||||
updateFoldInfo(cm, line, line + 1);
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
// 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.registerHelper("fold", "indent", function(cm, start) {
|
||||
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
|
||||
if (!/\S/.test(firstLine)) return;
|
||||
var getIndent = function(line) {
|
||||
return CodeMirror.countColumn(line, null, tabSize);
|
||||
};
|
||||
var myIndent = getIndent(firstLine);
|
||||
var lastLineInFold = null;
|
||||
// Go through lines until we find a line that definitely doesn't belong in
|
||||
// the block we're folding, or to the end.
|
||||
for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
|
||||
var curLine = cm.getLine(i);
|
||||
var curIndent = getIndent(curLine);
|
||||
if (curIndent > myIndent) {
|
||||
// Lines with a greater indent are considered part of the block.
|
||||
lastLineInFold = i;
|
||||
} else if (!/\S/.test(curLine)) {
|
||||
// Empty lines might be breaks within the block we're trying to fold.
|
||||
} else {
|
||||
// A non-empty line at an indent equal to or less than ours marks the
|
||||
// start of another block.
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastLineInFold) return {
|
||||
from: CodeMirror.Pos(start.line, firstLine.length),
|
||||
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
|
||||
};
|
||||
});
|
||||
|
||||
});
|
|
@ -0,0 +1,49 @@
|
|||
// 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.registerHelper("fold", "markdown", function(cm, start) {
|
||||
var maxDepth = 100;
|
||||
|
||||
function isHeader(lineNo) {
|
||||
var tokentype = cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0));
|
||||
return tokentype && /\bheader\b/.test(tokentype);
|
||||
}
|
||||
|
||||
function headerLevel(lineNo, line, nextLine) {
|
||||
var match = line && line.match(/^#+/);
|
||||
if (match && isHeader(lineNo)) return match[0].length;
|
||||
match = nextLine && nextLine.match(/^[=\-]+\s*$/);
|
||||
if (match && isHeader(lineNo + 1)) return nextLine[0] == "=" ? 1 : 2;
|
||||
return maxDepth;
|
||||
}
|
||||
|
||||
var firstLine = cm.getLine(start.line), nextLine = cm.getLine(start.line + 1);
|
||||
var level = headerLevel(start.line, firstLine, nextLine);
|
||||
if (level === maxDepth) return undefined;
|
||||
|
||||
var lastLineNo = cm.lastLine();
|
||||
var end = start.line, nextNextLine = cm.getLine(end + 2);
|
||||
while (end < lastLineNo) {
|
||||
if (headerLevel(end + 1, nextLine, nextNextLine) <= level) break;
|
||||
++end;
|
||||
nextLine = nextNextLine;
|
||||
nextNextLine = cm.getLine(end + 2);
|
||||
}
|
||||
|
||||
return {
|
||||
from: CodeMirror.Pos(start.line, firstLine.length),
|
||||
to: CodeMirror.Pos(end, cm.getLine(end).length)
|
||||
};
|
||||
});
|
||||
|
||||
});
|
|
@ -1,4 +1,14 @@
|
|||
(function() {
|
||||
// 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 Pos = CodeMirror.Pos;
|
||||
|
@ -136,8 +146,6 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
CodeMirror.tagRangeFinder = CodeMirror.fold.xml; // deprecated
|
||||
|
||||
CodeMirror.findMatchingTag = function(cm, pos, range) {
|
||||
var iter = new Iter(cm, pos.line, pos.ch, range);
|
||||
if (iter.text.indexOf(">") == -1 && iter.text.indexOf("<") == -1) return;
|
||||
|
@ -168,6 +176,6 @@
|
|||
// Used by addon/edit/closetag.js
|
||||
CodeMirror.scanForClosingTag = function(cm, pos, name, end) {
|
||||
var iter = new Iter(cm, pos.line, pos.ch, end ? {from: 0, to: end} : null);
|
||||
return !!findMatchingClose(iter, name);
|
||||
return findMatchingClose(iter, name);
|
||||
};
|
||||
})();
|
||||
});
|
||||
|
|
|
@ -1,31 +1,48 @@
|
|||
(function() {
|
||||
// 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 HINT_ELEMENT_CLASS = "CodeMirror-hint";
|
||||
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
|
||||
|
||||
// This is the old interface, kept around for now to stay
|
||||
// backwards-compatible.
|
||||
CodeMirror.showHint = function(cm, getHints, options) {
|
||||
// We want a single cursor position.
|
||||
if (cm.somethingSelected()) return;
|
||||
if (getHints == null) {
|
||||
if (options && options.async) return;
|
||||
else getHints = CodeMirror.hint.auto;
|
||||
}
|
||||
|
||||
if (cm.state.completionActive) cm.state.completionActive.close();
|
||||
|
||||
var completion = cm.state.completionActive = new Completion(cm, getHints, options || {});
|
||||
CodeMirror.signal(cm, "startCompletion", cm);
|
||||
if (completion.options.async)
|
||||
getHints(cm, function(hints) { completion.showHints(hints); }, completion.options);
|
||||
else
|
||||
return completion.showHints(getHints(cm, completion.options));
|
||||
if (!getHints) return cm.showHint(options);
|
||||
if (options && options.async) getHints.async = true;
|
||||
var newOpts = {hint: getHints};
|
||||
if (options) for (var prop in options) newOpts[prop] = options[prop];
|
||||
return cm.showHint(newOpts);
|
||||
};
|
||||
|
||||
function Completion(cm, getHints, options) {
|
||||
CodeMirror.defineExtension("showHint", function(options) {
|
||||
// We want a single cursor position.
|
||||
if (this.listSelections().length > 1 || this.somethingSelected()) return;
|
||||
|
||||
if (this.state.completionActive) this.state.completionActive.close();
|
||||
var completion = this.state.completionActive = new Completion(this, options);
|
||||
var getHints = completion.options.hint;
|
||||
if (!getHints) return;
|
||||
|
||||
CodeMirror.signal(this, "startCompletion", this);
|
||||
if (getHints.async)
|
||||
getHints(this, function(hints) { completion.showHints(hints); }, completion.options);
|
||||
else
|
||||
return completion.showHints(getHints(this, completion.options));
|
||||
});
|
||||
|
||||
function Completion(cm, options) {
|
||||
this.cm = cm;
|
||||
this.getHints = getHints;
|
||||
this.options = options;
|
||||
this.options = this.buildOptions(options);
|
||||
this.widget = this.onClose = null;
|
||||
}
|
||||
|
||||
|
@ -46,7 +63,8 @@
|
|||
pick: function(data, i) {
|
||||
var completion = data.list[i];
|
||||
if (completion.hint) completion.hint(this.cm, data, completion);
|
||||
else this.cm.replaceRange(getText(completion), data.from, data.to);
|
||||
else this.cm.replaceRange(getText(completion), completion.from || data.from,
|
||||
completion.to || data.to, "complete");
|
||||
CodeMirror.signal(data, "pick", completion);
|
||||
this.close();
|
||||
},
|
||||
|
@ -54,7 +72,7 @@
|
|||
showHints: function(data) {
|
||||
if (!data || !data.list.length || !this.active()) return this.close();
|
||||
|
||||
if (this.options.completeSingle != false && data.list.length == 1)
|
||||
if (this.options.completeSingle && data.list.length == 1)
|
||||
this.pick(data, 0);
|
||||
else
|
||||
this.showWidget(data);
|
||||
|
@ -65,7 +83,7 @@
|
|||
CodeMirror.signal(data, "shown");
|
||||
|
||||
var debounce = 0, completion = this, finished;
|
||||
var closeOn = this.options.closeCharacters || /[\s()\[\]{};:>,]/;
|
||||
var closeOn = this.options.closeCharacters;
|
||||
var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length;
|
||||
|
||||
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
|
||||
|
@ -84,15 +102,17 @@
|
|||
function update() {
|
||||
if (finished) return;
|
||||
CodeMirror.signal(data, "update");
|
||||
if (completion.options.async)
|
||||
completion.getHints(completion.cm, finishUpdate, completion.options);
|
||||
var getHints = completion.options.hint;
|
||||
if (getHints.async)
|
||||
getHints(completion.cm, finishUpdate, completion.options);
|
||||
else
|
||||
finishUpdate(completion.getHints(completion.cm, completion.options));
|
||||
finishUpdate(getHints(completion.cm, completion.options));
|
||||
}
|
||||
function finishUpdate(data_) {
|
||||
data = data_;
|
||||
if (finished) return;
|
||||
if (!data || !data.list.length) return done();
|
||||
if (completion.widget) completion.widget.close();
|
||||
completion.widget = new Widget(completion, data);
|
||||
}
|
||||
|
||||
|
@ -117,6 +137,17 @@
|
|||
}
|
||||
this.cm.on("cursorActivity", activity);
|
||||
this.onClose = done;
|
||||
},
|
||||
|
||||
buildOptions: function(options) {
|
||||
var editor = this.cm.options.hintOptions;
|
||||
var out = {};
|
||||
for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
|
||||
if (editor) for (var prop in editor)
|
||||
if (editor[prop] !== undefined) out[prop] = editor[prop];
|
||||
if (options) for (var prop in options)
|
||||
if (options[prop] !== undefined) out[prop] = options[prop];
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -125,7 +156,7 @@
|
|||
else return completion.text;
|
||||
}
|
||||
|
||||
function buildKeyMap(options, handle) {
|
||||
function buildKeyMap(completion, handle) {
|
||||
var baseMap = {
|
||||
Up: function() {handle.moveFocus(-1);},
|
||||
Down: function() {handle.moveFocus(1);},
|
||||
|
@ -137,7 +168,8 @@
|
|||
Tab: handle.pick,
|
||||
Esc: handle.close
|
||||
};
|
||||
var ourMap = options.customKeys ? {} : baseMap;
|
||||
var custom = completion.options.customKeys;
|
||||
var ourMap = custom ? {} : baseMap;
|
||||
function addBinding(key, val) {
|
||||
var bound;
|
||||
if (typeof val != "string")
|
||||
|
@ -149,12 +181,13 @@
|
|||
bound = val;
|
||||
ourMap[key] = bound;
|
||||
}
|
||||
if (options.customKeys)
|
||||
for (var key in options.customKeys) if (options.customKeys.hasOwnProperty(key))
|
||||
addBinding(key, options.customKeys[key]);
|
||||
if (options.extraKeys)
|
||||
for (var key in options.extraKeys) if (options.extraKeys.hasOwnProperty(key))
|
||||
addBinding(key, options.extraKeys[key]);
|
||||
if (custom)
|
||||
for (var key in custom) if (custom.hasOwnProperty(key))
|
||||
addBinding(key, custom[key]);
|
||||
var extra = completion.options.extraKeys;
|
||||
if (extra)
|
||||
for (var key in extra) if (extra.hasOwnProperty(key))
|
||||
addBinding(key, extra[key]);
|
||||
return ourMap;
|
||||
}
|
||||
|
||||
|
@ -168,11 +201,11 @@
|
|||
function Widget(completion, data) {
|
||||
this.completion = completion;
|
||||
this.data = data;
|
||||
var widget = this, cm = completion.cm, options = completion.options;
|
||||
var widget = this, cm = completion.cm;
|
||||
|
||||
var hints = this.hints = document.createElement("ul");
|
||||
hints.className = "CodeMirror-hints";
|
||||
this.selectedHint = options.getDefaultSelection ? options.getDefaultSelection(cm,options,data) : 0;
|
||||
this.selectedHint = data.selectedHint || 0;
|
||||
|
||||
var completions = data.list;
|
||||
for (var i = 0; i < completions.length; ++i) {
|
||||
|
@ -185,14 +218,14 @@
|
|||
elt.hintId = i;
|
||||
}
|
||||
|
||||
var pos = cm.cursorCoords(options.alignWithWord !== false ? data.from : null);
|
||||
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
|
||||
var left = pos.left, top = pos.bottom, below = true;
|
||||
hints.style.left = left + "px";
|
||||
hints.style.top = top + "px";
|
||||
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
|
||||
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
|
||||
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
|
||||
(options.container || document.body).appendChild(hints);
|
||||
(completion.options.container || document.body).appendChild(hints);
|
||||
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
|
||||
if (overlapY > 0) {
|
||||
var height = box.bottom - box.top, curTop = box.top - (pos.bottom - pos.top);
|
||||
|
@ -219,7 +252,7 @@
|
|||
hints.style.left = (left = pos.left - overlapX) + "px";
|
||||
}
|
||||
|
||||
cm.addKeyMap(this.keyMap = buildKeyMap(options, {
|
||||
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
|
||||
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
|
||||
setFocus: function(n) { widget.changeActive(n); },
|
||||
menuSize: function() { return widget.screenAmount(); },
|
||||
|
@ -229,7 +262,7 @@
|
|||
data: data
|
||||
}));
|
||||
|
||||
if (options.closeOnUnfocus !== false) {
|
||||
if (completion.options.closeOnUnfocus) {
|
||||
var closingOnBlur;
|
||||
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
|
||||
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
|
||||
|
@ -255,7 +288,7 @@
|
|||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) {
|
||||
widget.changeActive(t.hintId);
|
||||
if (options.completeOnSingleClick) widget.pick();
|
||||
if (completion.options.completeOnSingleClick) widget.pick();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -275,7 +308,7 @@
|
|||
this.completion.cm.removeKeyMap(this.keyMap);
|
||||
|
||||
var cm = this.completion.cm;
|
||||
if (this.completion.options.closeOnUnfocus !== false) {
|
||||
if (this.completion.options.closeOnUnfocus) {
|
||||
cm.off("blur", this.onBlur);
|
||||
cm.off("focus", this.onFocus);
|
||||
}
|
||||
|
@ -309,15 +342,16 @@
|
|||
};
|
||||
|
||||
CodeMirror.registerHelper("hint", "auto", function(cm, options) {
|
||||
var helpers = cm.getHelpers(cm.getCursor(), "hint");
|
||||
var helpers = cm.getHelpers(cm.getCursor(), "hint"), words;
|
||||
if (helpers.length) {
|
||||
for (var i = 0; i < helpers.length; i++) {
|
||||
var cur = helpers[i](cm, options);
|
||||
if (cur && cur.list.length) return cur;
|
||||
}
|
||||
} else {
|
||||
var words = cm.getHelper(cm.getCursor(), "hintWords");
|
||||
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
|
||||
if (words) return CodeMirror.hint.fromList(cm, {words: words});
|
||||
} else if (CodeMirror.hint.anyword) {
|
||||
return CodeMirror.hint.anyword(cm, options);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -338,4 +372,18 @@
|
|||
});
|
||||
|
||||
CodeMirror.commands.autocomplete = CodeMirror.showHint;
|
||||
})();
|
||||
|
||||
var defaultOptions = {
|
||||
hint: CodeMirror.hint.auto,
|
||||
completeSingle: true,
|
||||
alignWithWord: true,
|
||||
closeCharacters: /[\s()\[\]{};:>,]/,
|
||||
closeOnUnfocus: true,
|
||||
completeOnSingleClick: false,
|
||||
container: null,
|
||||
customKeys: null,
|
||||
extraKeys: null
|
||||
};
|
||||
|
||||
CodeMirror.defineOption("hintOptions", null);
|
||||
});
|
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
||||
|
@ -324,13 +327,7 @@
|
|||
},
|
||||
"Ctrl-O": repeated(function(cm) { cm.replaceSelection("\n", "start"); }),
|
||||
"Ctrl-T": repeated(function(cm) {
|
||||
var pos = cm.getCursor();
|
||||
if (pos.ch < cm.getLine(pos.line).length) pos = Pos(pos.line, pos.ch + 1);
|
||||
var from = cm.findPosH(pos, -2, "char");
|
||||
var range = cm.getRange(from, pos);
|
||||
if (range.length != 2) return;
|
||||
cm.setSelection(from, pos);
|
||||
cm.replaceSelection(range.charAt(1) + range.charAt(0), null, "+transpose");
|
||||
cm.execCommand("transposeChars");
|
||||
}),
|
||||
|
||||
"Alt-C": repeated(function(cm) {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
// A rough approximation of Sublime Text's keybindings
|
||||
// Depends on addon/search/searchcursor.js and optionally addon/dialog/dialogs.js
|
||||
|
||||
|
@ -52,10 +55,22 @@
|
|||
cmds[map["Alt-Right"] = "goSubwordRight"] = function(cm) { moveSubword(cm, 1); };
|
||||
|
||||
cmds[map[ctrl + "Up"] = "scrollLineUp"] = function(cm) {
|
||||
cm.scrollTo(null, cm.getScrollInfo().top - cm.defaultTextHeight());
|
||||
var info = cm.getScrollInfo();
|
||||
if (!cm.somethingSelected()) {
|
||||
var visibleBottomLine = cm.lineAtHeight(info.top + info.clientHeight, "local");
|
||||
if (cm.getCursor().line >= visibleBottomLine)
|
||||
cm.execCommand("goLineUp");
|
||||
}
|
||||
cm.scrollTo(null, info.top - cm.defaultTextHeight());
|
||||
};
|
||||
cmds[map[ctrl + "Down"] = "scrollLineDown"] = function(cm) {
|
||||
cm.scrollTo(null, cm.getScrollInfo().top + cm.defaultTextHeight());
|
||||
var info = cm.getScrollInfo();
|
||||
if (!cm.somethingSelected()) {
|
||||
var visibleTopLine = cm.lineAtHeight(info.top, "local")+1;
|
||||
if (cm.getCursor().line <= visibleTopLine)
|
||||
cm.execCommand("goLineDown");
|
||||
}
|
||||
cm.scrollTo(null, info.top + cm.defaultTextHeight());
|
||||
};
|
||||
|
||||
cmds[map["Shift-" + ctrl + "L"] = "splitSelectionByLine"] = function(cm) {
|
||||
|
@ -172,9 +187,12 @@
|
|||
};
|
||||
|
||||
cmds[map["Shift-" + ctrl + "Up"] = "swapLineUp"] = function(cm) {
|
||||
var ranges = cm.listSelections(), linesToMove = [], at = cm.firstLine() - 1;
|
||||
var ranges = cm.listSelections(), linesToMove = [], at = cm.firstLine() - 1, newSels = [];
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
var range = ranges[i], from = range.from().line - 1, to = range.to().line;
|
||||
newSels.push({anchor: Pos(range.anchor.line - 1, range.anchor.ch),
|
||||
head: Pos(range.head.line - 1, range.head.ch)});
|
||||
if (range.to().ch == 0 && !range.empty()) --to;
|
||||
if (from > at) linesToMove.push(from, to);
|
||||
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
|
||||
at = to;
|
||||
|
@ -184,16 +202,12 @@
|
|||
var from = linesToMove[i], to = linesToMove[i + 1];
|
||||
var line = cm.getLine(from);
|
||||
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
|
||||
if (to > cm.lastLine()) {
|
||||
if (to > cm.lastLine())
|
||||
cm.replaceRange("\n" + line, Pos(cm.lastLine()), null, "+swapLine");
|
||||
var sels = cm.listSelections(), last = sels[sels.length - 1];
|
||||
var head = last.head.line == to ? Pos(to - 1) : last.head;
|
||||
var anchor = last.anchor.line == to ? Pos(to - 1) : last.anchor;
|
||||
cm.setSelections(sels.slice(0, sels.length - 1).concat([{head: head, anchor: anchor}]));
|
||||
} else {
|
||||
else
|
||||
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
|
||||
}
|
||||
}
|
||||
cm.setSelections(newSels);
|
||||
cm.scrollIntoView();
|
||||
});
|
||||
};
|
||||
|
@ -202,6 +216,7 @@
|
|||
var ranges = cm.listSelections(), linesToMove = [], at = cm.lastLine() + 1;
|
||||
for (var i = ranges.length - 1; i >= 0; i--) {
|
||||
var range = ranges[i], from = range.to().line + 1, to = range.from().line;
|
||||
if (range.to().ch == 0 && !range.empty()) from--;
|
||||
if (from < at) linesToMove.push(from, to);
|
||||
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
|
||||
at = to;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
/**
|
||||
* Supported keybindings:
|
||||
*
|
||||
|
@ -58,9 +61,9 @@
|
|||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/dialog/dialog"));
|
||||
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/dialog/dialog"), require("../addon/edit/matchbrackets.js"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/dialog/dialog"], mod);
|
||||
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/dialog/dialog", "../addon/edit/matchbrackets"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
|
@ -201,13 +204,18 @@
|
|||
{ keys: [','], type: 'motion', motion: 'repeatLastCharacterSearch',
|
||||
motionArgs: { forward: false }},
|
||||
{ keys: ['\'', 'character'], type: 'motion', motion: 'goToMark',
|
||||
motionArgs: {toJumplist: true}},
|
||||
motionArgs: {toJumplist: true, linewise: true}},
|
||||
{ keys: ['`', 'character'], type: 'motion', motion: 'goToMark',
|
||||
motionArgs: {toJumplist: true}},
|
||||
{ keys: [']', '`'], type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true } },
|
||||
{ keys: ['[', '`'], type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false } },
|
||||
{ keys: [']', '\''], type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true, linewise: true } },
|
||||
{ keys: ['[', '\''], type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false, linewise: true } },
|
||||
// the next two aren't motions but must come before more general motion declarations
|
||||
{ keys: [']', 'p'], type: 'action', action: 'paste', isEdit: true,
|
||||
actionArgs: { after: true, isEdit: true, matchIndent: true}},
|
||||
{ keys: ['[', 'p'], type: 'action', action: 'paste', isEdit: true,
|
||||
actionArgs: { after: false, isEdit: true, matchIndent: true}},
|
||||
{ keys: [']', 'character'], type: 'motion',
|
||||
motion: 'moveToSymbol',
|
||||
motionArgs: { forward: true, toJumplist: true}},
|
||||
|
@ -266,6 +274,7 @@
|
|||
actionArgs: { insertAt: 'charAfter' }},
|
||||
{ keys: ['A'], type: 'action', action: 'enterInsertMode', isEdit: true,
|
||||
actionArgs: { insertAt: 'eol' }},
|
||||
{ keys: ['A'], type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'endOfSelectedArea' }, context: 'visual' },
|
||||
{ keys: ['i'], type: 'action', action: 'enterInsertMode', isEdit: true,
|
||||
actionArgs: { insertAt: 'inplace' }},
|
||||
{ keys: ['I'], type: 'action', action: 'enterInsertMode', isEdit: true,
|
||||
|
@ -292,6 +301,8 @@
|
|||
{ keys: ['R'], type: 'action', action: 'enterInsertMode', isEdit: true,
|
||||
actionArgs: { replace: true }},
|
||||
{ keys: ['u'], type: 'action', action: 'undo' },
|
||||
{ keys: ['u'], type: 'action', action: 'changeCase', actionArgs: {toLower: true}, context: 'visual', isEdit: true },
|
||||
{ keys: ['U'],type: 'action', action: 'changeCase', actionArgs: {toLower: false}, context: 'visual', isEdit: true },
|
||||
{ keys: ['<C-r>'], type: 'action', action: 'redo' },
|
||||
{ keys: ['m', 'character'], type: 'action', action: 'setMark' },
|
||||
{ keys: ['"', 'character'], type: 'action', action: 'setRegister' },
|
||||
|
@ -329,9 +340,11 @@
|
|||
{ keys: ['?'], type: 'search',
|
||||
searchArgs: { forward: false, querySrc: 'prompt', toJumplist: true }},
|
||||
{ keys: ['*'], type: 'search',
|
||||
searchArgs: { forward: true, querySrc: 'wordUnderCursor', toJumplist: true }},
|
||||
searchArgs: { forward: true, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
|
||||
{ keys: ['#'], type: 'search',
|
||||
searchArgs: { forward: false, querySrc: 'wordUnderCursor', toJumplist: true }},
|
||||
searchArgs: { forward: false, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
|
||||
{ keys: ['g', '*'], type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', toJumplist: true }},
|
||||
{ keys: ['g', '#'], type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', toJumplist: true }},
|
||||
// Ex command
|
||||
{ keys: [':'], type: 'ex' }
|
||||
];
|
||||
|
@ -345,12 +358,14 @@
|
|||
cm.setOption('disableInput', true);
|
||||
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
|
||||
cm.on('beforeSelectionChange', beforeSelectionChange);
|
||||
cm.on('cursorActivity', onCursorActivity);
|
||||
maybeInitVimState(cm);
|
||||
CodeMirror.on(cm.getInputField(), 'paste', getOnPasteFn(cm));
|
||||
} else if (cm.state.vim) {
|
||||
cm.setOption('keyMap', 'default');
|
||||
cm.setOption('disableInput', false);
|
||||
cm.off('beforeSelectionChange', beforeSelectionChange);
|
||||
cm.off('cursorActivity', onCursorActivity);
|
||||
CodeMirror.off(cm.getInputField(), 'paste', getOnPasteFn(cm));
|
||||
cm.state.vim = null;
|
||||
}
|
||||
|
@ -396,7 +411,7 @@
|
|||
var specialKeys = ['Left', 'Right', 'Up', 'Down', 'Space', 'Backspace',
|
||||
'Esc', 'Home', 'End', 'PageUp', 'PageDown', 'Enter'];
|
||||
var validMarks = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['<', '>']);
|
||||
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"']);
|
||||
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"', '.', ':']);
|
||||
|
||||
function isLine(cm, line) {
|
||||
return line >= cm.firstLine() && line <= cm.lastLine();
|
||||
|
@ -549,6 +564,7 @@
|
|||
this.latestRegister = undefined;
|
||||
this.isPlaying = false;
|
||||
this.isRecording = false;
|
||||
this.replaySearchQueries = [];
|
||||
this.onRecordingDone = undefined;
|
||||
this.lastInsertModeChanges = createInsertModeChanges();
|
||||
}
|
||||
|
@ -614,6 +630,8 @@
|
|||
searchQuery: null,
|
||||
// Whether we are searching backwards.
|
||||
searchIsReversed: false,
|
||||
// Replace part of the last substituted pattern
|
||||
lastSubstituteReplacePart: undefined,
|
||||
jumpList: createCircularJumpList(),
|
||||
macroModeState: new MacroModeState,
|
||||
// Recording latest f, t, F or T motion command.
|
||||
|
@ -670,13 +688,13 @@
|
|||
if (macroModeState.isRecording) {
|
||||
if (key == 'q') {
|
||||
macroModeState.exitMacroRecordMode();
|
||||
vim.inputState = new InputState();
|
||||
clearInputState(cm);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (key == '<Esc>') {
|
||||
// Clear input state and get back to normal mode.
|
||||
vim.inputState = new InputState();
|
||||
clearInputState(cm);
|
||||
if (vim.visualMode) {
|
||||
exitVisualMode(cm);
|
||||
}
|
||||
|
@ -754,6 +772,11 @@
|
|||
return repeat;
|
||||
};
|
||||
|
||||
function clearInputState(cm, reason) {
|
||||
cm.state.vim.inputState = new InputState();
|
||||
CodeMirror.signal(cm, 'vim-command-done', reason);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register stores information about copy and paste registers. Besides
|
||||
* text, a register must store whether it is linewise (i.e., when it is
|
||||
|
@ -764,6 +787,7 @@
|
|||
this.clear();
|
||||
this.keyBuffer = [text || ''];
|
||||
this.insertModeChanges = [];
|
||||
this.searchQueries = [];
|
||||
this.linewise = !!linewise;
|
||||
}
|
||||
Register.prototype = {
|
||||
|
@ -773,8 +797,10 @@
|
|||
},
|
||||
pushText: function(text, linewise) {
|
||||
// if this register has ever been set to linewise, use linewise.
|
||||
if (linewise || this.linewise) {
|
||||
this.keyBuffer.push('\n');
|
||||
if (linewise) {
|
||||
if (!this.linewise) {
|
||||
this.keyBuffer.push('\n');
|
||||
}
|
||||
this.linewise = true;
|
||||
}
|
||||
this.keyBuffer.push(text);
|
||||
|
@ -782,9 +808,13 @@
|
|||
pushInsertModeChanges: function(changes) {
|
||||
this.insertModeChanges.push(createInsertModeChanges(changes));
|
||||
},
|
||||
pushSearchQuery: function(query) {
|
||||
this.searchQueries.push(query);
|
||||
},
|
||||
clear: function() {
|
||||
this.keyBuffer = [];
|
||||
this.insertModeChanges = [];
|
||||
this.searchQueries = [];
|
||||
this.linewise = false;
|
||||
},
|
||||
toString: function() {
|
||||
|
@ -803,6 +833,8 @@
|
|||
function RegisterController(registers) {
|
||||
this.registers = registers;
|
||||
this.unnamedRegister = registers['"'] = new Register();
|
||||
registers['.'] = new Register();
|
||||
registers[':'] = new Register();
|
||||
}
|
||||
RegisterController.prototype = {
|
||||
pushText: function(registerName, operator, text, linewise) {
|
||||
|
@ -845,14 +877,13 @@
|
|||
// If we've gotten to this point, we've actually specified a register
|
||||
var append = isUpperCase(registerName);
|
||||
if (append) {
|
||||
register.append(text, linewise);
|
||||
// The unnamed register always has the same value as the last used
|
||||
// register.
|
||||
this.unnamedRegister.append(text, linewise);
|
||||
register.pushText(text, linewise);
|
||||
} else {
|
||||
register.setText(text, linewise);
|
||||
this.unnamedRegister.setText(text, linewise);
|
||||
}
|
||||
// The unnamed register always has the same value as the last used
|
||||
// register.
|
||||
this.unnamedRegister.setText(register.toString(), linewise);
|
||||
},
|
||||
// Gets the register named @name. If one of @name doesn't already exist,
|
||||
// create it. If @name is invalid, return the unnamedRegister.
|
||||
|
@ -998,7 +1029,7 @@
|
|||
return;
|
||||
} else {
|
||||
// 2 different operators in a row doesn't make sense.
|
||||
vim.inputState = new InputState();
|
||||
clearInputState(cm);
|
||||
}
|
||||
}
|
||||
inputState.operator = command.operator;
|
||||
|
@ -1043,7 +1074,7 @@
|
|||
actionArgs.repeat = repeat || 1;
|
||||
actionArgs.repeatIsExplicit = repeatIsExplicit;
|
||||
actionArgs.registerName = inputState.registerName;
|
||||
vim.inputState = new InputState();
|
||||
clearInputState(cm);
|
||||
vim.lastMotion = null;
|
||||
if (command.isEdit) {
|
||||
this.recordLastEdit(vim, inputState, command);
|
||||
|
@ -1056,6 +1087,7 @@
|
|||
return;
|
||||
}
|
||||
var forward = command.searchArgs.forward;
|
||||
var wholeWordOnly = command.searchArgs.wholeWordOnly;
|
||||
getSearchState(cm).setReversed(!forward);
|
||||
var promptPrefix = (forward) ? '/' : '?';
|
||||
var originalQuery = getSearchState(cm).getQuery();
|
||||
|
@ -1076,6 +1108,10 @@
|
|||
function onPromptClose(query) {
|
||||
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
|
||||
handleQuery(query, true /** ignoreCase */, true /** smartCase */);
|
||||
var macroModeState = vimGlobalState.macroModeState;
|
||||
if (macroModeState.isRecording) {
|
||||
logSearchQuery(macroModeState, query);
|
||||
}
|
||||
}
|
||||
function onPromptKeyUp(_e, query) {
|
||||
var parsedQuery;
|
||||
|
@ -1106,13 +1142,19 @@
|
|||
}
|
||||
switch (command.searchArgs.querySrc) {
|
||||
case 'prompt':
|
||||
showPrompt(cm, {
|
||||
onClose: onPromptClose,
|
||||
prefix: promptPrefix,
|
||||
desc: searchPromptDesc,
|
||||
onKeyUp: onPromptKeyUp,
|
||||
onKeyDown: onPromptKeyDown
|
||||
});
|
||||
var macroModeState = vimGlobalState.macroModeState;
|
||||
if (macroModeState.isPlaying) {
|
||||
var query = macroModeState.replaySearchQueries.shift();
|
||||
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
|
||||
} else {
|
||||
showPrompt(cm, {
|
||||
onClose: onPromptClose,
|
||||
prefix: promptPrefix,
|
||||
desc: searchPromptDesc,
|
||||
onKeyUp: onPromptKeyUp,
|
||||
onKeyDown: onPromptKeyDown
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'wordUnderCursor':
|
||||
var word = expandWordUnderCursor(cm, false /** inclusive */,
|
||||
|
@ -1130,8 +1172,8 @@
|
|||
}
|
||||
var query = cm.getLine(word.start.line).substring(word.start.ch,
|
||||
word.end.ch);
|
||||
if (isKeyword) {
|
||||
query = '\\b' + query + '\\b';
|
||||
if (isKeyword && wholeWordOnly) {
|
||||
query = '\\b' + query + '\\b';
|
||||
} else {
|
||||
query = escapeRegex(query);
|
||||
}
|
||||
|
@ -1213,7 +1255,7 @@
|
|||
inputState.selectedCharacter;
|
||||
}
|
||||
motionArgs.repeat = repeat;
|
||||
vim.inputState = new InputState();
|
||||
clearInputState(cm);
|
||||
if (motion) {
|
||||
var motionResult = motions[motion](cm, motionArgs, vim);
|
||||
vim.lastMotion = motions[motion];
|
||||
|
@ -1295,19 +1337,34 @@
|
|||
motionArgs.inclusive = true;
|
||||
}
|
||||
// Swap start and end if motion was backward.
|
||||
if (cursorIsBefore(curEnd, curStart)) {
|
||||
if (curEnd && cursorIsBefore(curEnd, curStart)) {
|
||||
var tmp = curStart;
|
||||
curStart = curEnd;
|
||||
curEnd = tmp;
|
||||
inverted = true;
|
||||
} else if (!curEnd) {
|
||||
curEnd = copyCursor(curStart);
|
||||
}
|
||||
if (motionArgs.inclusive && !(vim.visualMode && inverted)) {
|
||||
// Move the selection end one to the right to include the last
|
||||
// character.
|
||||
curEnd.ch++;
|
||||
}
|
||||
if (operatorArgs.selOffset) {
|
||||
// Replaying a visual mode operation
|
||||
curEnd.line = curStart.line + operatorArgs.selOffset.line;
|
||||
if (operatorArgs.selOffset.line) {curEnd.ch = operatorArgs.selOffset.ch; }
|
||||
else { curEnd.ch = curStart.ch + operatorArgs.selOffset.ch; }
|
||||
} else if (vim.visualMode) {
|
||||
var selOffset = Pos();
|
||||
selOffset.line = curEnd.line - curStart.line;
|
||||
if (selOffset.line) { selOffset.ch = curEnd.ch; }
|
||||
else { selOffset.ch = curEnd.ch - curStart.ch; }
|
||||
operatorArgs.selOffset = selOffset;
|
||||
}
|
||||
var linewise = motionArgs.linewise ||
|
||||
(vim.visualMode && vim.visualLine);
|
||||
(vim.visualMode && vim.visualLine) ||
|
||||
operatorArgs.linewise;
|
||||
if (linewise) {
|
||||
// Expand selection to entire line.
|
||||
expandSelectionToLine(cm, curStart, curEnd);
|
||||
|
@ -1372,10 +1429,11 @@
|
|||
highlightSearchMatches(cm, query);
|
||||
return findNext(cm, prev/** prev */, query, motionArgs.repeat);
|
||||
},
|
||||
goToMark: function(_cm, motionArgs, vim) {
|
||||
goToMark: function(cm, motionArgs, vim) {
|
||||
var mark = vim.marks[motionArgs.selectedCharacter];
|
||||
if (mark) {
|
||||
return mark.find();
|
||||
var pos = mark.find();
|
||||
return motionArgs.linewise ? { line: pos.line, ch: findFirstNonWhiteSpaceCharacter(cm.getLine(pos.line)) } : pos;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
@ -1503,10 +1561,7 @@
|
|||
// will move the cursor to where it should be in the end.
|
||||
var curStart = cm.getCursor();
|
||||
var repeat = motionArgs.repeat;
|
||||
cm.moveV((motionArgs.forward ? repeat : -repeat), 'page');
|
||||
var curEnd = cm.getCursor();
|
||||
cm.setCursor(curStart);
|
||||
return curEnd;
|
||||
return cm.findPosV(curStart, (motionArgs.forward ? repeat : -repeat), 'page');
|
||||
},
|
||||
moveByParagraph: function(cm, motionArgs) {
|
||||
var line = cm.getCursor().line;
|
||||
|
@ -1595,20 +1650,18 @@
|
|||
var ch = cursor.ch;
|
||||
var lineText = cm.getLine(line);
|
||||
var symbol;
|
||||
var startContext = cm.getTokenAt(cursor).type;
|
||||
var startCtxLevel = getContextLevel(startContext);
|
||||
do {
|
||||
symbol = lineText.charAt(ch++);
|
||||
if (symbol && isMatchableSymbol(symbol)) {
|
||||
var endContext = cm.getTokenAt(Pos(line, ch)).type;
|
||||
var endCtxLevel = getContextLevel(endContext);
|
||||
if (startCtxLevel >= endCtxLevel) {
|
||||
var style = cm.getTokenTypeAt(Pos(line, ch));
|
||||
if (style !== "string" && style !== "comment") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (symbol);
|
||||
if (symbol) {
|
||||
return findMatchedSymbol(cm, Pos(line, ch-1), symbol);
|
||||
var matched = cm.findMatchingBracket(Pos(line, ch));
|
||||
return matched.to;
|
||||
} else {
|
||||
return cursor;
|
||||
}
|
||||
|
@ -1637,6 +1690,13 @@
|
|||
var selfPaired = {'\'': true, '"': true};
|
||||
|
||||
var character = motionArgs.selectedCharacter;
|
||||
// 'b' refers to '()' block.
|
||||
// 'B' refers to '{}' block.
|
||||
if (character == 'b') {
|
||||
character = '(';
|
||||
} else if (character == 'B') {
|
||||
character = '{';
|
||||
}
|
||||
|
||||
// Inclusive is the difference between a and i
|
||||
// TODO: Instead of using the additional text object map to perform text
|
||||
|
@ -1647,7 +1707,7 @@
|
|||
|
||||
var tmp;
|
||||
if (mirroredPairs[character]) {
|
||||
tmp = selectCompanionObject(cm, mirroredPairs[character], inclusive);
|
||||
tmp = selectCompanionObject(cm, character, inclusive);
|
||||
} else if (selfPaired[character]) {
|
||||
tmp = findBeginningAndEnd(cm, character, inclusive);
|
||||
} else if (character === 'W') {
|
||||
|
@ -1863,6 +1923,12 @@
|
|||
cm.setCursor(offsetCursor(cm.getCursor(), 0, 1));
|
||||
} else if (insertAt == 'firstNonBlank') {
|
||||
cm.setCursor(motions.moveToFirstNonWhiteSpaceCharacter(cm));
|
||||
} else if (insertAt == 'endOfSelectedArea') {
|
||||
var selectionEnd = cm.getCursor('head');
|
||||
var selectionStart = cm.getCursor('anchor');
|
||||
selectionEnd = cursorIsBefore(selectionStart, selectionEnd) ? Pos(selectionEnd.line, selectionEnd.ch+1) : (selectionEnd.line < selectionStart.line ? Pos(selectionStart.line, 0) : selectionEnd);
|
||||
cm.setCursor(selectionEnd);
|
||||
exitVisualMode(cm);
|
||||
}
|
||||
cm.setOption('keyMap', 'vim-insert');
|
||||
cm.setOption('disableInput', false);
|
||||
|
@ -1878,7 +1944,6 @@
|
|||
if (!vimGlobalState.macroModeState.isPlaying) {
|
||||
// Only record if not replaying.
|
||||
cm.on('change', onChange);
|
||||
cm.on('cursorActivity', onCursorActivity);
|
||||
CodeMirror.on(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
|
||||
}
|
||||
},
|
||||
|
@ -2001,7 +2066,7 @@
|
|||
}
|
||||
this.enterInsertMode(cm, { repeat: actionArgs.repeat }, vim);
|
||||
},
|
||||
paste: function(cm, actionArgs) {
|
||||
paste: function(cm, actionArgs, vim) {
|
||||
var cur = copyCursor(cm.getCursor());
|
||||
var register = vimGlobalState.registerController.getRegister(
|
||||
actionArgs.registerName);
|
||||
|
@ -2009,12 +2074,42 @@
|
|||
if (!text) {
|
||||
return;
|
||||
}
|
||||
if (actionArgs.matchIndent) {
|
||||
// length that considers tabs and cm.options.tabSize
|
||||
var whitespaceLength = function(str) {
|
||||
var tabs = (str.split("\t").length - 1);
|
||||
var spaces = (str.split(" ").length - 1);
|
||||
return tabs * cm.options.tabSize + spaces * 1;
|
||||
};
|
||||
var currentLine = cm.getLine(cm.getCursor().line);
|
||||
var indent = whitespaceLength(currentLine.match(/^\s*/)[0]);
|
||||
// chomp last newline b/c don't want it to match /^\s*/gm
|
||||
var chompedText = text.replace(/\n$/, '');
|
||||
var wasChomped = text !== chompedText;
|
||||
var firstIndent = whitespaceLength(text.match(/^\s*/)[0]);
|
||||
var text = chompedText.replace(/^\s*/gm, function(wspace) {
|
||||
var newIndent = indent + (whitespaceLength(wspace) - firstIndent);
|
||||
if (newIndent < 0) {
|
||||
return "";
|
||||
}
|
||||
else if (cm.options.indentWithTabs) {
|
||||
var quotient = Math.floor(newIndent / cm.options.tabSize);
|
||||
return Array(quotient + 1).join('\t');
|
||||
}
|
||||
else {
|
||||
return Array(newIndent + 1).join(' ');
|
||||
}
|
||||
});
|
||||
text += wasChomped ? "\n" : "";
|
||||
}
|
||||
if (actionArgs.repeat > 1) {
|
||||
var text = Array(actionArgs.repeat + 1).join(text);
|
||||
}
|
||||
var linewise = register.linewise;
|
||||
if (linewise) {
|
||||
if (actionArgs.after) {
|
||||
if(vim.visualMode) {
|
||||
text = vim.visualLine ? text.slice(0, -1) : '\n' + text.slice(0, text.length - 1) + '\n';
|
||||
} else if (actionArgs.after) {
|
||||
// Move the newline at the end to the start instead, and paste just
|
||||
// before the newline character of the line we are on right now.
|
||||
text = '\n' + text.slice(0, text.length - 1);
|
||||
|
@ -2025,24 +2120,35 @@
|
|||
} else {
|
||||
cur.ch += actionArgs.after ? 1 : 0;
|
||||
}
|
||||
cm.replaceRange(text, cur);
|
||||
// Now fine tune the cursor to where we want it.
|
||||
var curPosFinal;
|
||||
var idx;
|
||||
if (linewise && actionArgs.after) {
|
||||
curPosFinal = Pos(
|
||||
cur.line + 1,
|
||||
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1)));
|
||||
} else if (linewise && !actionArgs.after) {
|
||||
curPosFinal = Pos(
|
||||
cur.line,
|
||||
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line)));
|
||||
} else if (!linewise && actionArgs.after) {
|
||||
idx = cm.indexFromPos(cur);
|
||||
curPosFinal = cm.posFromIndex(idx + text.length - 1);
|
||||
if (vim.visualMode) {
|
||||
var selectedArea = getSelectedAreaRange(cm, vim);
|
||||
var selectionStart = selectedArea[0];
|
||||
var selectionEnd = selectedArea[1];
|
||||
// push the previously selected text to unnamed register
|
||||
vimGlobalState.registerController.unnamedRegister.setText(cm.getRange(selectionStart, selectionEnd));
|
||||
cm.replaceRange(text, selectionStart, selectionEnd);
|
||||
curPosFinal = cm.posFromIndex(cm.indexFromPos(selectionStart) + text.length - 1);
|
||||
if(linewise)curPosFinal.ch=0;
|
||||
} else {
|
||||
idx = cm.indexFromPos(cur);
|
||||
curPosFinal = cm.posFromIndex(idx + text.length);
|
||||
cm.replaceRange(text, cur);
|
||||
// Now fine tune the cursor to where we want it.
|
||||
if (linewise && actionArgs.after) {
|
||||
curPosFinal = Pos(
|
||||
cur.line + 1,
|
||||
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1)));
|
||||
} else if (linewise && !actionArgs.after) {
|
||||
curPosFinal = Pos(
|
||||
cur.line,
|
||||
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line)));
|
||||
} else if (!linewise && actionArgs.after) {
|
||||
idx = cm.indexFromPos(cur);
|
||||
curPosFinal = cm.posFromIndex(idx + text.length - 1);
|
||||
} else {
|
||||
idx = cm.indexFromPos(cur);
|
||||
curPosFinal = cm.posFromIndex(idx + text.length);
|
||||
}
|
||||
}
|
||||
cm.setCursor(curPosFinal);
|
||||
},
|
||||
|
@ -2136,6 +2242,15 @@
|
|||
repeat = vim.lastEditInputState.repeatOverride || repeat;
|
||||
}
|
||||
repeatLastEdit(cm, vim, repeat, false /** repeatForInsert */);
|
||||
},
|
||||
changeCase: function(cm, actionArgs, vim) {
|
||||
var selectedAreaRange = getSelectedAreaRange(cm, vim);
|
||||
var selectionStart = selectedAreaRange[0];
|
||||
var selectionEnd = selectedAreaRange[1];
|
||||
var toLower = actionArgs.toLower;
|
||||
var text = cm.getRange(selectionStart, selectionEnd);
|
||||
cm.replaceRange(toLower ? text.toLowerCase() : text.toUpperCase(), selectionStart, selectionEnd);
|
||||
cm.setCursor(selectionStart);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2218,6 +2333,29 @@
|
|||
function escapeRegex(s) {
|
||||
return s.replace(/([.?*+$\[\]\/\\(){}|\-])/g, '\\$1');
|
||||
}
|
||||
function getSelectedAreaRange(cm, vim) {
|
||||
var selectionStart = cm.getCursor('anchor');
|
||||
var selectionEnd = cm.getCursor('head');
|
||||
var lastSelection = vim.lastSelection;
|
||||
if (!vim.visualMode) {
|
||||
var line = lastSelection.curEnd.line - lastSelection.curStart.line;
|
||||
var ch = line ? lastSelection.curEnd.ch : lastSelection.curEnd.ch - lastSelection.curStart.ch;
|
||||
selectionEnd = {line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch};
|
||||
if (lastSelection.visualLine) {
|
||||
return [{line: selectionStart.line, ch: 0}, {line: selectionEnd.line, ch: lineLength(cm, selectionEnd.line)}];
|
||||
}
|
||||
} else {
|
||||
if (cursorIsBefore(selectionEnd, selectionStart)) {
|
||||
var tmp = selectionStart;
|
||||
selectionStart = selectionEnd;
|
||||
selectionEnd = tmp;
|
||||
} else {
|
||||
selectionEnd = cm.clipPos(Pos(selectionEnd.line, selectionEnd.ch+1));
|
||||
}
|
||||
exitVisualMode(cm);
|
||||
}
|
||||
return [selectionStart, selectionEnd];
|
||||
}
|
||||
|
||||
function exitVisualMode(cm) {
|
||||
cm.off('mousedown', exitVisualMode);
|
||||
|
@ -2670,74 +2808,33 @@
|
|||
return idx;
|
||||
}
|
||||
|
||||
function getContextLevel(ctx) {
|
||||
return (ctx === 'string' || ctx === 'comment') ? 1 : 0;
|
||||
}
|
||||
|
||||
function findMatchedSymbol(cm, cur, symb) {
|
||||
var line = cur.line;
|
||||
var ch = cur.ch;
|
||||
symb = symb ? symb : cm.getLine(line).charAt(ch);
|
||||
|
||||
var symbContext = cm.getTokenAt(Pos(line, ch + 1)).type;
|
||||
var symbCtxLevel = getContextLevel(symbContext);
|
||||
|
||||
var reverseSymb = ({
|
||||
'(': ')', ')': '(',
|
||||
'[': ']', ']': '[',
|
||||
'{': '}', '}': '{'})[symb];
|
||||
|
||||
// Couldn't find a matching symbol, abort
|
||||
if (!reverseSymb) {
|
||||
return cur;
|
||||
}
|
||||
|
||||
// set our increment to move forward (+1) or backwards (-1)
|
||||
// depending on which bracket we're matching
|
||||
var increment = ({'(': 1, '{': 1, '[': 1})[symb] || -1;
|
||||
var endLine = increment === 1 ? cm.lineCount() : -1;
|
||||
var depth = 1, nextCh = symb, index = ch, lineText = cm.getLine(line);
|
||||
// Simple search for closing paren--just count openings and closings till
|
||||
// we find our match
|
||||
// TODO: use info from CodeMirror to ignore closing brackets in comments
|
||||
// and quotes, etc.
|
||||
while (line !== endLine && depth > 0) {
|
||||
index += increment;
|
||||
nextCh = lineText.charAt(index);
|
||||
if (!nextCh) {
|
||||
line += increment;
|
||||
lineText = cm.getLine(line) || '';
|
||||
if (increment > 0) {
|
||||
index = 0;
|
||||
} else {
|
||||
var lineLen = lineText.length;
|
||||
index = (lineLen > 0) ? (lineLen-1) : 0;
|
||||
}
|
||||
nextCh = lineText.charAt(index);
|
||||
}
|
||||
var revSymbContext = cm.getTokenAt(Pos(line, index + 1)).type;
|
||||
var revSymbCtxLevel = getContextLevel(revSymbContext);
|
||||
if (symbCtxLevel >= revSymbCtxLevel) {
|
||||
if (nextCh === symb) {
|
||||
depth++;
|
||||
} else if (nextCh === reverseSymb) {
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nextCh) {
|
||||
return Pos(line, index);
|
||||
}
|
||||
return cur;
|
||||
}
|
||||
|
||||
// TODO: perhaps this finagling of start and end positions belonds
|
||||
// in codmirror/replaceRange?
|
||||
function selectCompanionObject(cm, revSymb, inclusive) {
|
||||
var cur = copyCursor(cm.getCursor());
|
||||
var end = findMatchedSymbol(cm, cur, revSymb);
|
||||
var start = findMatchedSymbol(cm, end);
|
||||
function selectCompanionObject(cm, symb, inclusive) {
|
||||
var cur = cm.getCursor(), start, end;
|
||||
|
||||
var bracketRegexp = ({
|
||||
'(': /[()]/, ')': /[()]/,
|
||||
'[': /[[\]]/, ']': /[[\]]/,
|
||||
'{': /[{}]/, '}': /[{}]/})[symb];
|
||||
var openSym = ({
|
||||
'(': '(', ')': '(',
|
||||
'[': '[', ']': '[',
|
||||
'{': '{', '}': '{'})[symb];
|
||||
var curChar = cm.getLine(cur.line).charAt(cur.ch);
|
||||
// Due to the behavior of scanForBracket, we need to add an offset if the
|
||||
// cursor is on a matching open bracket.
|
||||
var offset = curChar === openSym ? 1 : 0;
|
||||
|
||||
start = cm.scanForBracket(Pos(cur.line, cur.ch + offset), -1, null, {'bracketRegex': bracketRegexp});
|
||||
end = cm.scanForBracket(Pos(cur.line, cur.ch + offset), 1, null, {'bracketRegex': bracketRegexp});
|
||||
|
||||
if (!start || !end) {
|
||||
return { start: cur, end: cur };
|
||||
}
|
||||
|
||||
start = start.pos;
|
||||
end = end.pos;
|
||||
|
||||
if ((start.line == end.line && start.ch > end.ch)
|
||||
|| (start.line > end.line)) {
|
||||
|
@ -2869,15 +2966,15 @@
|
|||
// Translates a search string from ex (vim) syntax into javascript form.
|
||||
function translateRegex(str) {
|
||||
// When these match, add a '\' if unescaped or remove one if escaped.
|
||||
var specials = ['|', '(', ')', '{'];
|
||||
var specials = '|(){';
|
||||
// Remove, but never add, a '\' for these.
|
||||
var unescape = ['}'];
|
||||
var unescape = '}';
|
||||
var escapeNextChar = false;
|
||||
var out = [];
|
||||
for (var i = -1; i < str.length; i++) {
|
||||
var c = str.charAt(i) || '';
|
||||
var n = str.charAt(i+1) || '';
|
||||
var specialComesNext = (specials.indexOf(n) != -1);
|
||||
var specialComesNext = (n && specials.indexOf(n) != -1);
|
||||
if (escapeNextChar) {
|
||||
if (c !== '\\' || !specialComesNext) {
|
||||
out.push(c);
|
||||
|
@ -2887,7 +2984,7 @@
|
|||
if (c === '\\') {
|
||||
escapeNextChar = true;
|
||||
// Treat the unescape list as special for removing, but not adding '\'.
|
||||
if (unescape.indexOf(n) != -1) {
|
||||
if (n && unescape.indexOf(n) != -1) {
|
||||
specialComesNext = true;
|
||||
}
|
||||
// Not passing this test means removing a '\'.
|
||||
|
@ -3188,7 +3285,7 @@
|
|||
{ name: 'substitute', shortName: 's' },
|
||||
{ name: 'nohlsearch', shortName: 'noh' },
|
||||
{ name: 'delmarks', shortName: 'delm' },
|
||||
{ name: 'registers', shortName: 'reg' }
|
||||
{ name: 'registers', shortName: 'reg', excludeFromCommandHistory: true }
|
||||
];
|
||||
Vim.ExCommandDispatcher = function() {
|
||||
this.buildCommandMap_();
|
||||
|
@ -3196,10 +3293,14 @@
|
|||
Vim.ExCommandDispatcher.prototype = {
|
||||
processCommand: function(cm, input) {
|
||||
var vim = cm.state.vim;
|
||||
var commandHistoryRegister = vimGlobalState.registerController.getRegister(':');
|
||||
var previousCommand = commandHistoryRegister.toString();
|
||||
if (vim.visualMode) {
|
||||
exitVisualMode(cm);
|
||||
}
|
||||
var inputStream = new CodeMirror.StringStream(input);
|
||||
// update ": with the latest command whether valid or invalid
|
||||
commandHistoryRegister.setText(input);
|
||||
var params = {};
|
||||
params.input = input;
|
||||
try {
|
||||
|
@ -3218,6 +3319,9 @@
|
|||
var command = this.matchCommand_(params.commandName);
|
||||
if (command) {
|
||||
commandName = command.name;
|
||||
if (command.excludeFromCommandHistory) {
|
||||
commandHistoryRegister.setText(previousCommand);
|
||||
}
|
||||
this.parseCommandArgs_(inputStream, params, command);
|
||||
if (command.type == 'exToKey') {
|
||||
// Handle Ex to Key mapping.
|
||||
|
@ -3509,7 +3613,7 @@
|
|||
continue;
|
||||
}
|
||||
var register = registers[registerName] || new Register();
|
||||
regInfo += '"' + registerName + ' ' + register.text + '<br>';
|
||||
regInfo += '"' + registerName + ' ' + register.toString() + '<br>';
|
||||
}
|
||||
}
|
||||
showConfirm(cm, regInfo);
|
||||
|
@ -3595,38 +3699,41 @@
|
|||
'any other getSearchCursor implementation.');
|
||||
}
|
||||
var argString = params.argString;
|
||||
var slashes = findUnescapedSlashes(argString);
|
||||
if (slashes[0] !== 0) {
|
||||
showConfirm(cm, 'Substitutions should be of the form ' +
|
||||
':s/pattern/replace/');
|
||||
return;
|
||||
}
|
||||
var regexPart = argString.substring(slashes[0] + 1, slashes[1]);
|
||||
var slashes = argString ? findUnescapedSlashes(argString) : [];
|
||||
var replacePart = '';
|
||||
var flagsPart;
|
||||
var count;
|
||||
var confirm = false; // Whether to confirm each replace.
|
||||
if (slashes[1]) {
|
||||
replacePart = argString.substring(slashes[1] + 1, slashes[2]);
|
||||
if (getOption('pcre')) {
|
||||
replacePart = unescapeRegexReplace(replacePart);
|
||||
} else {
|
||||
replacePart = translateRegexReplace(replacePart);
|
||||
if (slashes.length) {
|
||||
if (slashes[0] !== 0) {
|
||||
showConfirm(cm, 'Substitutions should be of the form ' +
|
||||
':s/pattern/replace/');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (slashes[2]) {
|
||||
// After the 3rd slash, we can have flags followed by a space followed
|
||||
// by count.
|
||||
var trailing = argString.substring(slashes[2] + 1).split(' ');
|
||||
flagsPart = trailing[0];
|
||||
count = parseInt(trailing[1]);
|
||||
}
|
||||
if (flagsPart) {
|
||||
if (flagsPart.indexOf('c') != -1) {
|
||||
confirm = true;
|
||||
flagsPart.replace('c', '');
|
||||
var regexPart = argString.substring(slashes[0] + 1, slashes[1]);
|
||||
var flagsPart;
|
||||
var count;
|
||||
var confirm = false; // Whether to confirm each replace.
|
||||
if (slashes[1]) {
|
||||
replacePart = argString.substring(slashes[1] + 1, slashes[2]);
|
||||
if (getOption('pcre')) {
|
||||
replacePart = unescapeRegexReplace(replacePart);
|
||||
} else {
|
||||
replacePart = translateRegexReplace(replacePart);
|
||||
}
|
||||
vimGlobalState.lastSubstituteReplacePart = replacePart;
|
||||
}
|
||||
if (slashes[2]) {
|
||||
// After the 3rd slash, we can have flags followed by a space followed
|
||||
// by count.
|
||||
var trailing = argString.substring(slashes[2] + 1).split(' ');
|
||||
flagsPart = trailing[0];
|
||||
count = parseInt(trailing[1]);
|
||||
}
|
||||
if (flagsPart) {
|
||||
if (flagsPart.indexOf('c') != -1) {
|
||||
confirm = true;
|
||||
flagsPart.replace('c', '');
|
||||
}
|
||||
regexPart = regexPart + '/' + flagsPart;
|
||||
}
|
||||
regexPart = regexPart + '/' + flagsPart;
|
||||
}
|
||||
if (regexPart) {
|
||||
// If regex part is empty, then use the previous query. Otherwise use
|
||||
|
@ -3639,6 +3746,11 @@
|
|||
return;
|
||||
}
|
||||
}
|
||||
replacePart = replacePart || vimGlobalState.lastSubstituteReplacePart;
|
||||
if (replacePart === undefined) {
|
||||
showConfirm(cm, 'No previous substitute regular expression');
|
||||
return;
|
||||
}
|
||||
var state = getSearchState(cm);
|
||||
var query = state.getQuery();
|
||||
var lineStart = (params.line !== undefined) ? params.line : cm.getCursor().line;
|
||||
|
@ -3847,6 +3959,7 @@
|
|||
// Closure to bind CodeMirror, key, modifier.
|
||||
function keyMapper(vimKey) {
|
||||
return function(cm) {
|
||||
CodeMirror.signal(cm, 'vim-keypress', vimKey);
|
||||
CodeMirror.Vim.handleKey(cm, vimKey);
|
||||
};
|
||||
}
|
||||
|
@ -3884,10 +3997,10 @@
|
|||
function exitInsertMode(cm) {
|
||||
var vim = cm.state.vim;
|
||||
var macroModeState = vimGlobalState.macroModeState;
|
||||
var insertModeChangeRegister = vimGlobalState.registerController.getRegister('.');
|
||||
var isPlaying = macroModeState.isPlaying;
|
||||
if (!isPlaying) {
|
||||
cm.off('change', onChange);
|
||||
cm.off('cursorActivity', onCursorActivity);
|
||||
CodeMirror.off(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
|
||||
}
|
||||
if (!isPlaying && vim.insertModeRepeat > 1) {
|
||||
|
@ -3897,11 +4010,13 @@
|
|||
vim.lastEditInputState.repeatOverride = vim.insertModeRepeat;
|
||||
}
|
||||
delete vim.insertModeRepeat;
|
||||
cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1);
|
||||
vim.insertMode = false;
|
||||
cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1);
|
||||
cm.setOption('keyMap', 'vim');
|
||||
cm.setOption('disableInput', true);
|
||||
cm.toggleOverwrite(false); // exit replace mode if we were in it.
|
||||
// update the ". register before exiting insert mode
|
||||
insertModeChangeRegister.setText(macroModeState.lastInsertModeChanges.changes.join(''));
|
||||
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
|
||||
if (macroModeState.isRecording) {
|
||||
logInsertModeChange(macroModeState);
|
||||
|
@ -3934,6 +4049,7 @@
|
|||
var keyBuffer = register.keyBuffer;
|
||||
var imc = 0;
|
||||
macroModeState.isPlaying = true;
|
||||
macroModeState.replaySearchQueries = register.searchQueries.slice(0);
|
||||
for (var i = 0; i < keyBuffer.length; i++) {
|
||||
var text = keyBuffer[i];
|
||||
var match, key;
|
||||
|
@ -3972,6 +4088,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
function logSearchQuery(macroModeState, query) {
|
||||
if (macroModeState.isPlaying) { return; }
|
||||
var registerName = macroModeState.latestRegister;
|
||||
var register = vimGlobalState.registerController.getRegister(registerName);
|
||||
if (register) {
|
||||
register.pushSearchQuery(query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for changes made in insert mode.
|
||||
* Should only be active in insert mode.
|
||||
|
@ -3995,18 +4120,23 @@
|
|||
|
||||
/**
|
||||
* Listens for any kind of cursor activity on CodeMirror.
|
||||
* - For tracking cursor activity in insert mode.
|
||||
* - Should only be active in insert mode.
|
||||
*/
|
||||
function onCursorActivity() {
|
||||
var macroModeState = vimGlobalState.macroModeState;
|
||||
if (macroModeState.isPlaying) { return; }
|
||||
var lastChange = macroModeState.lastInsertModeChanges;
|
||||
if (lastChange.expectCursorActivityForChange) {
|
||||
lastChange.expectCursorActivityForChange = false;
|
||||
} else {
|
||||
// Cursor moved outside the context of an edit. Reset the change.
|
||||
lastChange.changes = [];
|
||||
function onCursorActivity(cm) {
|
||||
var vim = cm.state.vim;
|
||||
if (vim.insertMode) {
|
||||
// Tracking cursor activity in insert mode (for macro support).
|
||||
var macroModeState = vimGlobalState.macroModeState;
|
||||
if (macroModeState.isPlaying) { return; }
|
||||
var lastChange = macroModeState.lastInsertModeChanges;
|
||||
if (lastChange.expectCursorActivityForChange) {
|
||||
lastChange.expectCursorActivityForChange = false;
|
||||
} else {
|
||||
// Cursor moved outside the context of an edit. Reset the change.
|
||||
lastChange.changes = [];
|
||||
}
|
||||
} else if (cm.doc.history.lastSelOrigin == '*mouse') {
|
||||
// Reset lastHPos if mouse click was done in normal mode.
|
||||
vim.lastHPos = cm.doc.getCursor().ch;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
||||
|
@ -173,7 +176,6 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
};
|
||||
});
|
||||
|
||||
(function() {
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
|
@ -251,6 +253,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
}
|
||||
|
||||
function def(mimes, mode) {
|
||||
if (typeof mimes == "string") mimes = [mimes];
|
||||
var words = [];
|
||||
function add(obj) {
|
||||
if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop))
|
||||
|
@ -295,7 +298,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
},
|
||||
modeProps: {fold: ["brace", "include"]}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-java", {
|
||||
def("text/x-java", {
|
||||
name: "clike",
|
||||
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
|
||||
"do double else enum extends final finally float for goto if implements import " +
|
||||
|
@ -312,7 +315,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
},
|
||||
modeProps: {fold: ["brace", "import"]}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-csharp", {
|
||||
def("text/x-csharp", {
|
||||
name: "clike",
|
||||
keywords: words("abstract as base break case catch checked class const continue" +
|
||||
" default delegate do else enum event explicit extern finally fixed for" +
|
||||
|
@ -338,7 +341,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
}
|
||||
}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-scala", {
|
||||
def("text/x-scala", {
|
||||
name: "clike",
|
||||
keywords: words(
|
||||
|
||||
|
@ -432,6 +435,5 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
hooks: {"#": cppHook},
|
||||
modeProps: {fold: ["brace", "include"]}
|
||||
});
|
||||
}());
|
||||
|
||||
});
|
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
||||
|
@ -16,6 +19,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
mediaTypes = parserConfig.mediaTypes || {},
|
||||
mediaFeatures = parserConfig.mediaFeatures || {},
|
||||
propertyKeywords = parserConfig.propertyKeywords || {},
|
||||
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
|
||||
colorKeywords = parserConfig.colorKeywords || {},
|
||||
valueKeywords = parserConfig.valueKeywords || {},
|
||||
fontProperties = parserConfig.fontProperties || {},
|
||||
|
@ -53,7 +57,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
if (/[\d.]/.test(stream.peek())) {
|
||||
stream.eatWhile(/[\w.%]/);
|
||||
return ret("number", "unit");
|
||||
} else if (stream.match(/^[^-]+-/)) {
|
||||
} else if (stream.match(/^\w+-/)) {
|
||||
return ret("meta", "meta");
|
||||
}
|
||||
} else if (/[,+>*\/]/.test(ch)) {
|
||||
|
@ -91,7 +95,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
|
||||
function tokenParenthesized(stream, state) {
|
||||
stream.next(); // Must be '('
|
||||
if (!stream.match(/\s*[\"\']/, false))
|
||||
if (!stream.match(/\s*[\"\')]/, false))
|
||||
state.tokenize = tokenString(")");
|
||||
else
|
||||
state.tokenize = null;
|
||||
|
@ -163,16 +167,20 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
} else if (type == ":") {
|
||||
return "pseudo";
|
||||
} else if (allowNested && type == "(") {
|
||||
return pushContext(state, stream, "params");
|
||||
return pushContext(state, stream, "parens");
|
||||
}
|
||||
return state.context.type;
|
||||
};
|
||||
|
||||
states.block = function(type, stream, state) {
|
||||
if (type == "word") {
|
||||
if (propertyKeywords.hasOwnProperty(stream.current().toLowerCase())) {
|
||||
var word = stream.current().toLowerCase();
|
||||
if (propertyKeywords.hasOwnProperty(word)) {
|
||||
override = "property";
|
||||
return "maybeprop";
|
||||
} else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
|
||||
override = "string-2";
|
||||
return "maybeprop";
|
||||
} else if (allowNested) {
|
||||
override = stream.match(/^\s*:/, false) ? "property" : "tag";
|
||||
return "block";
|
||||
|
@ -220,6 +228,8 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
states.parens = function(type, stream, state) {
|
||||
if (type == "{" || type == "}") return popAndPass(type, stream, state);
|
||||
if (type == ")") return popContext(state);
|
||||
if (type == "(") return pushContext(state, stream, "parens");
|
||||
if (type == "word") wordAsValue(stream);
|
||||
return "parens";
|
||||
};
|
||||
|
||||
|
@ -295,13 +305,6 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
return "interpolation";
|
||||
};
|
||||
|
||||
states.params = function(type, stream, state) {
|
||||
if (type == ")") return popContext(state);
|
||||
if (type == "{" || type == "}") return popAndPass(type, stream, state);
|
||||
if (type == "word") wordAsValue(stream);
|
||||
return "params";
|
||||
};
|
||||
|
||||
return {
|
||||
startState: function(base) {
|
||||
return {tokenize: null,
|
||||
|
@ -324,10 +327,10 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
indent: function(state, textAfter) {
|
||||
var cx = state.context, ch = textAfter && textAfter.charAt(0);
|
||||
var indent = cx.indent;
|
||||
if (cx.type == "prop" && ch == "}") cx = cx.prev;
|
||||
if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
|
||||
if (cx.prev &&
|
||||
(ch == "}" && (cx.type == "block" || cx.type == "top" || cx.type == "interpolation" || cx.type == "font_face") ||
|
||||
ch == ")" && (cx.type == "parens" || cx.type == "params" || cx.type == "media_parens") ||
|
||||
ch == ")" && (cx.type == "parens" || cx.type == "media_parens") ||
|
||||
ch == "{" && (cx.type == "at" || cx.type == "media"))) {
|
||||
indent = cx.indent - indentUnit;
|
||||
cx = cx.prev;
|
||||
|
@ -404,7 +407,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
"font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
|
||||
"font-variant-ligatures", "font-variant-numeric", "font-variant-position",
|
||||
"font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
|
||||
"grid-auto-rows", "grid-column", "grid-column-end",
|
||||
"grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",
|
||||
"grid-column-start", "grid-row", "grid-row-end", "grid-row-start",
|
||||
"grid-template", "grid-template-areas", "grid-template-columns",
|
||||
"grid-template-rows", "hanging-punctuation", "height", "hyphens",
|
||||
|
@ -417,7 +420,8 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
"marker-offset", "marks", "marquee-direction", "marquee-loop",
|
||||
"marquee-play-count", "marquee-speed", "marquee-style", "max-height",
|
||||
"max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
|
||||
"nav-left", "nav-right", "nav-up", "opacity", "order", "orphans", "outline",
|
||||
"nav-left", "nav-right", "nav-up", "object-fit", "object-position",
|
||||
"opacity", "order", "orphans", "outline",
|
||||
"outline-color", "outline-offset", "outline-style", "outline-width",
|
||||
"overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
|
||||
"padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
|
||||
|
@ -428,8 +432,8 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
"region-break-before", "region-break-inside", "region-fragment",
|
||||
"rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
|
||||
"right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
|
||||
"ruby-position", "ruby-span", "shape-inside", "shape-outside", "size",
|
||||
"speak", "speak-as", "speak-header",
|
||||
"ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
|
||||
"shape-outside", "size", "speak", "speak-as", "speak-header",
|
||||
"speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
|
||||
"tab-size", "table-layout", "target", "target-name", "target-new",
|
||||
"target-position", "text-align", "text-align-last", "text-decoration",
|
||||
|
@ -444,19 +448,27 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
"vertical-align", "visibility", "voice-balance", "voice-duration",
|
||||
"voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
|
||||
"voice-volume", "volume", "white-space", "widows", "width", "word-break",
|
||||
"word-spacing", "word-wrap", "z-index", "zoom",
|
||||
"word-spacing", "word-wrap", "z-index",
|
||||
// SVG-specific
|
||||
"clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
|
||||
"flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
|
||||
"color-interpolation", "color-interpolation-filters", "color-profile",
|
||||
"color-interpolation", "color-interpolation-filters",
|
||||
"color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
|
||||
"marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
|
||||
"stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
|
||||
"stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
|
||||
"baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
|
||||
"glyph-orientation-vertical", "kerning", "text-anchor", "writing-mode"
|
||||
"glyph-orientation-vertical", "text-anchor", "writing-mode"
|
||||
], propertyKeywords = keySet(propertyKeywords_);
|
||||
|
||||
var nonStandardPropertyKeywords = [
|
||||
"scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
|
||||
"scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
|
||||
"scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
|
||||
"searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
|
||||
"searchfield-results-decoration", "zoom"
|
||||
], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords);
|
||||
|
||||
var colorKeywords_ = [
|
||||
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
|
||||
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
|
||||
|
@ -576,7 +588,8 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
"font-stretch", "font-weight", "font-style"
|
||||
], fontProperties = keySet(fontProperties_);
|
||||
|
||||
var allWords = mediaTypes_.concat(mediaFeatures_).concat(propertyKeywords_).concat(colorKeywords_).concat(valueKeywords_);
|
||||
var allWords = mediaTypes_.concat(mediaFeatures_).concat(propertyKeywords_)
|
||||
.concat(nonStandardPropertyKeywords).concat(colorKeywords_).concat(valueKeywords_);
|
||||
CodeMirror.registerHelper("hintWords", "css", allWords);
|
||||
|
||||
function tokenCComment(stream, state) {
|
||||
|
@ -605,6 +618,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
mediaTypes: mediaTypes,
|
||||
mediaFeatures: mediaFeatures,
|
||||
propertyKeywords: propertyKeywords,
|
||||
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
||||
colorKeywords: colorKeywords,
|
||||
valueKeywords: valueKeywords,
|
||||
fontProperties: fontProperties,
|
||||
|
@ -627,6 +641,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
mediaTypes: mediaTypes,
|
||||
mediaFeatures: mediaFeatures,
|
||||
propertyKeywords: propertyKeywords,
|
||||
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
||||
colorKeywords: colorKeywords,
|
||||
valueKeywords: valueKeywords,
|
||||
fontProperties: fontProperties,
|
||||
|
@ -667,6 +682,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|||
mediaTypes: mediaTypes,
|
||||
mediaFeatures: mediaFeatures,
|
||||
propertyKeywords: propertyKeywords,
|
||||
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
||||
colorKeywords: colorKeywords,
|
||||
valueKeywords: valueKeywords,
|
||||
fontProperties: fontProperties,
|
|
@ -1,3 +1,6 @@
|
|||
// 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"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css"));
|
|
@ -1,3 +1,6 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
// TODO actually recognize syntax of TypeScript constructs
|
||||
|
||||
(function(mod) {
|
||||
|
@ -325,7 +328,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|||
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
||||
if (type == "{") return cont(pushlex("}"), block, poplex);
|
||||
if (type == ";") return cont();
|
||||
if (type == "if") return cont(pushlex("form"), expression, statement, poplex, maybeelse);
|
||||
if (type == "if") {
|
||||
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
|
||||
cx.state.cc.pop()();
|
||||
return cont(pushlex("form"), expression, statement, poplex, maybeelse);
|
||||
}
|
||||
if (type == "function") return cont(functiondef);
|
||||
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
|
||||
if (type == "variable") return cont(pushlex("stat"), maybelabel);
|
||||
|
@ -356,12 +363,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|||
|
||||
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
|
||||
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
|
||||
if (type == "function") return cont(functiondef);
|
||||
if (type == "function") return cont(functiondef, maybeop);
|
||||
if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
|
||||
if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop);
|
||||
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
|
||||
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
|
||||
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
|
||||
if (type == "quasi") { return pass(quasi, maybeop); }
|
||||
return cont();
|
||||
}
|
||||
function maybeexpression(type) {
|
||||
|
@ -386,21 +394,22 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|||
if (value == "?") return cont(expression, expect(":"), expr);
|
||||
return cont(expr);
|
||||
}
|
||||
if (type == "quasi") { cx.cc.push(me); return quasi(value); }
|
||||
if (type == "quasi") { return pass(quasi, me); }
|
||||
if (type == ";") return;
|
||||
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
|
||||
if (type == ".") return cont(property, me);
|
||||
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
|
||||
}
|
||||
function quasi(value) {
|
||||
if (value.slice(value.length - 2) != "${") return cont();
|
||||
function quasi(type, value) {
|
||||
if (type != "quasi") return pass();
|
||||
if (value.slice(value.length - 2) != "${") return cont(quasi);
|
||||
return cont(expression, continueQuasi);
|
||||
}
|
||||
function continueQuasi(type) {
|
||||
if (type == "}") {
|
||||
cx.marked = "string-2";
|
||||
cx.state.tokenize = tokenQuasi;
|
||||
return cont();
|
||||
return cont(quasi);
|
||||
}
|
||||
}
|
||||
function arrowBody(type) {
|
||||
|
@ -493,7 +502,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|||
if (type == ",") return cont(vardef);
|
||||
}
|
||||
function maybeelse(type, value) {
|
||||
if (type == "keyword b" && value == "else") return cont(pushlex("form"), statement, poplex);
|
||||
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
|
||||
}
|
||||
function forspec(type) {
|
||||
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
|
||||
|
@ -606,7 +615,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|||
if (state.tokenize != tokenBase) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
|
||||
// Kludge to prevent 'maybelse' from blocking lexical scope pops
|
||||
for (var i = state.cc.length - 1; i >= 0; --i) {
|
||||
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
|
||||
var c = state.cc[i];
|
||||
if (c == poplex) lexical = lexical.prev;
|
||||
else if (c != maybeelse) break;
|
||||
|
@ -639,6 +648,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|||
};
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("wordChars", "javascript", /[\\w$]/);
|
||||
|
||||
CodeMirror.defineMIME("text/javascript", "javascript");
|
||||
CodeMirror.defineMIME("text/ecmascript", "javascript");
|
||||
CodeMirror.defineMIME("application/javascript", "javascript");
|
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
||||
|
@ -58,7 +61,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
var alignCDATA = parserConfig.alignCDATA;
|
||||
|
||||
// Return variables for tokenizers
|
||||
var tagName, type, setStyle;
|
||||
var type, setStyle;
|
||||
|
||||
function inText(stream, state) {
|
||||
function chain(parser) {
|
||||
|
@ -85,15 +88,9 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
state.tokenize = inBlock("meta", "?>");
|
||||
return "meta";
|
||||
} else {
|
||||
var isClose = stream.eat("/");
|
||||
tagName = "";
|
||||
var c;
|
||||
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
|
||||
if (Kludges.caseFold) tagName = tagName.toLowerCase();
|
||||
if (!tagName) return "tag error";
|
||||
type = isClose ? "closeTag" : "openTag";
|
||||
type = stream.eat("/") ? "closeTag" : "openTag";
|
||||
state.tokenize = inTag;
|
||||
return "tag";
|
||||
return "tag bracket";
|
||||
}
|
||||
} else if (ch == "&") {
|
||||
var ok;
|
||||
|
@ -118,7 +115,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
|
||||
state.tokenize = inText;
|
||||
type = ch == ">" ? "endTag" : "selfcloseTag";
|
||||
return "tag";
|
||||
return "tag bracket";
|
||||
} else if (ch == "=") {
|
||||
type = "equals";
|
||||
return null;
|
||||
|
@ -127,13 +124,13 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
state.state = baseState;
|
||||
state.tagName = state.tagStart = null;
|
||||
var next = state.tokenize(stream, state);
|
||||
return next ? next + " error" : "error";
|
||||
return next ? next + " tag error" : "tag error";
|
||||
} else if (/[\'\"]/.test(ch)) {
|
||||
state.tokenize = inAttribute(ch);
|
||||
state.stringStartCol = stream.column();
|
||||
return state.tokenize(stream, state);
|
||||
} else {
|
||||
stream.eatWhile(/[^\s\u00a0=<>\"\']/);
|
||||
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
|
||||
return "word";
|
||||
}
|
||||
}
|
||||
|
@ -213,26 +210,42 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
|
||||
function baseState(type, stream, state) {
|
||||
if (type == "openTag") {
|
||||
state.tagName = tagName;
|
||||
state.tagStart = stream.column();
|
||||
return attrState;
|
||||
return tagNameState;
|
||||
} else if (type == "closeTag") {
|
||||
var err = false;
|
||||
if (state.context) {
|
||||
if (state.context.tagName != tagName) {
|
||||
if (Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
|
||||
popContext(state);
|
||||
err = !state.context || state.context.tagName != tagName;
|
||||
}
|
||||
} else {
|
||||
err = true;
|
||||
}
|
||||
if (err) setStyle = "error";
|
||||
return err ? closeStateErr : closeState;
|
||||
return closeTagNameState;
|
||||
} else {
|
||||
return baseState;
|
||||
}
|
||||
}
|
||||
function tagNameState(type, stream, state) {
|
||||
if (type == "word") {
|
||||
state.tagName = stream.current();
|
||||
setStyle = "tag";
|
||||
return attrState;
|
||||
} else {
|
||||
setStyle = "error";
|
||||
return tagNameState;
|
||||
}
|
||||
}
|
||||
function closeTagNameState(type, stream, state) {
|
||||
if (type == "word") {
|
||||
var tagName = stream.current();
|
||||
if (state.context && state.context.tagName != tagName &&
|
||||
Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
|
||||
popContext(state);
|
||||
if (state.context && state.context.tagName == tagName) {
|
||||
setStyle = "tag";
|
||||
return closeState;
|
||||
} else {
|
||||
setStyle = "tag error";
|
||||
return closeStateErr;
|
||||
}
|
||||
} else {
|
||||
setStyle = "error";
|
||||
return closeStateErr;
|
||||
}
|
||||
}
|
||||
|
||||
function closeState(type, _stream, state) {
|
||||
if (type != "endTag") {
|
||||
|
@ -296,7 +309,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
state.indented = stream.indentation();
|
||||
|
||||
if (stream.eatSpace()) return null;
|
||||
tagName = type = null;
|
||||
type = null;
|
||||
var style = state.tokenize(stream, state);
|
||||
if ((style || type) && style != "comment") {
|
||||
setStyle = null;
|
||||
|
@ -311,7 +324,10 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
var context = state.context;
|
||||
// Indent multi-line strings (e.g. css).
|
||||
if (state.tokenize.isInAttribute) {
|
||||
return state.stringStartCol + 1;
|
||||
if (state.tagStart == state.indented)
|
||||
return state.stringStartCol + 1;
|
||||
else
|
||||
return state.indented + indentUnit;
|
||||
}
|
||||
if (context && context.noIndent) return CodeMirror.Pass;
|
||||
if (state.tokenize != inTag && state.tokenize != inText)
|
||||
|
@ -324,15 +340,34 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
return state.tagStart + indentUnit * multilineTagIndentFactor;
|
||||
}
|
||||
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
|
||||
if (context && /^<\//.test(textAfter))
|
||||
context = context.prev;
|
||||
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
|
||||
if (tagAfter && tagAfter[1]) { // Closing tag spotted
|
||||
while (context) {
|
||||
if (context.tagName == tagAfter[2]) {
|
||||
context = context.prev;
|
||||
break;
|
||||
} else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) {
|
||||
context = context.prev;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (tagAfter) { // Opening tag spotted
|
||||
while (context) {
|
||||
var grabbers = Kludges.contextGrabbers[context.tagName];
|
||||
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
|
||||
context = context.prev;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (context && !context.startOfLine)
|
||||
context = context.prev;
|
||||
if (context) return context.indent + indentUnit;
|
||||
else return 0;
|
||||
},
|
||||
|
||||
electricChars: "/",
|
||||
electricInput: /<\/[\s\w:]+>$/,
|
||||
blockCommentStart: "<!--",
|
||||
blockCommentEnd: "-->",
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
// Highlighting text that matches the selection
|
||||
//
|
||||
// Defines an option highlightSelectionMatches, which, when enabled,
|
||||
|
@ -76,8 +79,9 @@
|
|||
cm.addOverlay(state.overlay = makeOverlay(line.slice(start, end), re, state.style));
|
||||
return;
|
||||
}
|
||||
if (cm.getCursor("head").line != cm.getCursor("anchor").line) return;
|
||||
var selection = cm.getSelections()[0].replace(/^\s+|\s+$/g, "");
|
||||
var from = cm.getCursor("from"), to = cm.getCursor("to");
|
||||
if (from.line != to.line) return;
|
||||
var selection = cm.getRange(from, to).replace(/^\s+|\s+$/g, "");
|
||||
if (selection.length >= state.minChars)
|
||||
cm.addOverlay(state.overlay = makeOverlay(selection, false, state.style));
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
// Define search commands. Depends on dialog.js or another
|
||||
// implementation of the openDialog method.
|
||||
|
||||
|
@ -16,21 +19,21 @@
|
|||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
function searchOverlay(query, caseInsensitive) {
|
||||
var startChar;
|
||||
if (typeof query == "string") {
|
||||
startChar = query.charAt(0);
|
||||
query = new RegExp("^" + query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"),
|
||||
caseInsensitive ? "i" : "");
|
||||
} else {
|
||||
query = new RegExp("^(?:" + query.source + ")", query.ignoreCase ? "i" : "");
|
||||
}
|
||||
if (typeof query == "string")
|
||||
query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");
|
||||
else if (!query.global)
|
||||
query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
|
||||
|
||||
return {token: function(stream) {
|
||||
if (stream.match(query)) return "searching";
|
||||
while (!stream.eol()) {
|
||||
stream.next();
|
||||
if (startChar && !caseInsensitive)
|
||||
stream.skipTo(startChar) || stream.skipToEnd();
|
||||
if (stream.match(query, false)) break;
|
||||
query.lastIndex = stream.pos;
|
||||
var match = query.exec(stream.string);
|
||||
if (match && match.index == stream.pos) {
|
||||
stream.pos += match[0].length;
|
||||
return "searching";
|
||||
} else if (match) {
|
||||
stream.pos = match.index;
|
||||
} else {
|
||||
stream.skipToEnd();
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// 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"));
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
// Because sometimes you need to style the cursor's line.
|
||||
//
|
||||
// Adds an option 'styleActiveLine' which, when enabled, gives the
|
|
@ -0,0 +1,118 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
// Because sometimes you need to mark the selected *text*.
|
||||
//
|
||||
// Adds an option 'styleSelectedText' which, when enabled, gives
|
||||
// selected text the CSS class given as option value, or
|
||||
// "CodeMirror-selectedtext" when the value is not a string.
|
||||
|
||||
(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.defineOption("styleSelectedText", false, function(cm, val, old) {
|
||||
var prev = old && old != CodeMirror.Init;
|
||||
if (val && !prev) {
|
||||
cm.state.markedSelection = [];
|
||||
cm.state.markedSelectionStyle = typeof val == "string" ? val : "CodeMirror-selectedtext";
|
||||
reset(cm);
|
||||
cm.on("cursorActivity", onCursorActivity);
|
||||
cm.on("change", onChange);
|
||||
} else if (!val && prev) {
|
||||
cm.off("cursorActivity", onCursorActivity);
|
||||
cm.off("change", onChange);
|
||||
clear(cm);
|
||||
cm.state.markedSelection = cm.state.markedSelectionStyle = null;
|
||||
}
|
||||
});
|
||||
|
||||
function onCursorActivity(cm) {
|
||||
cm.operation(function() { update(cm); });
|
||||
}
|
||||
|
||||
function onChange(cm) {
|
||||
if (cm.state.markedSelection.length)
|
||||
cm.operation(function() { clear(cm); });
|
||||
}
|
||||
|
||||
var CHUNK_SIZE = 8;
|
||||
var Pos = CodeMirror.Pos;
|
||||
var cmp = CodeMirror.cmpPos;
|
||||
|
||||
function coverRange(cm, from, to, addAt) {
|
||||
if (cmp(from, to) == 0) return;
|
||||
var array = cm.state.markedSelection;
|
||||
var cls = cm.state.markedSelectionStyle;
|
||||
for (var line = from.line;;) {
|
||||
var start = line == from.line ? from : Pos(line, 0);
|
||||
var endLine = line + CHUNK_SIZE, atEnd = endLine >= to.line;
|
||||
var end = atEnd ? to : Pos(endLine, 0);
|
||||
var mark = cm.markText(start, end, {className: cls});
|
||||
if (addAt == null) array.push(mark);
|
||||
else array.splice(addAt++, 0, mark);
|
||||
if (atEnd) break;
|
||||
line = endLine;
|
||||
}
|
||||
}
|
||||
|
||||
function clear(cm) {
|
||||
var array = cm.state.markedSelection;
|
||||
for (var i = 0; i < array.length; ++i) array[i].clear();
|
||||
array.length = 0;
|
||||
}
|
||||
|
||||
function reset(cm) {
|
||||
clear(cm);
|
||||
var ranges = cm.listSelections();
|
||||
for (var i = 0; i < ranges.length; i++)
|
||||
coverRange(cm, ranges[i].from(), ranges[i].to());
|
||||
}
|
||||
|
||||
function update(cm) {
|
||||
if (!cm.somethingSelected()) return clear(cm);
|
||||
if (cm.listSelections().length > 1) return reset(cm);
|
||||
|
||||
var from = cm.getCursor("start"), to = cm.getCursor("end");
|
||||
|
||||
var array = cm.state.markedSelection;
|
||||
if (!array.length) return coverRange(cm, from, to);
|
||||
|
||||
var coverStart = array[0].find(), coverEnd = array[array.length - 1].find();
|
||||
if (!coverStart || !coverEnd || to.line - from.line < CHUNK_SIZE ||
|
||||
cmp(from, coverEnd.to) >= 0 || cmp(to, coverStart.from) <= 0)
|
||||
return reset(cm);
|
||||
|
||||
while (cmp(from, coverStart.from) > 0) {
|
||||
array.shift().clear();
|
||||
coverStart = array[0].find();
|
||||
}
|
||||
if (cmp(from, coverStart.from) < 0) {
|
||||
if (coverStart.to.line - from.line < CHUNK_SIZE) {
|
||||
array.shift().clear();
|
||||
coverRange(cm, from, coverStart.to, 0);
|
||||
} else {
|
||||
coverRange(cm, from, coverStart.from, 0);
|
||||
}
|
||||
}
|
||||
|
||||
while (cmp(to, coverEnd.to) < 0) {
|
||||
array.pop().clear();
|
||||
coverEnd = array[array.length - 1].find();
|
||||
}
|
||||
if (cmp(to, coverEnd.to) > 0) {
|
||||
if (to.line - coverEnd.from.line < CHUNK_SIZE) {
|
||||
array.pop().clear();
|
||||
coverRange(cm, coverEnd.from, to);
|
||||
} else {
|
||||
coverRange(cm, coverEnd.to, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
|
@ -0,0 +1,86 @@
|
|||
.CodeMirror-Tern-completion {
|
||||
padding-left: 22px;
|
||||
position: relative;
|
||||
}
|
||||
.CodeMirror-Tern-completion:before {
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
bottom: 2px;
|
||||
border-radius: 50%;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
height: 15px;
|
||||
width: 15px;
|
||||
line-height: 16px;
|
||||
text-align: center;
|
||||
color: white;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.CodeMirror-Tern-completion-unknown:before {
|
||||
content: "?";
|
||||
background: #4bb;
|
||||
}
|
||||
.CodeMirror-Tern-completion-object:before {
|
||||
content: "O";
|
||||
background: #77c;
|
||||
}
|
||||
.CodeMirror-Tern-completion-fn:before {
|
||||
content: "F";
|
||||
background: #7c7;
|
||||
}
|
||||
.CodeMirror-Tern-completion-array:before {
|
||||
content: "A";
|
||||
background: #c66;
|
||||
}
|
||||
.CodeMirror-Tern-completion-number:before {
|
||||
content: "1";
|
||||
background: #999;
|
||||
}
|
||||
.CodeMirror-Tern-completion-string:before {
|
||||
content: "S";
|
||||
background: #999;
|
||||
}
|
||||
.CodeMirror-Tern-completion-bool:before {
|
||||
content: "B";
|
||||
background: #999;
|
||||
}
|
||||
|
||||
.CodeMirror-Tern-completion-guess {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.CodeMirror-Tern-tooltip {
|
||||
border: 1px solid silver;
|
||||
border-radius: 3px;
|
||||
color: #444;
|
||||
padding: 2px 5px;
|
||||
font-size: 90%;
|
||||
font-family: monospace;
|
||||
background-color: white;
|
||||
white-space: pre-wrap;
|
||||
|
||||
max-width: 40em;
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
|
||||
transition: opacity 1s;
|
||||
-moz-transition: opacity 1s;
|
||||
-webkit-transition: opacity 1s;
|
||||
-o-transition: opacity 1s;
|
||||
-ms-transition: opacity 1s;
|
||||
}
|
||||
|
||||
.CodeMirror-Tern-hint-doc {
|
||||
max-width: 25em;
|
||||
margin-top: -3px;
|
||||
}
|
||||
|
||||
.CodeMirror-Tern-fname { color: black; }
|
||||
.CodeMirror-Tern-farg { color: #70a; }
|
||||
.CodeMirror-Tern-farg-current { text-decoration: underline; }
|
||||
.CodeMirror-Tern-type { color: #07c; }
|
||||
.CodeMirror-Tern-fhint-guess { opacity: .7; }
|
|
@ -1,3 +1,6 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
// Glue code between CodeMirror and Tern.
|
||||
//
|
||||
// Create a CodeMirror.TernServer to wrap an actual Tern server,
|
||||
|
@ -14,7 +17,7 @@
|
|||
// indicate that a file is not available.
|
||||
// * fileFilter: A function(value, docName, doc) that will be applied
|
||||
// to documents before passing them on to Tern.
|
||||
// * switchToDoc: A function(name) that should, when providing a
|
||||
// * switchToDoc: A function(name, doc) that should, when providing a
|
||||
// multi-file view, switch the view or focus to the named file.
|
||||
// * showError: A function(editor, message) that can be used to
|
||||
// override the way errors are displayed.
|
||||
|
@ -40,7 +43,14 @@
|
|||
// load. Or, if you minified those into a single script and included
|
||||
// them in the workerScript, simply leave this undefined.
|
||||
|
||||
(function() {
|
||||
(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: tern
|
||||
|
||||
|
@ -65,6 +75,9 @@
|
|||
this.cachedArgHints = null;
|
||||
this.activeArgHints = null;
|
||||
this.jumpStack = [];
|
||||
|
||||
this.getHint = function(cm, c) { return hint(self, cm, c); };
|
||||
this.getHint.async = true;
|
||||
};
|
||||
|
||||
CodeMirror.TernServer.prototype = {
|
||||
|
@ -75,28 +88,25 @@
|
|||
return this.docs[name] = data;
|
||||
},
|
||||
|
||||
delDoc: function(name) {
|
||||
var found = this.docs[name];
|
||||
delDoc: function(id) {
|
||||
var found = resolveDoc(this, id);
|
||||
if (!found) return;
|
||||
CodeMirror.off(found.doc, "change", this.trackChange);
|
||||
delete this.docs[name];
|
||||
this.server.delFile(name);
|
||||
delete this.docs[found.name];
|
||||
this.server.delFile(found.name);
|
||||
},
|
||||
|
||||
hideDoc: function(name) {
|
||||
hideDoc: function(id) {
|
||||
closeArgHints(this);
|
||||
var found = this.docs[name];
|
||||
var found = resolveDoc(this, id);
|
||||
if (found && found.changed) sendDoc(this, found);
|
||||
},
|
||||
|
||||
complete: function(cm) {
|
||||
var self = this;
|
||||
CodeMirror.showHint(cm, function(cm, c) { return hint(self, cm, c); }, {async: true});
|
||||
cm.showHint({hint: this.getHint});
|
||||
},
|
||||
|
||||
getHint: function(cm, c) { return hint(this, cm, c); },
|
||||
|
||||
showType: function(cm, pos, c) { showType(this, cm, pos, c); },
|
||||
showType: function(cm, pos, cb) { showType(this, cm, pos, cb); },
|
||||
|
||||
updateArgHints: function(cm) { updateArgHints(this, cm); },
|
||||
|
||||
|
@ -106,6 +116,8 @@
|
|||
|
||||
rename: function(cm) { rename(this, cm); },
|
||||
|
||||
selectName: function(cm) { selectName(this, cm); },
|
||||
|
||||
request: function (cm, query, c, pos) {
|
||||
var self = this;
|
||||
var doc = findDoc(this, cm.getDoc());
|
||||
|
@ -145,6 +157,12 @@
|
|||
return ts.addDoc(name, doc);
|
||||
}
|
||||
|
||||
function resolveDoc(ts, id) {
|
||||
if (typeof id == "string") return ts.docs[id];
|
||||
if (id instanceof CodeMirror) id = id.getDoc();
|
||||
if (id instanceof CodeMirror.Doc) return findDoc(ts, id);
|
||||
}
|
||||
|
||||
function trackChange(ts, doc, change) {
|
||||
var data = findDoc(ts, doc);
|
||||
|
||||
|
@ -167,7 +185,7 @@
|
|||
|
||||
function sendDoc(ts, doc) {
|
||||
ts.server.request({files: [{type: "full", name: doc.name, text: docValue(ts, doc)}]}, function(error) {
|
||||
if (error) console.error(error);
|
||||
if (error) window.console.error(error);
|
||||
else doc.changed = null;
|
||||
});
|
||||
}
|
||||
|
@ -221,13 +239,13 @@
|
|||
|
||||
// Type queries
|
||||
|
||||
function showType(ts, cm, pos, c) {
|
||||
function showType(ts, cm, pos, cb) {
|
||||
ts.request(cm, "type", function(error, data) {
|
||||
if (error) return showError(ts, cm, error);
|
||||
if (ts.options.typeTip) {
|
||||
var tip = ts.options.typeTip(data);
|
||||
} else {
|
||||
var tip = elt("span", cls + "information", elt("strong", null, data.type || "not found"));
|
||||
var tip = elt("span", null, elt("strong", null, data.type || "not found"));
|
||||
if (data.doc)
|
||||
tip.appendChild(document.createTextNode(" — " + data.doc));
|
||||
if (data.url) {
|
||||
|
@ -236,7 +254,7 @@
|
|||
}
|
||||
}
|
||||
tempTooltip(cm, tip);
|
||||
c && c(tip);
|
||||
if (cb) cb();
|
||||
}, pos);
|
||||
}
|
||||
|
||||
|
@ -373,10 +391,10 @@
|
|||
}
|
||||
|
||||
function moveTo(ts, curDoc, doc, start, end) {
|
||||
doc.doc.setSelection(end, start);
|
||||
doc.doc.setSelection(start, end);
|
||||
if (curDoc != doc && ts.options.switchToDoc) {
|
||||
closeArgHints(ts);
|
||||
ts.options.switchToDoc(doc.name);
|
||||
ts.options.switchToDoc(doc.name, doc.doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,7 +439,7 @@
|
|||
|
||||
function rename(ts, cm) {
|
||||
var token = cm.getTokenAt(cm.getCursor());
|
||||
if (!/\w/.test(token.string)) showError(ts, cm, "Not at a variable");
|
||||
if (!/\w/.test(token.string)) return showError(ts, cm, "Not at a variable");
|
||||
dialog(cm, "New name for " + token.string, function(newName) {
|
||||
ts.request(cm, {type: "rename", newName: newName, fullDocs: true}, function(error, data) {
|
||||
if (error) return showError(ts, cm, error);
|
||||
|
@ -430,6 +448,23 @@
|
|||
});
|
||||
}
|
||||
|
||||
function selectName(ts, cm) {
|
||||
var name = findDoc(ts, cm.doc).name;
|
||||
ts.request(cm, {type: "refs"}, function(error, data) {
|
||||
if (error) return showError(ts, cm, error);
|
||||
var ranges = [], cur = 0;
|
||||
for (var i = 0; i < data.refs.length; i++) {
|
||||
var ref = data.refs[i];
|
||||
if (ref.file == name) {
|
||||
ranges.push({anchor: ref.start, head: ref.end});
|
||||
if (cmpPos(cur, ref.start) >= 0 && cmpPos(cur, ref.end) <= 0)
|
||||
cur = ranges.length - 1;
|
||||
}
|
||||
}
|
||||
cm.setSelections(ranges, cur);
|
||||
});
|
||||
}
|
||||
|
||||
var nextChangeOrig = 0;
|
||||
function applyChanges(ts, changes) {
|
||||
var perFile = Object.create(null);
|
||||
|
@ -522,7 +557,7 @@
|
|||
|
||||
// Generic utilities
|
||||
|
||||
function cmpPos(a, b) { return a.line - b.line || a.ch - b.ch; }
|
||||
var cmpPos = CodeMirror.cmpPos;
|
||||
|
||||
function elt(tagname, cls /*, ... elts*/) {
|
||||
var e = document.createElement(tagname);
|
||||
|
@ -615,7 +650,7 @@
|
|||
send({type: "getFile", err: String(err), text: text, id: data.id});
|
||||
});
|
||||
} else if (data.type == "debug") {
|
||||
console.log(data.message);
|
||||
window.console.log(data.message);
|
||||
} else if (data.id && pending[data.id]) {
|
||||
pending[data.id](data.err, data.body);
|
||||
delete pending[data.id];
|
||||
|
@ -630,4 +665,4 @@
|
|||
this.delFile = function(name) { send({type: "del", name: name}); };
|
||||
this.request = function(body, c) { send({type: "req", body: body}, c); };
|
||||
}
|
||||
})();
|
||||
});
|
|
@ -28,13 +28,13 @@ namespace = "comment_";
|
|||
cm.uncomment(Pos(0, 0), Pos(2, 1));
|
||||
}, simpleProg, simpleProg);
|
||||
|
||||
// test("fallbackToBlock", "css", function(cm) {
|
||||
// cm.lineComment(Pos(0, 0), Pos(2, 1));
|
||||
// }, "html {\n border: none;\n}", "/* html {\n border: none;\n} */");
|
||||
test("fallbackToBlock", "css", function(cm) {
|
||||
cm.lineComment(Pos(0, 0), Pos(2, 1));
|
||||
}, "html {\n border: none;\n}", "/* html {\n border: none;\n} */");
|
||||
|
||||
// test("fallbackToLine", "ruby", function(cm) {
|
||||
// cm.blockComment(Pos(0, 0), Pos(1));
|
||||
// }, "def blah()\n return hah\n", "# def blah()\n# return hah\n");
|
||||
test("fallbackToLine", "ruby", function(cm) {
|
||||
cm.blockComment(Pos(0, 0), Pos(1));
|
||||
}, "def blah()\n return hah\n", "# def blah()\n# return hah\n");
|
||||
|
||||
test("commentRange", "javascript", function(cm) {
|
||||
cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false});
|
||||
|
|
|
@ -320,6 +320,29 @@
|
|||
eq(cleared, 1);
|
||||
});
|
||||
|
||||
testDoc("sharedMarkerCopy", "A='abcde'", function(a) {
|
||||
var shared = a.markText(Pos(0, 1), Pos(0, 3), {shared: true});
|
||||
var b = a.linkedDoc();
|
||||
var found = b.findMarksAt(Pos(0, 2));
|
||||
eq(found.length, 1);
|
||||
eq(found[0], shared);
|
||||
shared.clear();
|
||||
eq(b.findMarksAt(Pos(0, 2)), 0);
|
||||
});
|
||||
|
||||
testDoc("sharedMarkerDetach", "A='abcde' B<A C<B", function(a, b, c) {
|
||||
var shared = a.markText(Pos(0, 1), Pos(0, 3), {shared: true});
|
||||
a.unlinkDoc(b);
|
||||
var inB = b.findMarksAt(Pos(0, 2));
|
||||
eq(inB.length, 1);
|
||||
is(inB[0] != shared);
|
||||
var inC = c.findMarksAt(Pos(0, 2));
|
||||
eq(inC.length, 1);
|
||||
is(inC[0] != shared);
|
||||
inC[0].clear();
|
||||
is(shared.find());
|
||||
});
|
||||
|
||||
testDoc("sharedBookmark", "A='ab\ncd\nef\ngh' B<A C<~A/1-2", function(a, b, c) {
|
||||
var mark = b.setBookmark(Pos(1, 1), {shared: true});
|
||||
var found = a.findMarksAt(Pos(1, 1));
|
||||
|
|
|
@ -108,10 +108,10 @@
|
|||
|
||||
sim("openLine", "foo bar", "Alt-F", "Ctrl-O", txt("foo\n bar"))
|
||||
|
||||
sim("transposeChar", "abcd\n\ne",
|
||||
"Ctrl-F", "Ctrl-T", "Ctrl-T", txt("bcad\n\ne"), at(0, 3),
|
||||
"Ctrl-F", "Ctrl-T", "Ctrl-T", "Ctrl-T", txt("bcda\n\ne"), at(0, 4),
|
||||
"Ctrl-F", "Ctrl-T", txt("bcd\na\ne"), at(1, 1));
|
||||
sim("transposeChar", "abcd\ne",
|
||||
"Ctrl-F", "Ctrl-T", "Ctrl-T", txt("bcad\ne"), at(0, 3),
|
||||
"Ctrl-F", "Ctrl-T", "Ctrl-T", "Ctrl-T", txt("bcda\ne"), at(0, 4),
|
||||
"Ctrl-F", "Ctrl-T", txt("bcde\na"), at(1, 0));
|
||||
|
||||
sim("manipWordCase", "foo BAR bAZ",
|
||||
"Alt-C", "Alt-L", "Alt-U", txt("Foo bar BAZ"),
|
||||
|
|
|
@ -8,3 +8,16 @@
|
|||
.mt-output .mt-style {
|
||||
font-size: x-small;
|
||||
}
|
||||
|
||||
.mt-output .mt-state {
|
||||
font-size: x-small;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.mt-output .mt-state-row {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mt-state-unhide .mt-output .mt-state-row {
|
||||
display: table-row;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
pos = end;
|
||||
}
|
||||
text = text.replace(/\[\[|\]\]/g, function(s) {return s.charAt(0);});
|
||||
tokens.push(style, text);
|
||||
tokens.push({style: style, text: text});
|
||||
plain += text;
|
||||
}
|
||||
}
|
||||
|
@ -67,16 +67,17 @@
|
|||
};
|
||||
|
||||
function esc(str) {
|
||||
return str.replace('&', '&').replace('<', '<');
|
||||
return str.replace('&', '&').replace('<', '<').replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||||
;
|
||||
}
|
||||
|
||||
function compare(text, expected, mode) {
|
||||
|
||||
var expectedOutput = [];
|
||||
for (var i = 0; i < expected.length; i += 2) {
|
||||
var sty = expected[i];
|
||||
for (var i = 0; i < expected.length; ++i) {
|
||||
var sty = expected[i].style;
|
||||
if (sty && sty.indexOf(" ")) sty = sty.split(' ').sort().join(' ');
|
||||
expectedOutput.push(sty, expected[i + 1]);
|
||||
expectedOutput.push({style: sty, text: expected[i].text});
|
||||
}
|
||||
|
||||
var observedOutput = highlight(text, mode);
|
||||
|
@ -89,7 +90,7 @@
|
|||
s += '<div class="cm-s-default">';
|
||||
s += 'expected:';
|
||||
s += prettyPrintOutputTable(expectedOutput, diff);
|
||||
s += 'observed:';
|
||||
s += 'observed: [<a onclick="this.parentElement.className+=\' mt-state-unhide\'">display states</a>]';
|
||||
s += prettyPrintOutputTable(observedOutput, diff);
|
||||
s += '</div>';
|
||||
s += '</div>';
|
||||
|
@ -101,8 +102,21 @@
|
|||
if (s) throw new Failure(s);
|
||||
}
|
||||
|
||||
function stringify(obj) {
|
||||
function replacer(key, obj) {
|
||||
if (typeof obj == "function") {
|
||||
var m = obj.toString().match(/function\s*[^\s(]*/);
|
||||
return m ? m[0] : "function";
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
if (window.JSON && JSON.stringify)
|
||||
return JSON.stringify(obj, replacer, 2);
|
||||
return "[unsupported]"; // Fail safely if no native JSON.
|
||||
}
|
||||
|
||||
function highlight(string, mode) {
|
||||
var state = mode.startState()
|
||||
var state = mode.startState();
|
||||
|
||||
var lines = string.replace(/\r\n/g,'\n').split('\n');
|
||||
var st = [], pos = 0;
|
||||
|
@ -119,17 +133,21 @@
|
|||
if (line == "" && mode.blankLine) mode.blankLine(state);
|
||||
/* Start copied code from CodeMirror.highlight */
|
||||
while (!stream.eol()) {
|
||||
var compare = mode.token(stream, state), substr = stream.current();
|
||||
for (var j = 0; j < 10 && stream.start >= stream.pos; j++)
|
||||
var compare = mode.token(stream, state);
|
||||
if (j == 10)
|
||||
throw new Failure("Failed to advance the stream." + stream.string + " " + stream.pos);
|
||||
var substr = stream.current();
|
||||
if (compare && compare.indexOf(" ") > -1) compare = compare.split(' ').sort().join(' ');
|
||||
stream.start = stream.pos;
|
||||
if (pos && st[pos-2] == compare && !newLine) {
|
||||
st[pos-1] += substr;
|
||||
if (pos && st[pos-1].style == compare && !newLine) {
|
||||
st[pos-1].text += substr;
|
||||
} else if (substr) {
|
||||
st[pos++] = compare; st[pos++] = substr;
|
||||
st[pos++] = {style: compare, text: substr, state: stringify(state)};
|
||||
}
|
||||
// Give up when line is ridiculously long
|
||||
if (stream.pos > 5000) {
|
||||
st[pos++] = null; st[pos++] = this.text.slice(stream.pos);
|
||||
st[pos++] = {style: null, text: this.text.slice(stream.pos)};
|
||||
break;
|
||||
}
|
||||
newLine = false;
|
||||
|
@ -142,27 +160,33 @@
|
|||
function highlightOutputsDifferent(o1, o2) {
|
||||
var minLen = Math.min(o1.length, o2.length);
|
||||
for (var i = 0; i < minLen; ++i)
|
||||
if (o1[i] != o2[i]) return i >> 1;
|
||||
if (o1[i].style != o2[i].style || o1[i].text != o2[i].text) return i;
|
||||
if (o1.length > minLen || o2.length > minLen) return minLen;
|
||||
}
|
||||
|
||||
function prettyPrintOutputTable(output, diffAt) {
|
||||
var s = '<table class="mt-output">';
|
||||
s += '<tr>';
|
||||
for (var i = 0; i < output.length; i += 2) {
|
||||
var style = output[i], val = output[i+1];
|
||||
for (var i = 0; i < output.length; ++i) {
|
||||
var style = output[i].style, val = output[i].text;
|
||||
s +=
|
||||
'<td class="mt-token"' + (i == diffAt * 2 ? " style='background: pink'" : "") + '>' +
|
||||
'<span class="cm-' + esc(String(style)) + '">' +
|
||||
esc(val.replace(/ /g,'\xb7')) +
|
||||
esc(val.replace(/ /g,'\xb7')) + // · MIDDLE DOT
|
||||
'</span>' +
|
||||
'</td>';
|
||||
}
|
||||
s += '</tr><tr>';
|
||||
for (var i = 0; i < output.length; i += 2) {
|
||||
s += '<td class="mt-style"><span>' + (output[i] || null) + '</span></td>';
|
||||
for (var i = 0; i < output.length; ++i) {
|
||||
s += '<td class="mt-style"><span>' + (output[i].style || null) + '</span></td>';
|
||||
}
|
||||
s += '</table>';
|
||||
if(output[0].state) {
|
||||
s += '</tr><tr class="mt-state-row" title="State AFTER each token">';
|
||||
for (var i = 0; i < output.length; ++i) {
|
||||
s += '<td class="mt-state"><pre>' + esc(output[i].state) + '</pre></td>';
|
||||
}
|
||||
}
|
||||
s += '</tr></table>';
|
||||
return s;
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -178,6 +178,12 @@
|
|||
1, 0, 2, 0,
|
||||
2, 2, 2, 2));
|
||||
|
||||
stTest("swapLineEmptyBottomSel", "1\n2\n3",
|
||||
setSel(0, 1, 1, 0),
|
||||
"swapLineDown", val("2\n1\n3"), hasSel(1, 1, 2, 0),
|
||||
"swapLineUp", val("1\n2\n3"), hasSel(0, 1, 1, 0),
|
||||
"swapLineUp", val("1\n2\n3"), hasSel(0, 0, 0, 0));
|
||||
|
||||
stTest("swapLineUpFromEnd", "a\nb\nc",
|
||||
Pos(2, 1), "swapLineUp",
|
||||
hasSel(1, 1, 1, 1), val("a\nc\nb"));
|
||||
|
|
|
@ -1548,6 +1548,19 @@ testCM("atomicMarker", function(cm) {
|
|||
eq(cm.getValue().length, 53, "del chunk");
|
||||
});
|
||||
|
||||
testCM("selectionBias", function(cm) {
|
||||
cm.markText(Pos(0, 1), Pos(0, 3), {atomic: true});
|
||||
cm.setCursor(Pos(0, 2));
|
||||
eqPos(cm.getCursor(), Pos(0, 3));
|
||||
cm.setCursor(Pos(0, 2));
|
||||
eqPos(cm.getCursor(), Pos(0, 1));
|
||||
cm.setCursor(Pos(0, 2), null, {bias: -1});
|
||||
eqPos(cm.getCursor(), Pos(0, 1));
|
||||
cm.setCursor(Pos(0, 4));
|
||||
cm.setCursor(Pos(0, 2), null, {bias: 1});
|
||||
eqPos(cm.getCursor(), Pos(0, 3), "A");
|
||||
}, {value: "12345"});
|
||||
|
||||
testCM("readOnlyMarker", function(cm) {
|
||||
function mark(ll, cl, lr, cr, at) {
|
||||
return cm.markText(Pos(ll, cl), Pos(lr, cr),
|
||||
|
@ -1776,6 +1789,20 @@ testCM("lineStyleFromMode", function(cm) {
|
|||
is(/^\s*cm-span\s*$/.test(spanElts[0].className));
|
||||
}, {value: "line1: [br] [br]\nline2: (par) (par)\nline3: <tag> <tag>"});
|
||||
|
||||
testCM("lineStyleFromBlankLine", function(cm) {
|
||||
CodeMirror.defineMode("lineStyleFromBlankLine_mode", function() {
|
||||
return {token: function(stream) { stream.skipToEnd(); return "comment"; },
|
||||
blankLine: function() { return "line-blank"; }};
|
||||
});
|
||||
cm.setOption("mode", "lineStyleFromBlankLine_mode");
|
||||
var blankElts = byClassName(cm.getWrapperElement(), "blank");
|
||||
eq(blankElts.length, 1);
|
||||
eq(blankElts[0].nodeName, "PRE");
|
||||
cm.replaceRange("x", Pos(1, 0));
|
||||
blankElts = byClassName(cm.getWrapperElement(), "blank");
|
||||
eq(blankElts.length, 0);
|
||||
}, {value: "foo\n\nbar"});
|
||||
|
||||
CodeMirror.registerHelper("xxx", "a", "A");
|
||||
CodeMirror.registerHelper("xxx", "b", "B");
|
||||
CodeMirror.defineMode("yyy", function() {
|
||||
|
@ -1876,3 +1903,16 @@ testCM("alwaysMergeSelEventWithChangeOrigin", function(cm) {
|
|||
cm.undoSelection();
|
||||
eq(cm.getValue(), "Va");
|
||||
}, {value: "a"});
|
||||
|
||||
testCM("getTokenTypeAt", function(cm) {
|
||||
eq(cm.getTokenTypeAt(Pos(0, 0)), "number");
|
||||
eq(cm.getTokenTypeAt(Pos(0, 6)), "string");
|
||||
cm.addOverlay({
|
||||
token: function(stream) {
|
||||
if (stream.match("foo")) return "foo";
|
||||
else stream.next();
|
||||
}
|
||||
});
|
||||
eq(byClassName(cm.getWrapperElement(), "cm-foo").length, 1);
|
||||
eq(cm.getTokenTypeAt(Pos(0, 6)), "string");
|
||||
}, {value: "1 + 'foo'", mode: "javascript"});
|
||||
|
|
|
@ -98,7 +98,7 @@ function copyCursor(cur) {
|
|||
|
||||
function forEach(arr, func) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
func(arr[i]);
|
||||
func(arr[i], i, arr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ testJumplist('jumplist_gg', ['g', 'g', '<C-o>'], [5,2], [5,2]);
|
|||
testJumplist('jumplist_%', ['%', '<C-o>'], [1,5], [1,5]);
|
||||
testJumplist('jumplist_{', ['{', '<C-o>'], [1,5], [1,5]);
|
||||
testJumplist('jumplist_}', ['}', '<C-o>'], [1,5], [1,5]);
|
||||
testJumplist('jumplist_\'', ['m', 'a', 'h', '\'', 'a', 'h', '<C-i>'], [1,5], [1,5]);
|
||||
testJumplist('jumplist_\'', ['m', 'a', 'h', '\'', 'a', 'h', '<C-i>'], [1,0], [1,5]);
|
||||
testJumplist('jumplist_`', ['m', 'a', 'h', '`', 'a', 'h', '<C-i>'], [1,5], [1,5]);
|
||||
testJumplist('jumplist_*_cachedCursor', ['*', '<C-o>'], [1,3], [1,3]);
|
||||
testJumplist('jumplist_#_cachedCursor', ['#', '<C-o>'], [1,3], [1,3]);
|
||||
|
@ -1015,6 +1015,7 @@ testEdit('daW_end_punct', 'foo \tbAr.', /A/, 'daW', 'foo');
|
|||
// Open and close on same line
|
||||
testEdit('di(_open_spc', 'foo (bAr) baz', /\(/, 'di(', 'foo () baz');
|
||||
testEdit('di)_open_spc', 'foo (bAr) baz', /\(/, 'di)', 'foo () baz');
|
||||
testEdit('dib_open_spc', 'foo (bAr) baz', /\(/, 'dib', 'foo () baz');
|
||||
testEdit('da(_open_spc', 'foo (bAr) baz', /\(/, 'da(', 'foo baz');
|
||||
testEdit('da)_open_spc', 'foo (bAr) baz', /\(/, 'da)', 'foo baz');
|
||||
|
||||
|
@ -1028,11 +1029,26 @@ testEdit('di)_close_spc', 'foo (bAr) baz', /\)/, 'di)', 'foo () baz');
|
|||
testEdit('da(_close_spc', 'foo (bAr) baz', /\)/, 'da(', 'foo baz');
|
||||
testEdit('da)_close_spc', 'foo (bAr) baz', /\)/, 'da)', 'foo baz');
|
||||
|
||||
// delete around and inner b.
|
||||
testEdit('dab_on_(_should_delete_around_()block', 'o( in(abc) )', /\(a/, 'dab', 'o( in )');
|
||||
|
||||
// delete around and inner B.
|
||||
testEdit('daB_on_{_should_delete_around_{}block', 'o{ in{abc} }', /{a/, 'daB', 'o{ in }');
|
||||
testEdit('diB_on_{_should_delete_inner_{}block', 'o{ in{abc} }', /{a/, 'diB', 'o{ in{} }');
|
||||
|
||||
testEdit('da{_on_{_should_delete_inner_block', 'o{ in{abc} }', /{a/, 'da{', 'o{ in }');
|
||||
testEdit('di[_on_(_should_not_delete', 'foo (bAr) baz', /\(/, 'di[', 'foo (bAr) baz');
|
||||
testEdit('di[_on_)_should_not_delete', 'foo (bAr) baz', /\)/, 'di[', 'foo (bAr) baz');
|
||||
testEdit('da[_on_(_should_not_delete', 'foo (bAr) baz', /\(/, 'da[', 'foo (bAr) baz');
|
||||
testEdit('da[_on_)_should_not_delete', 'foo (bAr) baz', /\)/, 'da[', 'foo (bAr) baz');
|
||||
testMotion('di(_outside_should_stay', ['d', 'i', '('], { line: 0, ch: 0}, { line: 0, ch: 0});
|
||||
|
||||
// Open and close on different lines, equally indented
|
||||
testEdit('di{_middle_spc', 'a{\n\tbar\n}b', /r/, 'di{', 'a{}b');
|
||||
testEdit('di}_middle_spc', 'a{\n\tbar\n}b', /r/, 'di}', 'a{}b');
|
||||
testEdit('da{_middle_spc', 'a{\n\tbar\n}b', /r/, 'da{', 'ab');
|
||||
testEdit('da}_middle_spc', 'a{\n\tbar\n}b', /r/, 'da}', 'ab');
|
||||
testEdit('daB_middle_spc', 'a{\n\tbar\n}b', /r/, 'daB', 'ab');
|
||||
|
||||
// open and close on diff lines, open indented less than close
|
||||
testEdit('di{_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'di{', 'a{}b');
|
||||
|
@ -1125,6 +1141,13 @@ testVim('a_eol', function(cm, vim, helpers) {
|
|||
helpers.assertCursorAt(0, lines[0].length);
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
});
|
||||
testVim('a_endOfSelectedArea', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('v', 'j', 'l');
|
||||
helpers.doKeys('A');
|
||||
helpers.assertCursorAt(1, 2);
|
||||
eq('vim-insert', cm.getOption('keyMap'));
|
||||
}, {value: 'foo\nbar'});
|
||||
testVim('i', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.doKeys('i');
|
||||
|
@ -1236,6 +1259,31 @@ testVim('p_lastline', function(cm, vim, helpers) {
|
|||
eq('___\n a\nd\n a\nd', cm.getValue());
|
||||
helpers.assertCursorAt(1, 2);
|
||||
}, { value: '___' });
|
||||
testVim(']p_first_indent_is_smaller', function(cm, vim, helpers) {
|
||||
helpers.getRegisterController().pushText('"', 'yank', ' abc\n def\n', true);
|
||||
helpers.doKeys(']', 'p');
|
||||
eq(' ___\n abc\n def', cm.getValue());
|
||||
}, { value: ' ___' });
|
||||
testVim(']p_first_indent_is_larger', function(cm, vim, helpers) {
|
||||
helpers.getRegisterController().pushText('"', 'yank', ' abc\n def\n', true);
|
||||
helpers.doKeys(']', 'p');
|
||||
eq(' ___\n abc\ndef', cm.getValue());
|
||||
}, { value: ' ___' });
|
||||
testVim(']p_with_tab_indents', function(cm, vim, helpers) {
|
||||
helpers.getRegisterController().pushText('"', 'yank', '\t\tabc\n\t\t\tdef\n', true);
|
||||
helpers.doKeys(']', 'p');
|
||||
eq('\t___\n\tabc\n\t\tdef', cm.getValue());
|
||||
}, { value: '\t___', indentWithTabs: true});
|
||||
testVim(']p_with_spaces_translated_to_tabs', function(cm, vim, helpers) {
|
||||
helpers.getRegisterController().pushText('"', 'yank', ' abc\n def\n', true);
|
||||
helpers.doKeys(']', 'p');
|
||||
eq('\t___\n\tabc\n\t\tdef', cm.getValue());
|
||||
}, { value: '\t___', indentWithTabs: true, tabSize: 2 });
|
||||
testVim('[p', function(cm, vim, helpers) {
|
||||
helpers.getRegisterController().pushText('"', 'yank', ' abc\n def\n', true);
|
||||
helpers.doKeys('[', 'p');
|
||||
eq(' abc\n def\n ___', cm.getValue());
|
||||
}, { value: ' ___' });
|
||||
testVim('P', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false);
|
||||
|
@ -1270,11 +1318,13 @@ testVim('mark', function(cm, vim, helpers) {
|
|||
cm.setCursor(2, 2);
|
||||
helpers.doKeys('m', 't');
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('\'', 't');
|
||||
helpers.assertCursorAt(2, 2);
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('`', 't');
|
||||
helpers.assertCursorAt(2, 2);
|
||||
cm.setCursor(2, 0);
|
||||
cm.replaceRange(' h', cm.getCursor());
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('\'', 't');
|
||||
helpers.assertCursorAt(2, 3);
|
||||
});
|
||||
testVim('jumpToMark_next', function(cm, vim, helpers) {
|
||||
cm.setCursor(2, 2);
|
||||
|
@ -1524,13 +1574,13 @@ testVim('visual_line', function(cm, vim, helpers) {
|
|||
eq(' 4\n 5', cm.getValue());
|
||||
}, { value: ' 1\n 2\n 3\n 4\n 5' });
|
||||
testVim('visual_marks', function(cm, vim, helpers) {
|
||||
helpers.doKeys('l', 'v', 'l', 'l', 'v');
|
||||
helpers.doKeys('l', 'v', 'l', 'l', 'j', 'j', 'v');
|
||||
// Test visual mode marks
|
||||
cm.setCursor(0, 0);
|
||||
cm.setCursor(2, 1);
|
||||
helpers.doKeys('\'', '<');
|
||||
helpers.assertCursorAt(0, 1);
|
||||
helpers.doKeys('\'', '>');
|
||||
helpers.assertCursorAt(0, 3);
|
||||
helpers.assertCursorAt(2, 0);
|
||||
});
|
||||
testVim('visual_join', function(cm, vim, helpers) {
|
||||
helpers.doKeys('l', 'V', 'l', 'j', 'j', 'J');
|
||||
|
@ -1577,7 +1627,50 @@ testVim('o_visual', function(cm,vim,helpers) {
|
|||
helpers.doKeys('d');
|
||||
eq('p',cm.getValue());
|
||||
}, { value: 'abcd\nefgh\nijkl\nmnop'});
|
||||
testVim('uppercase/lowercase_visual', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('v', 'l', 'l');
|
||||
helpers.doKeys('U');
|
||||
helpers.assertCursorAt(0, 0);
|
||||
helpers.doKeys('v', 'l', 'l');
|
||||
helpers.doKeys('u');
|
||||
helpers.assertCursorAt(0, 0);
|
||||
helpers.doKeys('l', 'l', 'l', '.');
|
||||
helpers.assertCursorAt(0, 3);
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('q', 'a', 'v', 'j', 'U', 'q');
|
||||
helpers.assertCursorAt(0, 0);
|
||||
helpers.doKeys('j', '@', 'a');
|
||||
helpers.assertCursorAt(1, 0);
|
||||
cm.setCursor(3, 0);
|
||||
helpers.doKeys('V', 'U', 'j', '.');
|
||||
eq('ABCDEF\nGHIJKL\nMnopq\nSHORT LINE\nLONG LINE OF TEXT', cm.getValue());
|
||||
}, { value: 'abcdef\nghijkl\nmnopq\nshort line\nlong line of text'});
|
||||
testVim('visual_paste', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('v', 'l', 'l', 'y', 'j', 'v', 'l', 'p');
|
||||
helpers.assertCursorAt(1, 4);
|
||||
eq('this is a\nunthi test for visual paste', cm.getValue());
|
||||
cm.setCursor(0, 0);
|
||||
// in case of pasting whole line
|
||||
helpers.doKeys('y', 'y');
|
||||
cm.setCursor(1, 6);
|
||||
helpers.doKeys('v', 'l', 'l', 'l', 'p');
|
||||
helpers.assertCursorAt(2, 0);
|
||||
eq('this is a\nunthi \nthis is a\n for visual paste', cm.getValue());
|
||||
}, { value: 'this is a\nunit test for visual paste'});
|
||||
|
||||
// This checks the contents of the register used to paste the text
|
||||
testVim('v_paste_from_register', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('"', 'a', 'y', 'w');
|
||||
cm.setCursor(1, 0);
|
||||
helpers.doKeys('v', 'p');
|
||||
cm.openDialog = helpers.fakeOpenDialog('registers');
|
||||
cm.openNotification = helpers.fakeOpenNotification(function(text) {
|
||||
is(/a\s+register/.test(text));
|
||||
});
|
||||
}, { value: 'register contents\nare not erased'});
|
||||
testVim('S_normal', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 1);
|
||||
helpers.doKeys('j', 'S');
|
||||
|
@ -1750,6 +1843,22 @@ testVim('#', function(cm, vim, helpers) {
|
|||
helpers.doKeys('#');
|
||||
helpers.assertCursorAt(1, 8);
|
||||
}, { value: ' := match nomatch match \nnomatch Match' });
|
||||
testVim('g*', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 8);
|
||||
helpers.doKeys('g', '*');
|
||||
helpers.assertCursorAt(0, 18);
|
||||
cm.setCursor(0, 8);
|
||||
helpers.doKeys('3', 'g', '*');
|
||||
helpers.assertCursorAt(1, 8);
|
||||
}, { value: 'matches match alsoMatch\nmatchme matching' });
|
||||
testVim('g#', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 8);
|
||||
helpers.doKeys('g', '#');
|
||||
helpers.assertCursorAt(0, 0);
|
||||
cm.setCursor(0, 8);
|
||||
helpers.doKeys('3', 'g', '#');
|
||||
helpers.assertCursorAt(1, 0);
|
||||
}, { value: 'matches match alsoMatch\nmatchme matching' });
|
||||
testVim('macro_insert', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('q', 'a', '0', 'i');
|
||||
|
@ -1769,6 +1878,46 @@ testVim('macro_space', function(cm, vim, helpers) {
|
|||
helpers.doKeys('@', 'a');
|
||||
helpers.assertCursorAt(0, 8);
|
||||
}, { value: 'one line of text.'});
|
||||
testVim('macro_t_search', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('q', 'a', 't', 'e', 'q');
|
||||
helpers.assertCursorAt(0, 1);
|
||||
helpers.doKeys('l', '@', 'a');
|
||||
helpers.assertCursorAt(0, 6);
|
||||
helpers.doKeys('l', ';');
|
||||
helpers.assertCursorAt(0, 12);
|
||||
}, { value: 'one line of text.'});
|
||||
testVim('macro_f_search', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('q', 'b', 'f', 'e', 'q');
|
||||
helpers.assertCursorAt(0, 2);
|
||||
helpers.doKeys('@', 'b');
|
||||
helpers.assertCursorAt(0, 7);
|
||||
helpers.doKeys(';');
|
||||
helpers.assertCursorAt(0, 13);
|
||||
}, { value: 'one line of text.'});
|
||||
testVim('macro_slash_search', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('q', 'c');
|
||||
cm.openDialog = helpers.fakeOpenDialog('e');
|
||||
helpers.doKeys('/', 'q');
|
||||
helpers.assertCursorAt(0, 2);
|
||||
helpers.doKeys('@', 'c');
|
||||
helpers.assertCursorAt(0, 7);
|
||||
helpers.doKeys('n');
|
||||
helpers.assertCursorAt(0, 13);
|
||||
}, { value: 'one line of text.'});
|
||||
testVim('macro_multislash_search', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('q', 'd');
|
||||
cm.openDialog = helpers.fakeOpenDialog('e');
|
||||
helpers.doKeys('/');
|
||||
cm.openDialog = helpers.fakeOpenDialog('t');
|
||||
helpers.doKeys('/', 'q');
|
||||
helpers.assertCursorAt(0, 12);
|
||||
helpers.doKeys('@', 'd');
|
||||
helpers.assertCursorAt(0, 15);
|
||||
}, { value: 'one line of text to rule them all.'});
|
||||
testVim('macro_parens', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('q', 'z', 'i');
|
||||
|
@ -1827,6 +1976,50 @@ testVim('yank_register', function(cm, vim, helpers) {
|
|||
});
|
||||
helpers.doKeys(':');
|
||||
}, { value: 'foo\nbar'});
|
||||
testVim('yank_append_line_to_line_register', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('"', 'a', 'y', 'y');
|
||||
helpers.doKeys('j', '"', 'A', 'y', 'y');
|
||||
cm.openDialog = helpers.fakeOpenDialog('registers');
|
||||
cm.openNotification = helpers.fakeOpenNotification(function(text) {
|
||||
is(/a\s+foo\nbar/.test(text));
|
||||
is(/"\s+foo\nbar/.test(text));
|
||||
});
|
||||
helpers.doKeys(':');
|
||||
}, { value: 'foo\nbar'});
|
||||
testVim('yank_append_word_to_word_register', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('"', 'a', 'y', 'w');
|
||||
helpers.doKeys('j', '"', 'A', 'y', 'w');
|
||||
cm.openDialog = helpers.fakeOpenDialog('registers');
|
||||
cm.openNotification = helpers.fakeOpenNotification(function(text) {
|
||||
is(/a\s+foobar/.test(text));
|
||||
is(/"\s+foobar/.test(text));
|
||||
});
|
||||
helpers.doKeys(':');
|
||||
}, { value: 'foo\nbar'});
|
||||
testVim('yank_append_line_to_word_register', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('"', 'a', 'y', 'w');
|
||||
helpers.doKeys('j', '"', 'A', 'y', 'y');
|
||||
cm.openDialog = helpers.fakeOpenDialog('registers');
|
||||
cm.openNotification = helpers.fakeOpenNotification(function(text) {
|
||||
is(/a\s+foo\nbar/.test(text));
|
||||
is(/"\s+foo\nbar/.test(text));
|
||||
});
|
||||
helpers.doKeys(':');
|
||||
}, { value: 'foo\nbar'});
|
||||
testVim('yank_append_word_to_line_register', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('"', 'a', 'y', 'y');
|
||||
helpers.doKeys('j', '"', 'A', 'y', 'w');
|
||||
cm.openDialog = helpers.fakeOpenDialog('registers');
|
||||
cm.openNotification = helpers.fakeOpenNotification(function(text) {
|
||||
is(/a\s+foo\nbar/.test(text));
|
||||
is(/"\s+foo\nbar/.test(text));
|
||||
});
|
||||
helpers.doKeys(':');
|
||||
}, { value: 'foo\nbar'});
|
||||
testVim('macro_register', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('q', 'a', 'i');
|
||||
|
@ -1844,6 +2037,25 @@ testVim('macro_register', function(cm, vim, helpers) {
|
|||
});
|
||||
helpers.doKeys(':');
|
||||
}, { value: ''});
|
||||
testVim('._register', function(cm,vim,helpers) {
|
||||
cm.setCursor(0,0);
|
||||
helpers.doKeys('i');
|
||||
cm.replaceRange('foo',cm.getCursor());
|
||||
helpers.doInsertModeKeys('Esc');
|
||||
cm.openDialog = helpers.fakeOpenDialog('registers');
|
||||
cm.openNotification = helpers.fakeOpenNotification(function(text) {
|
||||
is(/\.\s+foo/.test(text));
|
||||
});
|
||||
helpers.doKeys(':');
|
||||
}, {value: ''});
|
||||
testVim(':_register', function(cm,vim,helpers) {
|
||||
helpers.doEx('bar');
|
||||
cm.openDialog = helpers.fakeOpenDialog('registers');
|
||||
cm.openNotification = helpers.fakeOpenNotification(function(text) {
|
||||
is(/:\s+bar/.test(text));
|
||||
});
|
||||
helpers.doKeys(':');
|
||||
}, {value: ''});
|
||||
testVim('.', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('2', 'd', 'w');
|
||||
|
@ -1947,6 +2159,14 @@ testVim('._delete_repeat', function(cm, vim, helpers) {
|
|||
eq('zzce', cm.getValue());
|
||||
helpers.assertCursorAt(0, 1);
|
||||
}, { value: 'zzabcde'});
|
||||
testVim('._visual_>', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('V', 'j', '>');
|
||||
cm.setCursor(2, 0)
|
||||
helpers.doKeys('.');
|
||||
eq(' 1\n 2\n 3\n 4', cm.getValue());
|
||||
helpers.assertCursorAt(2, 2);
|
||||
}, { value: '1\n2\n3\n4'});
|
||||
testVim('f;', function(cm, vim, helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doKeys('f', 'x');
|
||||
|
@ -2155,7 +2375,8 @@ testVim('HML', function(cm, vim, helpers) {
|
|||
return upper + lower;
|
||||
})()});
|
||||
|
||||
var zVals = ['zb','zz','zt','z-','z.','z<CR>'].map(function(e, idx){
|
||||
var zVals = [];
|
||||
forEach(['zb','zz','zt','z-','z.','z<CR>'], function(e, idx){
|
||||
var lineNum = 250;
|
||||
var lines = 35;
|
||||
testVim(e, function(cm, vim, helpers) {
|
||||
|
@ -2496,6 +2717,13 @@ testVim('ex_substitute_javascript', function(cm, vim, helpers) {
|
|||
helpers.doEx('s/\\(\\d+\\)/$$ $\' $` $& \\1/')
|
||||
eq('a $$ $\' $` $& 0 b', cm.getValue());
|
||||
}, { value: 'a 0 b' });
|
||||
testVim('ex_substitute_empty_arguments', function(cm,vim,helpers) {
|
||||
cm.setCursor(0, 0);
|
||||
helpers.doEx('s/a/b');
|
||||
cm.setCursor(1, 0);
|
||||
helpers.doEx('s');
|
||||
eq('b b\nb b', cm.getValue());
|
||||
}, {value: 'a a\na a'});
|
||||
|
||||
// More complex substitute tests that test both pcre and nopcre options.
|
||||
function testSubstitute(name, options) {
|
||||
|
@ -2857,3 +3085,5 @@ testVim('beforeSelectionChange', function(cm, vim, helpers) {
|
|||
cm.setCursor(0, 100);
|
||||
eqPos(cm.getCursor('head'), cm.getCursor('anchor'));
|
||||
}, { value: 'abc' });
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче