Merge pull request #1260 from ajaxorg/toggleComment

Improve toggleCommentLines and make it faster
This commit is contained in:
Mostafa Eweda 2013-02-23 06:03:44 -08:00
commit 1b8fb10e50
52 changed files with 371 additions and 774 deletions

View file

@ -222,12 +222,12 @@ var EditSession = function(text, mode) {
this.$screenRowCache = [];
return;
}
var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
var l = this.$docRowCache.length;
this.$docRowCache.splice(i, l);
this.$screenRowCache.splice(i, l);
var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1;
if (l > i) {
this.$docRowCache.splice(i, l);
this.$screenRowCache.splice(i, l);
}
};
this.$getRowCacheIndex = function(cacheArray, val) {
@ -426,8 +426,7 @@ var EditSession = function(text, mode) {
self.$deltas = [];
}
this.$informUndoManager =
lang.deferredCall(this.$syncInformUndoManager);
this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
}
};

View file

@ -66,7 +66,6 @@ function Folding() {
*
*/
this.getFoldsInRange = function(range) {
range = range.clone();
var start = range.start;
var end = range.end;
var foldLines = this.$foldData;
@ -104,6 +103,9 @@ function Folding() {
foundFolds.push(fold);
}
}
start.column -= 1;
end.column += 1;
return foundFolds;
};

View file

@ -591,8 +591,9 @@ var Editor = function(renderer, session) {
};
this.onChangeMode = function() {
this.onChangeMode = function(e) {
this.renderer.updateText();
this._emit("changeMode", e);
};

View file

@ -189,15 +189,15 @@ module.exports = {
editor.getSelection().selectDown();
editor.toggleCommentLines();
assert.equal(["// abc", "//cde"].join("\n"), session.toString());
assert.equal(["// abc", "// cde"].join("\n"), session.toString());
var selection = editor.getSelectionRange();
assert.position(selection.start, 0, 4);
assert.position(selection.end, 1, 4);
assert.position(selection.start, 0, 5);
assert.position(selection.end, 1, 5);
},
"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);
editor.moveCursorTo(0, 1);
@ -235,7 +235,7 @@ module.exports = {
editor.getSelection().selectDown();
editor.toggleCommentLines();
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
assert.range(editor.getSelectionRange(), 0, 3, 1, 0);
// select up
var session = new EditSession(["abc", "cde"].join("\n"), new JavaScriptMode());
@ -245,7 +245,7 @@ module.exports = {
editor.getSelection().selectUp();
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() {

View file

@ -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
// http://es5.github.com/#x15.5.4.20
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 + "*"),
trimEndRegexp = new RegExp(ws + ws + "*$");
String.prototype.trim = function trim() {
if (this === undefined || this === null) {
throw new TypeError("can't convert "+this+" to object");
}
return String(this)
.replace(trimBeginRegexp, "")
.replace(trimEndRegexp, "");
return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
};
}

View file

@ -144,34 +144,9 @@ exports.getMatchOffsets = function(string, regExp) {
/* deprecated */
exports.deferredCall = function(fcn) {
var timer = null;
var callback = function() {
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;
if (typeof console != "undefined" && console.error)
console.error("Deprecated: use lang.delayedCall")
return exports.delayedCall(fcn);
};

View file

@ -50,33 +50,8 @@ 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++) {
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.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -46,33 +46,7 @@ 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++) {
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.lineCommentStart = ";";
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -19,6 +19,9 @@ oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -51,6 +51,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.foldingRules = "cStyle";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -56,6 +56,8 @@ oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -18,33 +18,8 @@ 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++) {
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.lineCommentStart = ["//", "#"];
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -1,80 +1,55 @@
define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
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.$tokenizer = new Tokenizer(new GolangHighlightRules().getRules());
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*)\/\//;
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
for (var i=startRow; i<= endRow; i++) {
if (!re.test(doc.getLine(i))) {
outdent = false;
break;
}
}
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
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) {
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;
}
}
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;
};//end getNextLineIndent
}
if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
}
}
this.checkOutdent = function(state, line, input) {
return this.$outdent.checkOutdent(line, input);
};
return indent;
};//end getNextLineIndent
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
this.checkOutdent = function(state, line, input) {
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;
});

View file

