Merge pull request #1260 from ajaxorg/toggleComment
Improve toggleCommentLines and make it faster
This commit is contained in:
commit
1b8fb10e50
52 changed files with 371 additions and 774 deletions
|
|
@ -222,12 +222,12 @@ var EditSession = function(text, mode) {
|
||||||
this.$screenRowCache = [];
|
this.$screenRowCache = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
|
|
||||||
var l = this.$docRowCache.length;
|
var l = this.$docRowCache.length;
|
||||||
this.$docRowCache.splice(i, l);
|
var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
|
||||||
this.$screenRowCache.splice(i, l);
|
if (l > i) {
|
||||||
|
this.$docRowCache.splice(i, l);
|
||||||
|
this.$screenRowCache.splice(i, l);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$getRowCacheIndex = function(cacheArray, val) {
|
this.$getRowCacheIndex = function(cacheArray, val) {
|
||||||
|
|
@ -426,8 +426,7 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
self.$deltas = [];
|
self.$deltas = [];
|
||||||
}
|
}
|
||||||
this.$informUndoManager =
|
this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
|
||||||
lang.deferredCall(this.$syncInformUndoManager);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ function Folding() {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
this.getFoldsInRange = function(range) {
|
this.getFoldsInRange = function(range) {
|
||||||
range = range.clone();
|
|
||||||
var start = range.start;
|
var start = range.start;
|
||||||
var end = range.end;
|
var end = range.end;
|
||||||
var foldLines = this.$foldData;
|
var foldLines = this.$foldData;
|
||||||
|
|
@ -104,6 +103,9 @@ function Folding() {
|
||||||
foundFolds.push(fold);
|
foundFolds.push(fold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
start.column -= 1;
|
||||||
|
end.column += 1;
|
||||||
|
|
||||||
return foundFolds;
|
return foundFolds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -591,8 +591,9 @@ var Editor = function(renderer, session) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.onChangeMode = function() {
|
this.onChangeMode = function(e) {
|
||||||
this.renderer.updateText();
|
this.renderer.updateText();
|
||||||
|
this._emit("changeMode", e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -189,15 +189,15 @@ module.exports = {
|
||||||
editor.getSelection().selectDown();
|
editor.getSelection().selectDown();
|
||||||
editor.toggleCommentLines();
|
editor.toggleCommentLines();
|
||||||
|
|
||||||
assert.equal(["// abc", "//cde"].join("\n"), session.toString());
|
assert.equal(["// abc", "// cde"].join("\n"), session.toString());
|
||||||
|
|
||||||
var selection = editor.getSelectionRange();
|
var selection = editor.getSelectionRange();
|
||||||
assert.position(selection.start, 0, 4);
|
assert.position(selection.start, 0, 5);
|
||||||
assert.position(selection.end, 1, 4);
|
assert.position(selection.end, 1, 5);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: uncomment lines should perserve selection" : function() {
|
"test: uncomment lines should perserve selection" : function() {
|
||||||
var session = new EditSession(["// abc", "//cde"].join("\n"), new JavaScriptMode());
|
var session = new EditSession(["// abc", "//cde"].join("\n"), new JavaScriptMode());
|
||||||
var editor = new Editor(new MockRenderer(), session);
|
var editor = new Editor(new MockRenderer(), session);
|
||||||
|
|
||||||
editor.moveCursorTo(0, 1);
|
editor.moveCursorTo(0, 1);
|
||||||
|
|
@ -235,7 +235,7 @@ module.exports = {
|
||||||
editor.getSelection().selectDown();
|
editor.getSelection().selectDown();
|
||||||
|
|
||||||
editor.toggleCommentLines();
|
editor.toggleCommentLines();
|
||||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
assert.range(editor.getSelectionRange(), 0, 3, 1, 0);
|
||||||
|
|
||||||
// select up
|
// select up
|
||||||
var session = new EditSession(["abc", "cde"].join("\n"), new JavaScriptMode());
|
var session = new EditSession(["abc", "cde"].join("\n"), new JavaScriptMode());
|
||||||
|
|
@ -245,7 +245,7 @@ module.exports = {
|
||||||
editor.getSelection().selectUp();
|
editor.getSelection().selectUp();
|
||||||
|
|
||||||
editor.toggleCommentLines();
|
editor.toggleCommentLines();
|
||||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
assert.range(editor.getSelectionRange(), 0, 3, 1, 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: move lines down should select moved lines" : function() {
|
"test: move lines down should select moved lines" : function() {
|
||||||
|
|
|
||||||
|
|
@ -982,45 +982,6 @@ if (!Date.now) {
|
||||||
// ======
|
// ======
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
// ES5 15.5.4.14
|
|
||||||
// http://es5.github.com/#x15.5.4.14
|
|
||||||
// [bugfix, chrome]
|
|
||||||
// If separator is undefined, then the result array contains just one String,
|
|
||||||
// which is the this value (converted to a String). If limit is not undefined,
|
|
||||||
// then the output array is truncated so that it contains no more than limit
|
|
||||||
// elements.
|
|
||||||
// "0".split(undefined, 0) -> []
|
|
||||||
if("0".split(void 0, 0).length) {
|
|
||||||
var string_split = String.prototype.split;
|
|
||||||
String.prototype.split = function(separator, limit) {
|
|
||||||
if(separator === void 0 && limit === 0)return [];
|
|
||||||
return string_split.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ECMA-262, 3rd B.2.3
|
|
||||||
// Note an ECMAScript standart, although ECMAScript 3rd Edition has a
|
|
||||||
// non-normative section suggesting uniform semantics and it should be
|
|
||||||
// normalized across all browsers
|
|
||||||
// [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
|
|
||||||
if("".substr && "0b".substr(-1) !== "b") {
|
|
||||||
var string_substr = String.prototype.substr;
|
|
||||||
/**
|
|
||||||
* Get the substring of a string
|
|
||||||
* @param {integer} start where to start the substring
|
|
||||||
* @param {integer} length how many characters to return
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
String.prototype.substr = function(start, length) {
|
|
||||||
return string_substr.call(
|
|
||||||
this,
|
|
||||||
start < 0 ? (start = this.length + start) < 0 ? 0 : start : start,
|
|
||||||
length
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ES5 15.5.4.20
|
// ES5 15.5.4.20
|
||||||
// http://es5.github.com/#x15.5.4.20
|
// http://es5.github.com/#x15.5.4.20
|
||||||
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
||||||
|
|
@ -1033,12 +994,7 @@ if (!String.prototype.trim || ws.trim()) {
|
||||||
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
|
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
|
||||||
trimEndRegexp = new RegExp(ws + ws + "*$");
|
trimEndRegexp = new RegExp(ws + ws + "*$");
|
||||||
String.prototype.trim = function trim() {
|
String.prototype.trim = function trim() {
|
||||||
if (this === undefined || this === null) {
|
return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
|
||||||
throw new TypeError("can't convert "+this+" to object");
|
|
||||||
}
|
|
||||||
return String(this)
|
|
||||||
.replace(trimBeginRegexp, "")
|
|
||||||
.replace(trimEndRegexp, "");
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,34 +144,9 @@ exports.getMatchOffsets = function(string, regExp) {
|
||||||
|
|
||||||
/* deprecated */
|
/* deprecated */
|
||||||
exports.deferredCall = function(fcn) {
|
exports.deferredCall = function(fcn) {
|
||||||
|
if (typeof console != "undefined" && console.error)
|
||||||
var timer = null;
|
console.error("Deprecated: use lang.delayedCall")
|
||||||
var callback = function() {
|
return exports.delayedCall(fcn);
|
||||||
timer = null;
|
|
||||||
fcn();
|
|
||||||
};
|
|
||||||
|
|
||||||
var deferred = function(timeout) {
|
|
||||||
deferred.cancel();
|
|
||||||
timer = setTimeout(callback, timeout || 0);
|
|
||||||
return deferred;
|
|
||||||
};
|
|
||||||
|
|
||||||
deferred.schedule = deferred;
|
|
||||||
|
|
||||||
deferred.call = function() {
|
|
||||||
this.cancel();
|
|
||||||
fcn();
|
|
||||||
return deferred;
|
|
||||||
};
|
|
||||||
|
|
||||||
deferred.cancel = function() {
|
|
||||||
clearTimeout(timer);
|
|
||||||
timer = null;
|
|
||||||
return deferred;
|
|
||||||
};
|
|
||||||
|
|
||||||
return deferred;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,33 +50,8 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = "//";
|
||||||
var outdent = true;
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
var re = /^(\s*)\/\//;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "//");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -46,33 +46,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = ";";
|
||||||
var outdent = true;
|
|
||||||
var re = /^(\s*)#/;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, ";");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.lineCommentStart = "//";
|
||||||
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ oop.inherits(Mode, TextMode);
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.foldingRules = "cStyle";
|
this.foldingRules = "cStyle";
|
||||||
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here.
|
// Extra logic goes here.
|
||||||
|
this.lineCommentStart = "//";
|
||||||
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -18,33 +18,8 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = ["//", "#"];
|
||||||
var outdent = true;
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
var re = /^(\s*)\/\//;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "//");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -1,80 +1,55 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
var oop = require("../lib/oop");
|
var oop = require("../lib/oop");
|
||||||
var TextMode = require("./text").Mode;
|
var TextMode = require("./text").Mode;
|
||||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||||
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
|
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
|
||||||
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
||||||
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
||||||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||||
|
|
||||||
|
var Mode = function() {
|
||||||
|
this.$tokenizer = new Tokenizer(new GolangHighlightRules().getRules());
|
||||||
|
this.$outdent = new MatchingBraceOutdent();
|
||||||
|
this.foldingRules = new CStyleFoldMode();
|
||||||
|
};
|
||||||
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
var Mode = function() {
|
this.lineCommentStart = "//";
|
||||||
this.$tokenizer = new Tokenizer(new GolangHighlightRules().getRules());
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
this.$outdent = new MatchingBraceOutdent();
|
|
||||||
this.foldingRules = new CStyleFoldMode();
|
|
||||||
};
|
|
||||||
oop.inherits(Mode, TextMode);
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
|
||||||
var outdent = true;
|
|
||||||
var re = /^(\s*)\/\//;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
if (!re.test(doc.getLine(i))) {
|
var indent = this.$getIndent(line);
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
var tokens = tokenizedLine.tokens;
|
||||||
for (var i=startRow; i<= endRow; i++)
|
var endState = tokenizedLine.state;
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "//");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
|
||||||
var indent = this.$getIndent(line);
|
|
||||||
|
|
||||||
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
|
||||||
var tokens = tokenizedLine.tokens;
|
|
||||||
var endState = tokenizedLine.state;
|
|
||||||
|
|
||||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
|
||||||
return indent;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state == "start") {
|
|
||||||
var match = line.match(/^.*[\{\(\[]\s*$/);
|
|
||||||
if (match) {
|
|
||||||
indent += tab;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||||
return indent;
|
return indent;
|
||||||
};//end getNextLineIndent
|
}
|
||||||
|
|
||||||
|
if (state == "start") {
|
||||||
|
var match = line.match(/^.*[\{\(\[]\s*$/);
|
||||||
|
if (match) {
|
||||||
|
indent += tab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.checkOutdent = function(state, line, input) {
|
return indent;
|
||||||
return this.$outdent.checkOutdent(line, input);
|
};//end getNextLineIndent
|
||||||
};
|
|
||||||
|
|
||||||
this.autoOutdent = function(state, doc, row) {
|
this.checkOutdent = function(state, line, input) {
|
||||||
this.$outdent.autoOutdent(doc, row);
|
return this.$outdent.checkOutdent(line, input);
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
this.autoOutdent = function(state, doc, row) {
|
||||||
|
this.$outdent.autoOutdent(doc, row);
|
||||||
|
};
|
||||||
|
|
||||||
exports.Mode = Mode;
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
|
exports.Mode = Mode;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,8 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here.
|
this.lineCommentStart = ["//", "#"];
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,9 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
this.lineCommentStart = "//";
|
||||||
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.blockComment = {start: "<!--", end: "-->"};
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
return this.$getIndent(line);
|
return this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here.
|
// Extra logic goes here.
|
||||||
|
this.lineCommentStart = "//";
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
* Copyright (c) 2010, Ajax.org B.V.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
* * Neither the name of Ajax.org B.V. nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
|
@ -51,34 +51,8 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.lineCommentStart = "//";
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
var outdent = true;
|
|
||||||
var re = /^(\s*)\/\//;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "//");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
@ -90,7 +64,7 @@ oop.inherits(Mode, TextMode);
|
||||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||||
return indent;
|
return indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == "start" || state == "no_regex") {
|
if (state == "start" || state == "no_regex") {
|
||||||
var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
|
var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
|
|
@ -119,7 +93,7 @@ oop.inherits(Mode, TextMode);
|
||||||
this.autoOutdent = function(state, doc, row) {
|
this.autoOutdent = function(state, doc, row) {
|
||||||
this.$outdent.autoOutdent(doc, row);
|
this.$outdent.autoOutdent(doc, row);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createWorker = function(session) {
|
this.createWorker = function(session) {
|
||||||
var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
|
var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
|
||||||
worker.attachToDocument(session.getDocument());
|
worker.attachToDocument(session.getDocument());
|
||||||
|
|
@ -127,11 +101,11 @@ oop.inherits(Mode, TextMode);
|
||||||
worker.on("jslint", function(results) {
|
worker.on("jslint", function(results) {
|
||||||
session.setAnnotations(results.data);
|
session.setAnnotations(results.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.on("terminate", function() {
|
worker.on("terminate", function() {
|
||||||
session.clearAnnotations();
|
session.clearAnnotations();
|
||||||
});
|
});
|
||||||
|
|
||||||
return worker;
|
return worker;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,14 +58,14 @@ module.exports = {
|
||||||
var session = new EditSession([" abc", "cde", "fg"]);
|
var session = new EditSession([" abc", "cde", "fg"]);
|
||||||
|
|
||||||
this.mode.toggleCommentLines("start", session, 0, 1);
|
this.mode.toggleCommentLines("start", session, 0, 1);
|
||||||
assert.equal(["// abc", "//cde", "fg"].join("\n"), session.toString());
|
assert.equal(["// abc", "// cde", "fg"].join("\n"), session.toString());
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: toggle comment on commented lines should remove leading '//' chars" : function() {
|
"test: toggle comment on commented lines should remove leading '//' chars" : function() {
|
||||||
var session = new EditSession(["// abc", "//cde", "fg"]);
|
var session = new EditSession(["// abc", "//cde", "fg"]);
|
||||||
|
|
||||||
this.mode.toggleCommentLines("start", session, 0, 1);
|
this.mode.toggleCommentLines("start", session, 0, 1);
|
||||||
assert.equal([" abc", "cde", "fg"].join("\n"), session.toString());
|
assert.equal([" abc", "cde", "fg"].join("\n"), session.toString());
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: toggle comment lines twice should return the original text" : function() {
|
"test: toggle comment lines twice should return the original text" : function() {
|
||||||
|
|
@ -77,10 +77,10 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: toggle comment on multiple lines with one commented line prepend '//' to each line" : function() {
|
"test: toggle comment on multiple lines with one commented line prepend '//' to each line" : function() {
|
||||||
var session = new EditSession(["// abc", "//cde", "fg"]);
|
var session = new EditSession([" // abc", " //cde", " fg"]);
|
||||||
|
|
||||||
this.mode.toggleCommentLines("start", session, 0, 2);
|
this.mode.toggleCommentLines("start", session, 0, 2);
|
||||||
assert.equal(["//// abc", "////cde", "//fg"].join("\n"), session.toString());
|
assert.equal([" // // abc", " // //cde", " // fg"].join("\n"), session.toString());
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: toggle comment on a comment line with leading white space": function() {
|
"test: toggle comment on a comment line with leading white space": function() {
|
||||||
|
|
|
||||||
|
|
@ -19,33 +19,36 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.lineCommentStart = "//";
|
||||||
var indent = this.$getIndent(line);
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var tokens = tokenizedLine.tokens;
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
||||||
return indent;
|
var tokens = tokenizedLine.tokens;
|
||||||
}
|
|
||||||
|
|
||||||
if (state == "start") {
|
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||||
var match = line.match(/^.*[\{\(\[]\s*$/);
|
return indent;
|
||||||
if (match) {
|
}
|
||||||
indent += tab;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return indent;
|
if (state == "start") {
|
||||||
};
|
var match = line.match(/^.*[\{\(\[]\s*$/);
|
||||||
|
if (match) {
|
||||||
|
indent += tab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.checkOutdent = function(state, line, input) {
|
return indent;
|
||||||
return this.$outdent.checkOutdent(line, input);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
this.autoOutdent = function(state, doc, row) {
|
this.checkOutdent = function(state, line, input) {
|
||||||
this.$outdent.autoOutdent(doc, row);
|
return this.$outdent.checkOutdent(line, input);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.autoOutdent = function(state, doc, row) {
|
||||||
|
this.$outdent.autoOutdent(doc, row);
|
||||||
|
};
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,120 +1,120 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
var oop = require("../lib/oop");
|
var oop = require("../lib/oop");
|
||||||
var lang = require("../lib/lang");
|
var lang = require("../lib/lang");
|
||||||
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
|
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
|
||||||
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
||||||
|
|
||||||
|
var JsxHighlightRules = function() {
|
||||||
|
var keywords = lang.arrayToMap(
|
||||||
|
("break|do|instanceof|typeof|case|else|new|var|catch|finally|return|void|continue|for|switch|default|while|function|this|" +
|
||||||
|
"if|throw|" +
|
||||||
|
"delete|in|try|" +
|
||||||
|
"class|extends|super|import|from|into|implements|interface|static|mixin|override|abstract|final|" +
|
||||||
|
"number|int|string|boolean|variant|" +
|
||||||
|
"log|assert").split("|")
|
||||||
|
);
|
||||||
|
|
||||||
var JsxHighlightRules = function() {
|
var buildinConstants = lang.arrayToMap(
|
||||||
var keywords = lang.arrayToMap(
|
("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|")
|
||||||
("break|do|instanceof|typeof|case|else|new|var|catch|finally|return|void|continue|for|switch|default|while|function|this|" +
|
);
|
||||||
"if|throw|" +
|
|
||||||
"delete|in|try|" +
|
var reserved = lang.arrayToMap(
|
||||||
"class|extends|super|import|from|into|implements|interface|static|mixin|override|abstract|final|" +
|
("debugger|with|" +
|
||||||
"number|int|string|boolean|variant|" +
|
"const|export|" +
|
||||||
"log|assert").split("|")
|
"let|private|public|yield|protected|" +
|
||||||
);
|
"extern|native|as|operator|__fake__|__readonly__").split("|")
|
||||||
|
);
|
||||||
var buildinConstants = lang.arrayToMap(
|
|
||||||
("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|")
|
var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
|
||||||
);
|
|
||||||
|
this.$rules = {
|
||||||
var reserved = lang.arrayToMap(
|
"start" : [
|
||||||
("debugger|with|" +
|
{
|
||||||
"const|export|" +
|
token : "comment",
|
||||||
"let|private|public|yield|protected|" +
|
regex : "\\/\\/.*$"
|
||||||
"extern|native|as|operator|__fake__|__readonly__").split("|")
|
},
|
||||||
);
|
DocCommentHighlightRules.getStartRule("doc-start"),
|
||||||
|
{
|
||||||
var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
|
token : "comment", // multi line comment
|
||||||
|
regex : "\\/\\*",
|
||||||
this.$rules = {
|
next : "comment"
|
||||||
"start" : [
|
}, {
|
||||||
{
|
token : "string.regexp",
|
||||||
token : "comment",
|
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
||||||
regex : "\\/\\/.*$"
|
}, {
|
||||||
|
token : "string", // single line
|
||||||
|
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||||
|
}, {
|
||||||
|
token : "string", // single line
|
||||||
|
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
||||||
|
}, {
|
||||||
|
token : "constant.numeric", // hex
|
||||||
|
regex : "0[xX][0-9a-fA-F]+\\b"
|
||||||
|
}, {
|
||||||
|
token : "constant.numeric", // float
|
||||||
|
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
||||||
|
}, {
|
||||||
|
token : "constant.language.boolean",
|
||||||
|
regex : "(?:true|false)\\b"
|
||||||
|
}, {
|
||||||
|
token : [
|
||||||
|
"storage.type",
|
||||||
|
"text",
|
||||||
|
"entity.name.function"
|
||||||
|
],
|
||||||
|
regex : "(function)(\\s+)(" + identifierRe + ")"
|
||||||
|
}, {
|
||||||
|
token : function(value) {
|
||||||
|
if (value == "this")
|
||||||
|
return "variable.language";
|
||||||
|
else if (value == "function")
|
||||||
|
return "storage.type";
|
||||||
|
else if (keywords.hasOwnProperty(value) || reserved.hasOwnProperty(value))
|
||||||
|
return "keyword";
|
||||||
|
else if (buildinConstants.hasOwnProperty(value))
|
||||||
|
return "constant.language";
|
||||||
|
else if (/^_?[A-Z][a-zA-Z0-9_]*$/.test(value))
|
||||||
|
return "language.support.class";
|
||||||
|
else
|
||||||
|
return "identifier";
|
||||||
},
|
},
|
||||||
DocCommentHighlightRules.getStartRule("doc-start"),
|
// TODO: Unicode escape sequences
|
||||||
{
|
// TODO: Unicode identifiers
|
||||||
token : "comment", // multi line comment
|
regex : identifierRe
|
||||||
regex : "\\/\\*",
|
}, {
|
||||||
next : "comment"
|
token : "keyword.operator",
|
||||||
}, {
|
regex : "!|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
||||||
token : "string.regexp",
|
}, {
|
||||||
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
token : "punctuation.operator",
|
||||||
}, {
|
regex : "\\?|\\:|\\,|\\;|\\."
|
||||||
token : "string", // single line
|
}, {
|
||||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
token : "paren.lparen",
|
||||||
}, {
|
regex : "[[({<]"
|
||||||
token : "string", // single line
|
}, {
|
||||||
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
token : "paren.rparen",
|
||||||
}, {
|
regex : "[\\])}>]"
|
||||||
token : "constant.numeric", // hex
|
}, {
|
||||||
regex : "0[xX][0-9a-fA-F]+\\b"
|
token : "text",
|
||||||
}, {
|
regex : "\\s+"
|
||||||
token : "constant.numeric", // float
|
}
|
||||||
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
],
|
||||||
}, {
|
"comment" : [
|
||||||
token : "constant.language.boolean",
|
{
|
||||||
regex : "(?:true|false)\\b"
|
token : "comment", // closing comment
|
||||||
}, {
|
regex : ".*?\\*\\/",
|
||||||
token : [
|
next : "start"
|
||||||
"storage.type",
|
}, {
|
||||||
"text",
|
token : "comment", // comment spanning whole line
|
||||||
"entity.name.function"
|
regex : ".+"
|
||||||
],
|
}
|
||||||
regex : "(function)(\\s+)(" + identifierRe + ")"
|
]
|
||||||
}, {
|
|
||||||
token : function(value) {
|
|
||||||
if (value == "this")
|
|
||||||
return "variable.language";
|
|
||||||
else if (value == "function")
|
|
||||||
return "storage.type";
|
|
||||||
else if (keywords.hasOwnProperty(value) || reserved.hasOwnProperty(value))
|
|
||||||
return "keyword";
|
|
||||||
else if (buildinConstants.hasOwnProperty(value))
|
|
||||||
return "constant.language";
|
|
||||||
else if (/^_?[A-Z][a-zA-Z0-9_]*$/.test(value))
|
|
||||||
return "language.support.class";
|
|
||||||
else
|
|
||||||
return "identifier";
|
|
||||||
},
|
|
||||||
// TODO: Unicode escape sequences
|
|
||||||
// TODO: Unicode identifiers
|
|
||||||
regex : identifierRe
|
|
||||||
}, {
|
|
||||||
token : "keyword.operator",
|
|
||||||
regex : "!|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
|
||||||
}, {
|
|
||||||
token : "punctuation.operator",
|
|
||||||
regex : "\\?|\\:|\\,|\\;|\\."
|
|
||||||
}, {
|
|
||||||
token : "paren.lparen",
|
|
||||||
regex : "[[({<]"
|
|
||||||
}, {
|
|
||||||
token : "paren.rparen",
|
|
||||||
regex : "[\\])}>]"
|
|
||||||
}, {
|
|
||||||
token : "text",
|
|
||||||
regex : "\\s+"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"comment" : [
|
|
||||||
{
|
|
||||||
token : "comment", // closing comment
|
|
||||||
regex : ".*?\\*\\/",
|
|
||||||
next : "start"
|
|
||||||
}, {
|
|
||||||
token : "comment", // comment spanning whole line
|
|
||||||
regex : ".+"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
this.embedRules(DocCommentHighlightRules, "doc-",
|
|
||||||
[ DocCommentHighlightRules.getEndRule("start") ]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(JsxHighlightRules, TextHighlightRules);
|
this.embedRules(DocCommentHighlightRules, "doc-",
|
||||||
|
[ DocCommentHighlightRules.getEndRule("start") ]);
|
||||||
|
};
|
||||||
|
|
||||||
exports.JsxHighlightRules = JsxHighlightRules;
|
oop.inherits(JsxHighlightRules, TextHighlightRules);
|
||||||
|
|
||||||
|
exports.JsxHighlightRules = JsxHighlightRules;
|
||||||
});
|
});
|
||||||
|
|
@ -15,42 +15,8 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = "%";
|
||||||
// This code is adapted from ruby.js
|
|
||||||
var outdent = true;
|
|
||||||
|
|
||||||
// LaTeX comments begin with % and go to the end of the line
|
|
||||||
var commentRegEx = /^(\s*)\%/;
|
|
||||||
|
|
||||||
for (var i = startRow; i <= endRow; i++) {
|
|
||||||
if (!commentRegEx.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i = startRow; i <= endRow; i++) {
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(commentRegEx);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "%");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// There is no universally accepted way of indenting a tex document
|
|
||||||
// so just maintain the indentation of the previous line
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
|
||||||
return this.$getIndent(line);
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,9 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.lineCommentStart = "//";
|
||||||
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -45,34 +45,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.blockComment = {start: "<!--", end: "-->"};
|
||||||
var outdent = true;
|
|
||||||
var outentedRows = [];
|
|
||||||
var re = /^(\s*)#/;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "#");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,6 @@
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -53,7 +49,9 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here.
|
|
||||||
|
this.lineCommentStart = ";";
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,10 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.lineCommentStart = "--";
|
||||||
|
this.blockComment = {start: "--[", end: "]--"};
|
||||||
|
|
||||||
var indentKeywords = {
|
var indentKeywords = {
|
||||||
"function": 1,
|
"function": 1,
|
||||||
"then": 1,
|
"then": 1,
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,8 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here.
|
|
||||||
|
this.lineCommentStart = "#";
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,9 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.lineCommentStart = ">";
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
if (state == "listblock") {
|
if (state == "listblock") {
|
||||||
var match = /^(\s*)(?:([-+*])|(\d+)\.)(\s+)/.exec(line);
|
var match = /^(\s*)(?:([-+*])|(\d+)\.)(\s+)/.exec(line);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,8 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here. (see below)
|
this.lineCommentStart = "//";
|
||||||
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,13 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here.
|
|
||||||
|
this.lineCommentStart = ["--", "//"];
|
||||||
|
this.blockComment = [
|
||||||
|
{start: "(*", end: "*)"},
|
||||||
|
{start: "{", end: "}"}
|
||||||
|
];
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,6 @@ var PascalHighlightRules = function() {
|
||||||
'storage.type.prototype.pascal',
|
'storage.type.prototype.pascal',
|
||||||
'entity.name.function.prototype.pascal' ],
|
'entity.name.function.prototype.pascal' ],
|
||||||
regex: '\\b(function|procedure)(\\s+)(\\w+)(\\.\\w+)?(?=(?:\\(.*?\\))?;\\s*(?:attribute|forward|external))' },
|
regex: '\\b(function|procedure)(\\s+)(\\w+)(\\.\\w+)?(?=(?:\\(.*?\\))?;\\s*(?:attribute|forward|external))' },
|
||||||
{ token: 'keyword.operator',
|
|
||||||
regex: '[+\\-;,/*%]|:=|=' },
|
|
||||||
{ caseInsensitive: true,
|
{ caseInsensitive: true,
|
||||||
token:
|
token:
|
||||||
[ 'variable.pascal', "text",
|
[ 'variable.pascal', "text",
|
||||||
|
|
@ -116,7 +114,9 @@ var PascalHighlightRules = function() {
|
||||||
{ token: 'punctuation.definition.string.end.pascal',
|
{ token: 'punctuation.definition.string.end.pascal',
|
||||||
regex: '\'',
|
regex: '\'',
|
||||||
next: 'pop' },
|
next: 'pop' },
|
||||||
{ defaultToken: 'string.quoted.single.pascal' } ] } ] }
|
{ defaultToken: 'string.quoted.single.pascal' } ] },
|
||||||
|
{ token: 'keyword.operator',
|
||||||
|
regex: '[+\\-;,/*%]|:=|=' } ] }
|
||||||
|
|
||||||
this.normalizeRules();
|
this.normalizeRules();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -48,33 +48,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = "#";
|
||||||
var outdent = true;
|
|
||||||
var re = /^(\s*)#/;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "#");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -30,58 +30,30 @@
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
var oop = require("../lib/oop");
|
var oop = require("../lib/oop");
|
||||||
var TextMode = require("../mode/text").Mode;
|
var TextMode = require("../mode/text").Mode;
|
||||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||||
var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules;
|
var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules;
|
||||||
var Range = require("../range").Range;
|
var Range = require("../range").Range;
|
||||||
|
|
||||||
var Mode = function() {
|
var Mode = function() {
|
||||||
this.$tokenizer = new Tokenizer(new PgsqlHighlightRules().getRules());
|
this.$tokenizer = new Tokenizer(new PgsqlHighlightRules().getRules());
|
||||||
};
|
};
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
this.lineCommentStart = "--";
|
||||||
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var outdent = true;
|
if (state == "start" || state == "keyword.statementEnd") {
|
||||||
// var outentedRows = [];
|
return "";
|
||||||
var re = /^(\s*)--/;
|
} else {
|
||||||
|
return this.$getIndent(line); // Keep whatever indent the previous line has
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "--");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
|
||||||
if (state == "start" || state == "keyword.statementEnd") {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return this.$getIndent(line); // Keep whatever indent the previous line has
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -69,33 +69,9 @@ oop.inherits(Mode, TextMode);
|
||||||
+ unicode.packages.Pc + "\_]|\s])+", "g"
|
+ unicode.packages.Pc + "\_]|\s])+", "g"
|
||||||
);
|
);
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
|
||||||
var outdent = true;
|
this.lineCommentStart = ["#", "//"];
|
||||||
var re = /^(\s*)#/;
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "#");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.lineCommentStart = "#";
|
||||||
|
this.blockComment = {start: "<#", end: "#>"};
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,33 +46,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = "#";
|
||||||
var outdent = true;
|
|
||||||
var re = /^(\s*)#/;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "#");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -48,33 +48,8 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
|
||||||
var outdent = true;
|
this.lineCommentStart = "#";
|
||||||
var re = /^(\s*)#/;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "#");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ var Mode = function() {
|
||||||
};
|
};
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
this.lineCommentStart = "//";
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -50,33 +50,8 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = "//";
|
||||||
var outdent = true;
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
var re = /^(\s*)\/\//;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "//");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,9 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here.
|
|
||||||
|
this.lineCommentStart = ";";
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,10 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.lineCommentStart = "//";
|
||||||
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,33 +44,8 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
|
||||||
var outdent = true;
|
this.lineCommentStart = "#";
|
||||||
var re = /^(\s*)#/;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "#");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -44,34 +44,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = "--";
|
||||||
var outdent = true;
|
|
||||||
var outentedRows = [];
|
|
||||||
var re = /^(\s*)--/;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "--");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,33 +48,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.lineCommentStart = "#";
|
||||||
var outdent = true;
|
|
||||||
var re = /^(\s*)#/;
|
|
||||||
|
|
||||||
for (var i=startRow; i<= endRow; i++) {
|
|
||||||
if (!re.test(doc.getLine(i))) {
|
|
||||||
outdent = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outdent) {
|
|
||||||
var deleteRange = new Range(0, 0, 0, 0);
|
|
||||||
for (var i=startRow; i<= endRow; i++)
|
|
||||||
{
|
|
||||||
var line = doc.getLine(i);
|
|
||||||
var m = line.match(re);
|
|
||||||
deleteRange.start.row = i;
|
|
||||||
deleteRange.end.row = i;
|
|
||||||
deleteRange.end.column = m[0].length;
|
|
||||||
doc.replace(deleteRange, m[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
doc.indentRows(startRow, endRow, "#");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ var Tokenizer = require("../tokenizer").Tokenizer;
|
||||||
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
||||||
var Behaviour = require("./behaviour").Behaviour;
|
var Behaviour = require("./behaviour").Behaviour;
|
||||||
var unicode = require("../unicode");
|
var unicode = require("../unicode");
|
||||||
|
var lang = require("../lib/lang");
|
||||||
|
|
||||||
var Mode = function() {
|
var Mode = function() {
|
||||||
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
|
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
|
||||||
|
|
@ -61,7 +62,46 @@ var Mode = function() {
|
||||||
return this.$tokenizer;
|
return this.$tokenizer;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
this.toggleCommentLines = function(state, session, startRow, endRow) {
|
||||||
|
var doc = session.doc;
|
||||||
|
var regexpStart, lineCommentStart;
|
||||||
|
if (!this.lineCommentStart) {
|
||||||
|
return false
|
||||||
|
} else if (Array.isArray(this.lineCommentStart)) {
|
||||||
|
regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|");
|
||||||
|
lineCommentStart = this.lineCommentStart[0];
|
||||||
|
} else {
|
||||||
|
regexpStart = lang.escapeRegExp(this.lineCommentStart);
|
||||||
|
lineCommentStart = this.lineCommentStart;
|
||||||
|
}
|
||||||
|
regexpStart = new RegExp("^\\s*(?:" + regexpStart + ") ?");
|
||||||
|
|
||||||
|
var removeComment = true;
|
||||||
|
var minSpace = Infinity;
|
||||||
|
var indentations = [];
|
||||||
|
|
||||||
|
for (var i = startRow; i <= endRow; i++) {
|
||||||
|
var line = doc.getLine(i);
|
||||||
|
var indent = line.search(/\S|$/);
|
||||||
|
indentations[i] = indent;
|
||||||
|
if (indent < minSpace)
|
||||||
|
minSpace = indent;
|
||||||
|
if (removeComment && !regexpStart.test(line))
|
||||||
|
removeComment = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removeComment) {
|
||||||
|
for (var i = startRow; i <= endRow; i++) {
|
||||||
|
var line = doc.getLine(i);
|
||||||
|
var m = line.match(regexpStart);
|
||||||
|
doc.removeInLine(i, indentations[i], m[0].length);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lineCommentStart += " ";
|
||||||
|
for (var i = startRow; i <= endRow; i++) {
|
||||||
|
doc.insertInLine({row: i, column: minSpace}, lineCommentStart);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,6 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,9 @@ var Mode = function() {
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Extra logic goes here.
|
|
||||||
|
this.lineCommentStart = ["'", "REM"];
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,7 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.blockComment = {start: "<!--", end: "-->"};
|
||||||
return this.$getIndent(line);
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,9 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.lineCommentStart = "#";
|
||||||
|
|
||||||
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
if (state == "start") {
|
if (state == "start") {
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ function onMouseDown(e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (!shift && alt && button == 0) {
|
} else if (alt && button == 0) {
|
||||||
e.stop();
|
e.stop();
|
||||||
|
|
||||||
if (isMultiSelect && !ctrl)
|
if (isMultiSelect && !ctrl)
|
||||||
|
|
@ -128,10 +128,15 @@ function onMouseDown(e) {
|
||||||
else if (!isMultiSelect && ctrl)
|
else if (!isMultiSelect && ctrl)
|
||||||
selection.addRange();
|
selection.addRange();
|
||||||
|
|
||||||
selection.moveCursorToPosition(pos);
|
|
||||||
selection.clearSelection();
|
|
||||||
|
|
||||||
var rectSel = [];
|
var rectSel = [];
|
||||||
|
if (shift) {
|
||||||
|
screenAnchor = session.documentToScreenPosition(selection.lead);
|
||||||
|
blockSelect();
|
||||||
|
} else {
|
||||||
|
selection.moveCursorToPosition(pos);
|
||||||
|
selection.clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var onMouseSelectionEnd = function(e) {
|
var onMouseSelectionEnd = function(e) {
|
||||||
clearInterval(timerId);
|
clearInterval(timerId);
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ var Split = function(container, theme, splits) {
|
||||||
|
|
||||||
// Overwrite the default $informUndoManager function such that new delas
|
// Overwrite the default $informUndoManager function such that new delas
|
||||||
// aren't added to the undo manager from the new and the old session.
|
// aren't added to the undo manager from the new and the old session.
|
||||||
s.$informUndoManager = lang.deferredCall(function() { s.$deltas = []; });
|
s.$informUndoManager = lang.delayedCall(function() { s.$deltas = []; });
|
||||||
|
|
||||||
// Copy over 'settings' from the session.
|
// Copy over 'settings' from the session.
|
||||||
s.setTabSize(session.getTabSize());
|
s.setTabSize(session.getTabSize());
|
||||||
|
|
|
||||||
|
|
@ -304,6 +304,11 @@ var VirtualRenderer = function(container, theme) {
|
||||||
size.height = height;
|
size.height = height;
|
||||||
|
|
||||||
size.scrollerHeight = this.scroller.clientHeight;
|
size.scrollerHeight = this.scroller.clientHeight;
|
||||||
|
if (!size.scrollerHeight) {
|
||||||
|
size.scrollerHeight = size.height;
|
||||||
|
if (this.$horizScroll)
|
||||||
|
size.scrollerHeight -= this.scrollBar.getWidth();
|
||||||
|
}
|
||||||
this.scrollBar.setHeight(size.scrollerHeight);
|
this.scrollBar.setHeight(size.scrollerHeight);
|
||||||
|
|
||||||
if (this.session) {
|
if (this.session) {
|
||||||
|
|
@ -332,6 +337,9 @@ var VirtualRenderer = function(container, theme) {
|
||||||
else
|
else
|
||||||
this.$loop.schedule(changes);
|
this.$loop.schedule(changes);
|
||||||
|
|
||||||
|
if (force)
|
||||||
|
this.$gutterLayer.$padding = null;
|
||||||
|
|
||||||
if (force)
|
if (force)
|
||||||
delete this.resizing;
|
delete this.resizing;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue