This commit is contained in:
nightwing 2014-01-30 21:23:48 +04:00
commit cd12b25ea6
10 changed files with 95 additions and 76 deletions

View file

@ -30,8 +30,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
/*global define, require */
/** /**
* Generates a list of themes available when ace was built. * Generates a list of themes available when ace was built.
@ -77,7 +75,7 @@ var themeData = [
["Tomorrow Night 80s" ,"tomorrow_night_eighties" , "dark"], ["Tomorrow Night 80s" ,"tomorrow_night_eighties" , "dark"],
["Twilight" ,"twilight" , "dark"], ["Twilight" ,"twilight" , "dark"],
["Vibrant Ink" ,"vibrant_ink" , "dark"] ["Vibrant Ink" ,"vibrant_ink" , "dark"]
] ];
exports.themesByName = {}; exports.themesByName = {};
@ -88,10 +86,10 @@ exports.themesByName = {};
exports.themes = themeData.map(function(data) { exports.themes = themeData.map(function(data) {
var name = data[1] || data[0].replace(/ /g, "_").toLowerCase(); var name = data[1] || data[0].replace(/ /g, "_").toLowerCase();
var theme = { var theme = {
caption: data[0], caption: data[0],
theme: "ace/theme/" + name, theme: "ace/theme/" + name,
isDark: data[2] == "dark", isDark: data[2] == "dark",
name: name name: name
}; };
exports.themesByName[name] = theme; exports.themesByName[name] = theme;
return theme; return theme;

View file

@ -64,6 +64,9 @@ exports.$detectIndentation = function(lines, fallback) {
while (line[line.length - 1] == "\\") while (line[line.length - 1] == "\\")
line = lines[i++]; line = lines[i++];
} }
if (!stats.length)
return;
function getScore(indent) { function getScore(indent) {
var score = 0; var score = 0;

View file

@ -100,30 +100,30 @@ exports.handler.attach = function(editor) {
editor.emacsMark = function() { editor.emacsMark = function() {
return this.session.$emacsMark; return this.session.$emacsMark;
} };
editor.setEmacsMark = function(p) { editor.setEmacsMark = function(p) {
// to deactivate pass in a falsy value // to deactivate pass in a falsy value
this.session.$emacsMark = p; this.session.$emacsMark = p;
} };
editor.pushEmacsMark = function(p, activate) { editor.pushEmacsMark = function(p, activate) {
var prevMark = this.session.$emacsMark; var prevMark = this.session.$emacsMark;
if (prevMark) if (prevMark)
this.session.$emacsMarkRing.push(prevMark); this.session.$emacsMarkRing.push(prevMark);
if (!p || activate) this.setEmacsMark(p) if (!p || activate) this.setEmacsMark(p);
else this.session.$emacsMarkRing.push(p); else this.session.$emacsMarkRing.push(p);
} };
editor.popEmacsMark = function() { editor.popEmacsMark = function() {
var mark = this.emacsMark(); var mark = this.emacsMark();
if (mark) { this.setEmacsMark(null); return mark; } if (mark) { this.setEmacsMark(null); return mark; }
return this.session.$emacsMarkRing.pop(); return this.session.$emacsMarkRing.pop();
} };
editor.getLastEmacsMark = function(p) { editor.getLastEmacsMark = function(p) {
return this.session.$emacsMark || this.session.$emacsMarkRing.slice(-1)[0]; return this.session.$emacsMark || this.session.$emacsMarkRing.slice(-1)[0];
} };
editor.on("click", $resetMarkMode); editor.on("click", $resetMarkMode);
editor.on("changeSession", $kbSessionChange); editor.on("changeSession", $kbSessionChange);
@ -163,15 +163,15 @@ var $kbSessionChange = function(e) {
e.session.$emacsMark = null; e.session.$emacsMark = null;
if (!e.session.hasOwnProperty('$emacsMarkRing')) if (!e.session.hasOwnProperty('$emacsMarkRing'))
e.session.$emacsMarkRing = []; e.session.$emacsMarkRing = [];
} };
var $resetMarkMode = function(e) { var $resetMarkMode = function(e) {
e.editor.session.$emacsMark = null; e.editor.session.$emacsMark = null;
} };
var keys = require("../lib/keys").KEY_MODS, var keys = require("../lib/keys").KEY_MODS;
eMods = {C: "ctrl", S: "shift", M: "alt", CMD: "command"}, var eMods = {C: "ctrl", S: "shift", M: "alt", CMD: "command"};
combinations = ["C-S-M-CMD", var combinations = ["C-S-M-CMD",
"S-M-CMD", "C-M-CMD", "C-S-CMD", "C-S-M", "S-M-CMD", "C-M-CMD", "C-S-CMD", "C-S-M",
"M-CMD", "S-CMD", "S-M", "C-CMD", "C-M", "C-S", "M-CMD", "S-CMD", "S-M", "C-CMD", "C-M", "C-S",
"CMD", "M", "S", "C"]; "CMD", "M", "S", "C"];
@ -188,11 +188,11 @@ exports.handler.onCopy = function(e, editor) {
editor.$handlesEmacsOnCopy = true; editor.$handlesEmacsOnCopy = true;
exports.handler.commands.killRingSave.exec(editor); exports.handler.commands.killRingSave.exec(editor);
delete editor.$handlesEmacsOnCopy; delete editor.$handlesEmacsOnCopy;
} };
exports.handler.onPaste = function(e, editor) { exports.handler.onPaste = function(e, editor) {
editor.pushEmacsMark(editor.getCursorPosition()); editor.pushEmacsMark(editor.getCursorPosition());
} };
exports.handler.bindKey = function(key, command) { exports.handler.bindKey = function(key, command) {
if (!key) if (!key)
@ -216,7 +216,7 @@ exports.handler.bindKey = function(key, command) {
if (!ckb[keyPart]) ckb[keyPart] = "null"; if (!ckb[keyPart]) ckb[keyPart] = "null";
}); });
}, this); }, this);
} };
exports.handler.handleKeyboard = function(data, hashId, key, keyCode) { exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
var editor = data.editor; var editor = data.editor;
@ -224,7 +224,7 @@ exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
if (hashId == -1) { if (hashId == -1) {
editor.pushEmacsMark(); editor.pushEmacsMark();
if (data.count) { if (data.count) {
var str = Array(data.count + 1).join(key); var str = new Array(data.count + 1).join(key);
data.count = null; data.count = null;
return {command: "insertstring", args: str}; return {command: "insertstring", args: str};
} }
@ -313,7 +313,7 @@ exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
} }
}; };
} else { } else {
if (!args) args = {} if (!args) args = {};
if (typeof args === 'object') args.count = count; if (typeof args === 'object') args.count = count;
} }
} }
@ -508,8 +508,8 @@ exports.handler.addCommands({
killLine: function(editor) { killLine: function(editor) {
editor.pushEmacsMark(null); editor.pushEmacsMark(null);
var pos = editor.getCursorPosition(); var pos = editor.getCursorPosition();
if (pos.column == 0 && if (pos.column === 0 &&
editor.session.doc.getLine(pos.row).length == 0) { editor.session.doc.getLine(pos.row).length === 0) {
// If an already empty line is killed, remove // If an already empty line is killed, remove
// the line entirely // the line entirely
editor.selection.selectLine(); editor.selection.selectLine();

View file

@ -96,7 +96,7 @@ exports.handler = {
if (util.currentMode === "insert") { if (util.currentMode === "insert") {
this.onCompositionStartOrig(text); this.onCompositionStartOrig(text);
} }
} };
if (enable) { if (enable) {
if (!editor.onCompositionUpdateOrig) { if (!editor.onCompositionUpdateOrig) {
editor.onCompositionUpdateOrig = editor.onCompositionUpdate; editor.onCompositionUpdateOrig = editor.onCompositionUpdate;
@ -134,7 +134,7 @@ exports.handler = {
return {command: "null", passEvent: true}; return {command: "null", passEvent: true};
} }
return {command: coreCommands.stop}; return {command: coreCommands.stop};
} else if ((key == "esc" && hashId == 0) || key == "ctrl-[") { } else if ((key == "esc" && hashId === 0) || key == "ctrl-[") {
return {command: coreCommands.stop}; return {command: coreCommands.stop};
} else if (data.state == "start") { } else if (data.state == "start") {
if (useragent.isMac && this.handleMacRepeat(data, hashId, key)) { if (useragent.isMac && this.handleMacRepeat(data, hashId, key)) {
@ -142,15 +142,15 @@ exports.handler = {
key = data.inputChar; key = data.inputChar;
} }
if (hashId == -1 || hashId == 1 || hashId == 0 && key.length > 1) { if (hashId == -1 || hashId == 1 || hashId === 0 && key.length > 1) {
if (cmds.inputBuffer.idle && startCommands[key]) if (cmds.inputBuffer.idle && startCommands[key])
return startCommands[key]; return startCommands[key];
cmds.inputBuffer.push(editor, key); cmds.inputBuffer.push(editor, key);
return {command: "null", passEvent: false}; return {command: "null", passEvent: false};
} // if no modifier || shift: wait for input. } // if no modifier || shift: wait for input.
else if (key.length == 1 && (hashId == 0 || hashId == 4)) { else if (key.length == 1 && (hashId === 0 || hashId == 4)) {
return {command: "null", passEvent: true}; return {command: "null", passEvent: true};
} else if (key == "esc" && hashId == 0) { } else if (key == "esc" && hashId === 0) {
return {command: coreCommands.stop}; return {command: coreCommands.stop};
} }
} else { } else {

View file

@ -31,6 +31,10 @@
define(function(require, exports, module) { define(function(require, exports, module) {
"use strict"; "use strict";
exports.last = function(a) {
return a[a.length - 1];
};
exports.stringReverse = function(string) { exports.stringReverse = function(string) {
return string.split("").reverse().join(""); return string.split("").reverse().join("");
}; };

View file

@ -66,7 +66,7 @@ var C9SearchHighlightRules = function() {
var m; var m;
var last = 0; var last = 0;
if (regex) { if (regex && regex.exec) {
regex.lastIndex = 0; regex.lastIndex = 0;
while (m = regex.exec(str)) { while (m = regex.exec(str)) {
var skipped = str.substring(last, m.index); var skipped = str.substring(last, m.index);
@ -92,42 +92,26 @@ var C9SearchHighlightRules = function() {
regex : "Searching for .*$", regex : "Searching for .*$",
onMatch: function(val, state, stack) { onMatch: function(val, state, stack) {
var parts = val.split("\x01"); var parts = val.split("\x01");
var search = parts[1];
if (parts.length < 3) if (parts.length < 3)
return "text"; return "text";
var options = parts[2] == " in" ? parts[5] : parts[6];
if (!/regex/.test(options)) var options, search, replace;
search = lang.escapeRegExp(search);
if (/whole/.test(options))
search = "\\b" + search + "\\b";
var regex = search && safeCreateRegexp(
"(" + search + ")",
/ sensitive/.test(options) ? "g" : "ig"
);
if (regex) {
stack[0] = state;
stack[1] = regex;
}
var i = 0; var i = 0;
var tokens = [ var tokens = [{
{ value: parts[i++] + "'",
value: parts[i++] + "'", type: "text"
type: "text" }, {
}, value: search = parts[i++],
{ type: "text" // "c9searchresults.keyword"
value: parts[i++], }, {
type: "text" // "c9searchresults.keyword" value: "'" + parts[i++],
}, type: "text"
{ }];
value: "'" + parts[i++],
type: "text"
}
];
// replaced // replaced
if (parts[2] !== " in") { if (parts[2] !== " in") {
replace = parts[i];
tokens.push({ tokens.push({
value: "'" + parts[i++] + "'", value: "'" + parts[i++] + "'",
type: "text" type: "text"
@ -143,6 +127,7 @@ var C9SearchHighlightRules = function() {
}); });
// options // options
if (parts[i+1]) { if (parts[i+1]) {
options = parts[i+1];
tokens.push({ tokens.push({
value: "(" + parts[i+1] + ")", value: "(" + parts[i+1] + ")",
type: "text" type: "text"
@ -151,11 +136,33 @@ var C9SearchHighlightRules = function() {
} else { } else {
i -= 1; i -= 1;
} }
while (i++ < parts.length) while (i++ < parts.length) {
parts[i] && tokens.push({ parts[i] && tokens.push({
value: parts[i], value: parts[i],
type: "text" type: "text"
}); });
}
if (replace) {
search = replace;
options = "";
}
if (search) {
if (!/regex/.test(options))
search = lang.escapeRegExp(search);
if (/whole/.test(options))
search = "\\b" + search + "\\b";
}
var regex = search && safeCreateRegexp(
"(" + search + ")",
/ sensitive/.test(options) ? "g" : "ig"
);
if (regex) {
stack[0] = state;
stack[1] = regex;
}
return tokens; return tokens;
} }

View file

@ -50,24 +50,30 @@ oop.inherits(FoldMode, BaseFoldMode);
var level1 = /^(Found.*|Searching for.*)$/; var level1 = /^(Found.*|Searching for.*)$/;
var level2 = /^(\S.*\:|\s*)$/; var level2 = /^(\S.*\:|\s*)$/;
var re = level1.test(line) ? level1 : level2; var re = level1.test(line) ? level1 : level2;
var startRow = row;
var endRow = row;
if (this.foldingStartMarker.test(line)) { if (this.foldingStartMarker.test(line)) {
for (var i = row + 1, l = session.getLength(); i < l; i++) { for (var i = row + 1, l = session.getLength(); i < l; i++) {
if (re.test(lines[i])) if (re.test(lines[i]))
break; break;
} }
endRow = i;
return new Range(row, line.length, i, 0);
} }
else if (this.foldingStopMarker.test(line)) {
if (this.foldingStopMarker.test(line)) {
for (var i = row - 1; i >= 0; i--) { for (var i = row - 1; i >= 0; i--) {
line = lines[i]; line = lines[i];
if (re.test(line)) if (re.test(line))
break; break;
} }
startRow = i;
return new Range(i, line.length, row, 0); }
if (startRow != endRow) {
var col = line.length;
if (re === level1)
col = line.search(/\(Found[^)]+\)$|$/);
return new Range(startRow, col, endRow, 0);
} }
}; };

View file

@ -57,7 +57,7 @@ var Mode = function() {
+ unicode.packages.L + unicode.packages.L
+ unicode.packages.Mn + unicode.packages.Mc + unicode.packages.Mn + unicode.packages.Mc
+ unicode.packages.Nd + unicode.packages.Nd
+ unicode.packages.Pc + "\\$_]|\s])+", "g" + unicode.packages.Pc + "\\$_]|\\s])+", "g"
); );
this.getTokenizer = function() { this.getTokenizer = function() {
@ -217,10 +217,10 @@ var Mode = function() {
var row = iterator.getCurrentTokenRow(); var row = iterator.getCurrentTokenRow();
var column = iterator.getCurrentTokenColumn() + i; var column = iterator.getCurrentTokenColumn() + i;
startRange = new Range(row, column, row, column + comment.start.length); startRange = new Range(row, column, row, column + comment.start.length);
break break;
} }
token = iterator.stepBackward(); token = iterator.stepBackward();
}; }
var iterator = new TokenIterator(session, cursor.row, cursor.column); var iterator = new TokenIterator(session, cursor.row, cursor.column);
var token = iterator.getCurrentToken(); var token = iterator.getCurrentToken();
@ -239,10 +239,10 @@ var Mode = function() {
if (startRange) { if (startRange) {
session.remove(startRange); session.remove(startRange);
startRow = startRange.start.row; startRow = startRange.start.row;
colDiff = -comment.start.length colDiff = -comment.start.length;
} }
} else { } else {
colDiff = comment.start.length colDiff = comment.start.length;
startRow = range.start.row; startRow = range.start.row;
session.insert(range.end, comment.end); session.insert(range.end, comment.end);
session.insert(range.start, comment.start); session.insert(range.start, comment.start);
@ -284,7 +284,8 @@ var Mode = function() {
} }
} }
var delegations = ['toggleCommentLines', 'getNextLineIndent', 'checkOutdent', 'autoOutdent', 'transformAction', 'getCompletions']; var delegations = ['toggleBlockComment', 'toggleCommentLines', 'getNextLineIndent',
'checkOutdent', 'autoOutdent', 'transformAction', 'getCompletions'];
for (var i = 0; i < delegations.length; i++) { for (var i = 0; i < delegations.length; i++) {
(function(scope) { (function(scope) {
@ -292,7 +293,7 @@ var Mode = function() {
var defaultHandler = scope[functionName]; var defaultHandler = scope[functionName];
scope[delegations[i]] = function() { scope[delegations[i]] = function() {
return this.$delegator(functionName, arguments, defaultHandler); return this.$delegator(functionName, arguments, defaultHandler);
} };
} (this)); } (this));
} }
}; };
@ -364,7 +365,7 @@ var Mode = function() {
if (!this.$highlightRules) if (!this.$highlightRules)
this.getTokenizer(); this.getTokenizer();
return this.$keywordList = this.$highlightRules.$keywordList || []; return this.$keywordList = this.$highlightRules.$keywordList || [];
} };
this.getCompletions = function(state, session, pos, prefix) { this.getCompletions = function(state, session, pos, prefix) {
var keywords = this.$keywordList || this.$createKeywordList(); var keywords = this.$keywordList || this.$createKeywordList();

View file

@ -238,7 +238,7 @@ function DefaultHandlers(mouseHandler) {
if (ev.getAccelKey()) if (ev.getAccelKey())
return; return;
//shift wheel to horiz scroll //shift wheel to horiz scroll
if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) { if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) {
ev.wheelX = ev.wheelY; ev.wheelX = ev.wheelY;
ev.wheelY = 0; ev.wheelY = 0;

View file

@ -17,7 +17,7 @@ window.window = window;
window.ace = window; window.ace = window;
window.onerror = function(message, file, line, col, err) { window.onerror = function(message, file, line, col, err) {
console.error("Worker " + err.stack); console.error("Worker " + (err ? err.stack : message));
}; };
window.normalizeModule = function(parentId, moduleName) { window.normalizeModule = function(parentId, moduleName) {