@ -55,7 +55,8 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
this.lineCommentStart = ["//", "#"];
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -18,7 +18,9 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -57,10 +57,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.toggleCommentLines = function(state, doc, startRow, endRow) {
return 0;
};
this.blockComment = {start: "<!--", end: "-->"};
this.getNextLineIndent = function(state, line, tab) {
return this.$getIndent(line);

View file

@ -52,6 +52,7 @@ oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
this.lineCommentStart = "//";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -3,7 +3,7 @@
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* 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
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -51,34 +51,8 @@ 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++) {
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.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
@ -90,7 +64,7 @@ oop.inherits(Mode, TextMode);
if (tokens.length && tokens[tokens.length-1].type == "comment") {
return indent;
}
if (state == "start" || state == "no_regex") {
var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
if (match) {
@ -119,7 +93,7 @@ oop.inherits(Mode, TextMode);
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
this.createWorker = function(session) {
var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
worker.attachToDocument(session.getDocument());
@ -127,11 +101,11 @@ oop.inherits(Mode, TextMode);
worker.on("jslint", function(results) {
session.setAnnotations(results.data);
});
worker.on("terminate", function() {
session.clearAnnotations();
});
return worker;
};

View file

@ -58,14 +58,14 @@ module.exports = {
var session = new EditSession([" abc", "cde", "fg"]);
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() {
var session = new EditSession(["// abc", "//cde", "fg"]);
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() {
@ -77,10 +77,10 @@ module.exports = {
},
"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);
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() {

View file

@ -19,33 +19,36 @@ oop.inherits(Mode, TextMode);
(function() {
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
var tokens = tokenizedLine.tokens;
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
if (tokens.length && tokens[tokens.length-1].type == "comment") {
return indent;
}
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
var tokens = tokenizedLine.tokens;
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;
};
if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
}
}
this.checkOutdent = function(state, line, input) {
return this.$outdent.checkOutdent(line, input);
};
return indent;
};
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
this.checkOutdent = function(state, line, input) {
return this.$outdent.checkOutdent(line, input);
};
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
}).call(Mode.prototype);

View file

@ -1,120 +1,120 @@
define(function(require, exports, module) {
var oop = require("../lib/oop");
var lang = require("../lib/lang");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var oop = require("../lib/oop");
var lang = require("../lib/lang");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
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 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 buildinConstants = lang.arrayToMap(
("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|")
);
var reserved = lang.arrayToMap(
("debugger|with|" +
"const|export|" +
"let|private|public|yield|protected|" +
"extern|native|as|operator|__fake__|__readonly__").split("|")
);
var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
this.$rules = {
"start" : [
{
token : "comment",
regex : "\\/\\/.*$"
var buildinConstants = lang.arrayToMap(
("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|")
);
var reserved = lang.arrayToMap(
("debugger|with|" +
"const|export|" +
"let|private|public|yield|protected|" +
"extern|native|as|operator|__fake__|__readonly__").split("|")
);
var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
this.$rules = {
"start" : [
{
token : "comment",
regex : "\\/\\/.*$"
},
DocCommentHighlightRules.getStartRule("doc-start"),
{
token : "comment", // multi line comment
regex : "\\/\\*",
next : "comment"
}, {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
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"),
{
token : "comment", // multi line comment
regex : "\\/\\*",
next : "comment"
}, {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
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";
},
// 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") ]);
// 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 : ".+"
}
]
};
oop.inherits(JsxHighlightRules, TextHighlightRules);
this.embedRules(DocCommentHighlightRules, "doc-",
[ DocCommentHighlightRules.getEndRule("start") ]);
};
exports.JsxHighlightRules = JsxHighlightRules;
oop.inherits(JsxHighlightRules, TextHighlightRules);
exports.JsxHighlightRules = JsxHighlightRules;
});

View file

@ -15,42 +15,8 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
this.toggleCommentLines = function(state, doc, startRow, endRow) {
// 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*)\%/;
this.lineCommentStart = "%";
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);
exports.Mode = Mode;

View file

@ -48,6 +48,9 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -45,34 +45,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.toggleCommentLines = function(state, doc, startRow, endRow) {
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.blockComment = {start: "<!--", end: "-->"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -27,10 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* Contributor(s):
*
*
*
* ***** END LICENSE BLOCK ***** */
/*
@ -53,7 +49,9 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
this.lineCommentStart = ";";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -45,6 +45,10 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "--";
this.blockComment = {start: "--[", end: "]--"};
var indentKeywords = {
"function": 1,
"then": 1,

View file

@ -55,7 +55,8 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
this.lineCommentStart = "#";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -56,6 +56,9 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = ">";
this.getNextLineIndent = function(state, line, tab) {
if (state == "listblock") {
var match = /^(\s*)(?:([-+*])|(\d+)\.)(\s+)/.exec(line);

View file

@ -55,7 +55,8 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here. (see below)
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -55,7 +55,13 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
this.lineCommentStart = ["--", "//"];
this.blockComment = [
{start: "(*", end: "*)"},
{start: "{", end: "}"}
];
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -60,8 +60,6 @@ var PascalHighlightRules = function() {
'storage.type.prototype.pascal',
'entity.name.function.prototype.pascal' ],
regex: '\\b(function|procedure)(\\s+)(\\w+)(\\.\\w+)?(?=(?:\\(.*?\\))?;\\s*(?:attribute|forward|external))' },
{ token: 'keyword.operator',
regex: '[+\\-;,/*%]|:=|=' },
{ caseInsensitive: true,
token:
[ 'variable.pascal', "text",
@ -116,7 +114,9 @@ var PascalHighlightRules = function() {
{ token: 'punctuation.definition.string.end.pascal',
regex: '\'',
next: 'pop' },
{ defaultToken: 'string.quoted.single.pascal' } ] } ] }
{ defaultToken: 'string.quoted.single.pascal' } ] },
{ token: 'keyword.operator',
regex: '[+\\-;,/*%]|:=|=' } ] }
this.normalizeRules();
};

View file

@ -48,33 +48,7 @@ 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++) {
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.lineCommentStart = "#";
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -30,58 +30,30 @@
define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("../mode/text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules;
var Range = require("../range").Range;
var oop = require("../lib/oop");
var TextMode = require("../mode/text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.$tokenizer = new Tokenizer(new PgsqlHighlightRules().getRules());
};
oop.inherits(Mode, TextMode);
var Mode = function() {
this.$tokenizer = new Tokenizer(new PgsqlHighlightRules().getRules());
};
oop.inherits(Mode, TextMode);
(function() {
(function() {
this.lineCommentStart = "--";
this.blockComment = {start: "/*", end: "*/"};
this.toggleCommentLines = function(state, doc, startRow, endRow) {
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) {
if (state == "start" || state == "keyword.statementEnd") {
return "";
} else {
return this.$getIndent(line); // Keep whatever indent the previous line has
}
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;
});

View file

@ -69,33 +69,9 @@ oop.inherits(Mode, TextMode);
+ unicode.packages.Pc + "\_]|\s])+", "g"
);
this.toggleCommentLines = function(state, doc, startRow, endRow) {
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.lineCommentStart = ["#", "//"];
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -19,6 +19,9 @@ oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "#";
this.blockComment = {start: "<#", end: "#>"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -46,33 +46,7 @@ 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++) {
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.lineCommentStart = "#";
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -48,33 +48,8 @@ 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++) {
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.lineCommentStart = "#";
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -43,8 +43,8 @@ var Mode = function() {
};
oop.inherits(Mode, TextMode);
(function() {
(function() {
this.lineCommentStart = "//";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -50,33 +50,8 @@ 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++) {
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.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -49,7 +49,9 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
this.lineCommentStart = ";";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -48,7 +48,10 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -44,33 +44,8 @@ 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++) {
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.lineCommentStart = "#";
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -44,34 +44,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.toggleCommentLines = function(state, doc, startRow, endRow) {
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.lineCommentStart = "--";
}).call(Mode.prototype);

View file

@ -48,33 +48,7 @@ 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++) {
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.lineCommentStart = "#";
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

View file

@ -35,6 +35,7 @@ var Tokenizer = require("../tokenizer").Tokenizer;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var Behaviour = require("./behaviour").Behaviour;
var unicode = require("../unicode");
var lang = require("../lib/lang");
var Mode = function() {
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
@ -61,7 +62,46 @@ var Mode = function() {
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) {

View file

@ -26,11 +26,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* Contributor(s):
*
*
*
* ***** END LICENSE BLOCK ***** */
/*

View file

@ -53,7 +53,9 @@ var Mode = function() {
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
this.lineCommentStart = ["'", "REM"];
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -48,9 +48,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.getNextLineIndent = function(state, line, tab) {
return this.$getIndent(line);
};
this.blockComment = {start: "<!--", end: "-->"};
}).call(Mode.prototype);

View file

@ -47,7 +47,9 @@ oop.inherits(Mode, TextMode);
(function() {
this.getNextLineIndent = function(state, line, tab) {
this.lineCommentStart = "#";
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
if (state == "start") {

View file

@ -120,7 +120,7 @@ function onMouseDown(e) {
}
});
} else if (!shift && alt && button == 0) {
} else if (alt && button == 0) {
e.stop();
if (isMultiSelect && !ctrl)
@ -128,10 +128,15 @@ function onMouseDown(e) {
else if (!isMultiSelect && ctrl)
selection.addRange();
selection.moveCursorToPosition(pos);
selection.clearSelection();
var rectSel = [];
if (shift) {
screenAnchor = session.documentToScreenPosition(selection.lead);
blockSelect();
} else {
selection.moveCursorToPosition(pos);
selection.clearSelection();
}
var onMouseSelectionEnd = function(e) {
clearInterval(timerId);

View file

@ -224,7 +224,7 @@ var Split = function(container, theme, splits) {
// Overwrite the default $informUndoManager function such that new delas
// 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.
s.setTabSize(session.getTabSize());

View file

@ -304,6 +304,11 @@ var VirtualRenderer = function(container, theme) {
size.height = height;
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);
if (this.session) {
@ -332,6 +337,9 @@ var VirtualRenderer = function(container, theme) {
else
this.$loop.schedule(changes);
if (force)
this.$gutterLayer.$padding = null;
if (force)
delete this.resizing;
};