Merge pull request #1673 from ajaxorg/cloud9_update

Cloud9 update
This commit is contained in:
Lennart Kats 2013-11-10 15:47:01 -08:00
commit 1ab54b0b8f
25 changed files with 582 additions and 192 deletions

View file

@ -1,4 +1,4 @@
Searching for 'var' in /workspace/configs Searching for var in/.c9/metadata/workspace/pluginsregexp, case sensitive, whole word
configs/default.js: configs/default.js:
1: var fs = require("fs"); 1: var fs = require("fs");

View file

@ -209,6 +209,9 @@ var AcePopup = function(parentNode) {
} }
// public // public
popup.isOpen = false;
popup.isTopdown = false;
popup.data = []; popup.data = [];
popup.setData = function(list) { popup.setData = function(list) {
popup.data = list || []; popup.data = list || [];
@ -233,26 +236,33 @@ var AcePopup = function(parentNode) {
popup._signal("select"); popup._signal("select");
} }
}; };
popup.on("changeSelection", function() {
if (popup.isOpen)
popup.setRow(popup.selection.lead.row);
});
popup.hide = function() { popup.hide = function() {
this.container.style.display = "none"; this.container.style.display = "none";
this._signal("hide"); this._signal("hide");
popup.isOpen = false; popup.isOpen = false;
}; };
popup.show = function(pos, lineHeight) { popup.show = function(pos, lineHeight, topdownOnly) {
var el = this.container; var el = this.container;
var screenHeight = window.innerHeight; var screenHeight = window.innerHeight;
var renderer = this.renderer; var renderer = this.renderer;
// var maxLines = Math.min(renderer.$maxLines, this.session.getLength()); // var maxLines = Math.min(renderer.$maxLines, this.session.getLength());
var maxH = renderer.$maxLines * lineHeight * 1.4; var maxH = renderer.$maxLines * lineHeight * 1.4;
var top = pos.top + this.$borderSize; var top = pos.top + this.$borderSize;
if (top + maxH > screenHeight - lineHeight) { if (top + maxH > screenHeight - lineHeight && !topdownOnly) {
el.style.top = ""; el.style.top = "";
el.style.bottom = screenHeight - top + "px"; el.style.bottom = screenHeight - top + "px";
popup.isTopdown = false;
} else { } else {
top += lineHeight; top += lineHeight;
el.style.top = top + "px"; el.style.top = top + "px";
el.style.bottom = ""; el.style.bottom = "";
popup.isTopdown = true;
} }
el.style.left = pos.left + "px"; el.style.left = pos.left + "px";

View file

@ -35,12 +35,13 @@ var lang = require("../lib/lang");
var config = require("../config"); var config = require("../config");
function bindKey(win, mac) { function bindKey(win, mac) {
return { return {win: win, mac: mac};
win: win,
mac: mac
};
} }
/*
multiSelectAction: "forEach"|"forEachLine"|function|undefined,
scrollIntoView: true|"cursor"|"center"|"selectionPart"
*/
exports.commands = [{ exports.commands = [{
name: "showSettingsMenu", name: "showSettingsMenu",
bindKey: bindKey("Ctrl-,", "Command-,"), bindKey: bindKey("Ctrl-,", "Command-,"),
@ -75,21 +76,46 @@ exports.commands = [{
name: "fold", name: "fold",
bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"), bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
exec: function(editor) { editor.session.toggleFold(false); }, exec: function(editor) { editor.session.toggleFold(false); },
scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "unfold", name: "unfold",
bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"), bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
exec: function(editor) { editor.session.toggleFold(true); }, exec: function(editor) { editor.session.toggleFold(true); },
scrollIntoView: "center",
readOnly: true
}, {
name: "toggleFoldWidget",
bindKey: bindKey("F2", "F2"),
exec: function(editor) { editor.session.toggleFoldWidget(); },
scrollIntoView: "center",
readOnly: true
}, {
name: "toggleParentFoldWidget",
bindKey: bindKey("Alt-F2", "Alt-F2"),
exec: function(editor) { editor.session.toggleFoldWidget(true); },
scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "foldall", name: "foldall",
bindKey: bindKey("Alt-0", "Command-Option-0"), bindKey: bindKey("Ctrl-Alt-0", "Ctrl-Command-Option-0"),
exec: function(editor) { editor.session.foldAll(); }, exec: function(editor) { editor.session.foldAll(); },
scrollIntoView: "center",
readOnly: true
}, {
name: "foldOther",
bindKey: bindKey("Alt-0", "Command-Option-0"),
exec: function(editor) {
editor.session.foldAll();
editor.session.unfold(editor.selection.getAllRanges());
},
scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "unfoldall", name: "unfoldall",
bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"), bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
exec: function(editor) { editor.session.unfold(); }, exec: function(editor) { editor.session.unfold(); },
scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "findnext", name: "findnext",
@ -345,7 +371,8 @@ exports.commands = [{
name: "togglecomment", name: "togglecomment",
bindKey: bindKey("Ctrl-/", "Command-/"), bindKey: bindKey("Ctrl-/", "Command-/"),
exec: function(editor) { editor.toggleCommentLines(); }, exec: function(editor) { editor.toggleCommentLines(); },
multiSelectAction: "forEachLine" multiSelectAction: "forEachLine",
scrollIntoView: "selectionPart"
}, { }, {
name: "toggleBlockComment", name: "toggleBlockComment",
bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"), bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
@ -439,26 +466,31 @@ exports.commands = [{
name: "outdent", name: "outdent",
bindKey: bindKey("Shift-Tab", "Shift-Tab"), bindKey: bindKey("Shift-Tab", "Shift-Tab"),
exec: function(editor) { editor.blockOutdent(); }, exec: function(editor) { editor.blockOutdent(); },
multiSelectAction: "forEach" multiSelectAction: "forEach",
scrollIntoView: "selectionPart"
}, { }, {
name: "indent", name: "indent",
bindKey: bindKey("Tab", "Tab"), bindKey: bindKey("Tab", "Tab"),
exec: function(editor) { editor.indent(); }, exec: function(editor) { editor.indent(); },
multiSelectAction: "forEach" multiSelectAction: "forEach",
},{ scrollIntoView: "selectionPart"
}, {
name: "blockoutdent", name: "blockoutdent",
bindKey: bindKey("Ctrl-[", "Ctrl-["), bindKey: bindKey("Ctrl-[", "Ctrl-["),
exec: function(editor) { editor.blockOutdent(); }, exec: function(editor) { editor.blockOutdent(); },
multiSelectAction: "forEachLine" multiSelectAction: "forEachLine",
},{ scrollIntoView: "selectionPart"
}, {
name: "blockindent", name: "blockindent",
bindKey: bindKey("Ctrl-]", "Ctrl-]"), bindKey: bindKey("Ctrl-]", "Ctrl-]"),
exec: function(editor) { editor.blockIndent(); }, exec: function(editor) { editor.blockIndent(); },
multiSelectAction: "forEachLine" multiSelectAction: "forEachLine",
scrollIntoView: "selectionPart"
}, { }, {
name: "insertstring", name: "insertstring",
exec: function(editor, str) { editor.insert(str); }, exec: function(editor, str) { editor.insert(str); },
multiSelectAction: "forEach" multiSelectAction: "forEach",
scrollIntoView: "cursor"
}, { }, {
name: "inserttext", name: "inserttext",
exec: function(editor, args) { exec: function(editor, args) {

View file

@ -158,7 +158,7 @@
z-index: 1; z-index: 1;
position: absolute; position: absolute;
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: pre;
height: 100%; height: 100%;
width: 100%; width: 100%;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;

View file

@ -108,6 +108,18 @@ function Folding() {
return foundFolds; return foundFolds;
}; };
this.getFoldsInRangeList = function(ranges) {
if (Array.isArray(ranges)) {
var folds = [];
ranges.forEach(function(range) {
folds = folds.concat(this.getFoldsInRange(range));
}, this);
} else {
var folds = this.getFoldsInRange(ranges);
}
return folds;
}
/* /*
* Returns all folds in the document * Returns all folds in the document
@ -413,7 +425,7 @@ function Folding() {
}; };
this.expandFold = function(fold) { this.expandFold = function(fold) {
this.removeFold(fold); this.removeFold(fold);
fold.subFolds.forEach(function(subFold) { fold.subFolds.forEach(function(subFold) {
fold.restoreRange(subFold); fold.restoreRange(subFold);
this.addFold(subFold); this.addFold(subFold);
@ -441,8 +453,8 @@ function Folding() {
range = Range.fromPoints(location, location); range = Range.fromPoints(location, location);
else else
range = location; range = location;
folds = this.getFoldsInRange(range); folds = this.getFoldsInRangeList(range);
if (expandInner) { if (expandInner) {
this.removeFolds(folds); this.removeFolds(folds);
} else { } else {
@ -450,7 +462,7 @@ function Folding() {
// expandFolds several times. // expandFolds several times.
while (folds.length) { while (folds.length) {
this.expandFolds(folds); this.expandFolds(folds);
folds = this.getFoldsInRange(range); folds = this.getFoldsInRangeList(range);
} }
} }
}; };
@ -636,17 +648,16 @@ function Folding() {
continue; continue;
var range = this.getFoldWidgetRange(row); var range = this.getFoldWidgetRange(row);
var rangeEndRow = range.end.row;
// sometimes range can be incompatible with existing fold // sometimes range can be incompatible with existing fold
// TODO change addFold to return null istead of throwing // TODO change addFold to return null istead of throwing
if (range && range.isMultiLine() if (range && range.isMultiLine()
&& rangeEndRow <= endRow && range.end.row <= endRow
&& range.start.row >= startRow && range.start.row >= startRow
) try { ) try {
var fold = this.addFold("...", range); var fold = this.addFold("...", range);
fold.collapseChildren = depth; fold.collapseChildren = depth;
// addFold can change the range // addFold can change the range
row = rangeEndRow; row = range.end.row;
} catch(e) {} } catch(e) {}
} }
}; };
@ -727,25 +738,34 @@ function Folding() {
} }
this.onFoldWidgetClick = function(row, e) { this.onFoldWidgetClick = function(row, e) {
e = e.domEvent;
var options = {
children: e.shiftKey,
all: e.ctrlKey || e.metaKey,
siblings: e.altKey
};
var range = this.$toggleFoldWidget(row, options);
if (!range)
(e.target || e.srcElement).className += " ace_invalid";
};
this.$toggleFoldWidget = function(row, options) {
var type = this.getFoldWidget(row); var type = this.getFoldWidget(row);
var line = this.getLine(row); var line = this.getLine(row);
e = e.domEvent;
var children = e.shiftKey;
var all = e.ctrlKey || e.metaKey;
var siblings = e.altKey;
var dir = type === "end" ? -1 : 1; var dir = type === "end" ? -1 : 1;
var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir); var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
if (fold) { if (fold) {
if (children || all) if (options.children || options.all)
this.removeFold(fold); this.removeFold(fold);
else else
this.expandFold(fold); this.expandFold(fold);
return; return;
} }
var range = this.getFoldWidgetRange(row); var range = this.getFoldWidgetRange(row, true);
// sometimes singleline folds can be missed by the code above // sometimes singleline folds can be missed by the code above
if (range && !range.isMultiLine()) { if (range && !range.isMultiLine()) {
fold = this.getFoldAt(range.start.row, range.start.column, 1); fold = this.getFoldAt(range.start.row, range.start.column, 1);
@ -755,24 +775,48 @@ function Folding() {
} }
} }
if (siblings) { if (options.siblings) {
var data = this.getParentFoldRangeData(row); var data = this.getParentFoldRangeData(row);
if (data.range) { if (data.range) {
var startRow = data.range.start.row + 1; var startRow = data.range.start.row + 1;
var endRow = data.range.end.row; var endRow = data.range.end.row;
} }
this.foldAll(startRow, endRow, all ? 10000 : 0); this.foldAll(startRow, endRow, options.all ? 10000 : 0);
} else if (children) { } else if (options.children) {
var endRow = range ? range.end.row : this.getLength(); endRow = range ? range.end.row : this.getLength();
this.foldAll(row + 1, range.end.row, all ? 10000 : 0); this.foldAll(row + 1, range.end.row, options.all ? 10000 : 0);
} else if (range) { } else if (range) {
if (all) if (options.all)
range.collapseChildren = 10000; range.collapseChildren = 10000;
this.addFold("...", range); this.addFold("...", range);
} }
if (!range) return range;
(e.target || e.srcElement).className += " ace_invalid" };
this.toggleFoldWidget = function(toggleParent) {
var row = this.selection.getCursor().row;
row = this.getRowFoldStart(row);
var range = this.$toggleFoldWidget(row, {});
if (range)
return;
// handle toggleParent
var data = this.getParentFoldRangeData(row, true);
range = data.range || data.firstRange;
if (range) {
row = range.start.row;
var fold = this.getFoldAt(row, this.getLine(row).length, 1);
if (fold) {
this.removeFold(fold);
} else {
this.addFold("...", range);
}
}
}; };
this.updateFoldWidgets = function(e) { this.updateFoldWidgets = function(e) {

View file

@ -170,12 +170,33 @@ var Editor = function(renderer, session) {
command: commadEvent.command || {}, command: commadEvent.command || {},
args: commadEvent.args args: commadEvent.args
}; };
var command = this.curOp.command;
if (command && command.scrollIntoView)
this.$blockScrolling++;
this.selections.push(this.selection.toJSON()); this.selections.push(this.selection.toJSON());
}; };
this.endOperation = function() { this.endOperation = function() {
if (this.curOp) { if (this.curOp) {
var command = this.curOp.command;
if (command && command.scrollIntoView) {
this.$blockScrolling--;
switch (command.scrollIntoView) {
case "center":
this.renderer.scrollCursorIntoView(null, 0.5);
break;
case "cursor":
this.renderer.scrollCursorIntoView();
break;
case "selectionPart":
this.renderer.scrollCursorIntoView();
break;
default:
break;
}
}
this.prevOp = this.curOp; this.prevOp = this.curOp;
this.curOp = null; this.curOp = null;
} }
@ -1643,8 +1664,8 @@ var Editor = function(renderer, session) {
var range = this.getSelectionRange().collapseRows(); var range = this.getSelectionRange().collapseRows();
return { return {
first: range.start.row, first: this.session.getRowFoldStart(range.start.row),
last: range.end.row last: this.session.getRowFoldEnd(range.end.row)
}; };
}; };

View file

@ -119,6 +119,9 @@ function HashHandler(config, platform) {
if (typeof command === "function") if (typeof command === "function")
command = { exec: command }; command = { exec: command };
if (typeof command !== "object")
return;
if (!command.name) if (!command.name)
command.name = name; command.name = name;

View file

@ -75,8 +75,7 @@ var Gutter = function(parentEl) {
this.setAnnotations = function(annotations) { this.setAnnotations = function(annotations) {
// iterate over sparse array // iterate over sparse array
this.$annotations = [] this.$annotations = [];
var rowInfo, row;
for (var i = 0; i < annotations.length; i++) { for (var i = 0; i < annotations.length; i++) {
var annotation = annotations[i]; var annotation = annotations[i];
var row = annotation.row; var row = annotation.row;
@ -112,7 +111,7 @@ var Gutter = function(parentEl) {
} else if (delta.action == "removeText" || delta.action == "removeLines") { } else if (delta.action == "removeText" || delta.action == "removeLines") {
this.$annotations.splice(firstRow, len + 1, null); this.$annotations.splice(firstRow, len + 1, null);
} else { } else {
var args = Array(len + 1); var args = new Array(len + 1);
args.unshift(firstRow, 1); args.unshift(firstRow, 1);
this.$annotations.splice.apply(this.$annotations, args); this.$annotations.splice.apply(this.$annotations, args);
} }
@ -121,13 +120,16 @@ var Gutter = function(parentEl) {
this.update = function(config) { this.update = function(config) {
var firstRow = config.firstRow; var firstRow = config.firstRow;
var lastRow = config.lastRow; var lastRow = config.lastRow;
var fold = this.session.getNextFoldLine(firstRow); var session = this.session;
var fold = session.getNextFoldLine(firstRow);
var foldStart = fold ? fold.start.row : Infinity; var foldStart = fold ? fold.start.row : Infinity;
var foldWidgets = this.$showFoldWidgets && this.session.foldWidgets; var foldWidgets = this.$showFoldWidgets && session.foldWidgets;
var breakpoints = this.session.$breakpoints; var breakpoints = session.$breakpoints;
var decorations = this.session.$decorations; var decorations = session.$decorations;
var firstLineNumber = this.session.$firstLineNumber; var firstLineNumber = session.$firstLineNumber;
var lastLineNumber = 0; var lastLineNumber = 0;
var gutterRenderer = session.gutterRenderer;
var cell = null; var cell = null;
var index = -1; var index = -1;
@ -135,7 +137,7 @@ var Gutter = function(parentEl) {
while (true) { while (true) {
if (row > foldStart) { if (row > foldStart) {
row = fold.end.row + 1; row = fold.end.row + 1;
fold = this.session.getNextFoldLine(row, fold); fold = session.getNextFoldLine(row, fold);
foldStart = fold ? fold.start.row : Infinity; foldStart = fold ? fold.start.row : Infinity;
} }
if (row > lastRow) { if (row > lastRow) {
@ -166,19 +168,15 @@ var Gutter = function(parentEl) {
if (cell.element.className != className) if (cell.element.className != className)
cell.element.className = className; cell.element.className = className;
var height = this.session.getRowLength(row) * config.lineHeight + "px"; var height = session.getRowLength(row) * config.lineHeight + "px";
if (height != cell.element.style.height) if (height != cell.element.style.height)
cell.element.style.height = height; cell.element.style.height = height;
var text = lastLineNumber = row + firstLineNumber;
if (text != cell.textNode.data)
cell.textNode.data = text;
if (foldWidgets) { if (foldWidgets) {
var c = foldWidgets[row]; var c = foldWidgets[row];
// check if cached value is invalidated and we need to recompute // check if cached value is invalidated and we need to recompute
if (c == null) if (c == null)
c = foldWidgets[row] = this.session.getFoldWidget(row); c = foldWidgets[row] = session.getFoldWidget(row);
} }
if (c) { if (c) {
@ -198,21 +196,30 @@ var Gutter = function(parentEl) {
if (cell.foldWidget.style.height != height) if (cell.foldWidget.style.height != height)
cell.foldWidget.style.height = height; cell.foldWidget.style.height = height;
} else { } else {
if (cell.foldWidget != null) { if (cell.foldWidget) {
cell.element.removeChild(cell.foldWidget); cell.element.removeChild(cell.foldWidget);
cell.foldWidget = null; cell.foldWidget = null;
} }
} }
var text = lastLineNumber = gutterRenderer
? gutterRenderer.getText(session, row)
: row + firstLineNumber;
if (text != cell.textNode.data)
cell.textNode.data = text;
row++; row++;
} }
this.element.style.height = config.minHeight + "px"; this.element.style.height = config.minHeight + "px";
if (this.$fixedWidth || this.session.$useWrapMode) if (this.$fixedWidth || session.$useWrapMode)
lastLineNumber = this.session.getLength(); lastLineNumber = session.getLength();
var gutterWidth = lastLineNumber.toString().length * config.characterWidth; var gutterWidth = gutterRenderer
? gutterRenderer.getWidth(session, lastLineNumber, config)
: lastLineNumber.toString().length * config.characterWidth;
var padding = this.$padding || this.$computePadding(); var padding = this.$padding || this.$computePadding();
gutterWidth += padding.left + padding.right; gutterWidth += padding.left + padding.right;
if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) { if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) {

View file

@ -78,14 +78,16 @@ exports.copyArray = function(array){
}; };
exports.deepCopy = function (obj) { exports.deepCopy = function (obj) {
if (typeof obj != "object") { if (typeof obj !== "object" || !obj)
return obj;
var cons = obj.constructor;
if (cons === RegExp)
return obj; return obj;
}
var copy = obj.constructor(); var copy = cons();
for (var key in obj) { for (var key in obj) {
if (typeof obj[key] == "object") { if (typeof obj[key] === "object") {
copy[key] = this.deepCopy(obj[key]); copy[key] = exports.deepCopy(obj[key]);
} else { } else {
copy[key] = obj[key]; copy[key] = obj[key];
} }
@ -170,6 +172,10 @@ exports.deferredCall = function(fcn) {
timer = null; timer = null;
return deferred; return deferred;
}; };
deferred.isPending = function() {
return timer;
};
return deferred; return deferred;
}; };
@ -183,15 +189,15 @@ exports.delayedCall = function(fcn, defaultTimeout) {
}; };
var _self = function(timeout) { var _self = function(timeout) {
if (timer == null)
timer = setTimeout(callback, timeout || defaultTimeout);
};
_self.delay = function(timeout) {
timer && clearTimeout(timer); timer && clearTimeout(timer);
timer = setTimeout(callback, timeout || defaultTimeout); timer = setTimeout(callback, timeout || defaultTimeout);
}; };
_self.schedule = _self;
_self.delay = _self;
_self.schedule = function(timeout) {
if (timer == null)
timer = setTimeout(callback, timeout || 0);
};
_self.call = function() { _self.call = function() {
this.cancel(); this.cancel();

View file

@ -50,9 +50,13 @@ function generateTestData() {
var data = tokenizer.getLineTokens(line, state); var data = tokenizer.getLineTokens(line, state);
var tmp = []; var tmp = [];
tmp.push(JSON.stringify(data.state)); tmp.push(JSON.stringify(data.state));
var tokenizedLine = "";
data.tokens.forEach(function(x) { data.tokens.forEach(function(x) {
tokenizedLine += x.value;
tmp.push(JSON.stringify([x.type, x.value])); tmp.push(JSON.stringify([x.type, x.value]));
}); });
if (tokenizedLine != line)
tmp.push(JSON.stringify(line));
state = data.state; state = data.state;
return tmp.join(",\n "); return tmp.join(",\n ");
}); });
@ -85,12 +89,15 @@ function testMode(modeName, i) {
lineData.values = []; lineData.values = [];
lineData.types = []; lineData.types = [];
lineData.state = lineData.shift(); lineData.state = lineData.shift();
var line = null;
if (typeof lineData[lineData.length - 1] == "string")
line = lineData.pop()
lineData.forEach(function(x) { lineData.forEach(function(x) {
lineData.types.push(x[0]); lineData.types.push(x[0]);
lineData.values.push(x[1]); lineData.values.push(x[1]);
}); });
if (typeof line != "string")
var line = lineData.values.join(""); line = lineData.values.join("");
var tokens = tokenizer.getLineTokens(line, state); var tokens = tokenizer.getLineTokens(line, state);
var values = tokens.tokens.map(function(x) {return x.value;}); var values = tokens.tokens.map(function(x) {return x.value;});
@ -98,7 +105,7 @@ function testMode(modeName, i) {
var success = true; var success = true;
var err = testEqual([ var err = testEqual([
lineData.state, tokens.state, JSON.stringify(lineData.state), JSON.stringify(tokens.state),
lineData.types, types, lineData.types, types,
lineData.values, values]); lineData.values, values]);
@ -107,7 +114,7 @@ function testMode(modeName, i) {
throw "error"; throw "error";
} }
state = lineData.state; state = tokens.state;
}); });
} }
function testEqual(a) { function testEqual(a) {

View file

@ -1,104 +1,131 @@
[[ [[
"start", ["start",{}],
["text","Searching for 'var' in /workspace/configs"] ["text","Searching for '"],
["text","var"],
["text","' in"],
["text"," /.c9/metadata/workspace/plugins "],
["text","(regexp, case sensitive, whole word)"],
"Searching for \u0001var\u0001 in\u0001/.c9/metadata/workspace/plugins\u0001\u0001regexp, case sensitive, whole word\u0001"
],[ ],[
"start" ["start",{}]
],[ ],[
"start", ["start",{}],
["string","configs/default.js"], ["string","configs/default.js"],
["text",":"] ["text",":"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric"," 1"], ["c9searchresults.constant.numeric"," 1"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var fs = require(\"fs\");"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," fs = require(\"fs\");"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t2"], ["c9searchresults.constant.numeric","\t2"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var argv = require('optimist').argv;"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," argv = require('optimist').argv;"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t3"], ["c9searchresults.constant.numeric","\t3"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var path = require(\"path\");"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," path = require(\"path\");"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t5"], ["c9searchresults.constant.numeric","\t5"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var clientExtensions = {};"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," clientExtensions = {};"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t6"], ["c9searchresults.constant.numeric","\t6"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var clientDirs = fs.readdirSync(__dirname + \"/../plugins-client\");"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," clientDirs = fs.readdirSync(__dirname + \"/../plugins-client\");"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t7"], ["c9searchresults.constant.numeric","\t7"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","for (var i = 0; i < clientDirs.length; i++) {"] ["c9searchresults.text","for ("],
["c9searchresults.keyword","var"],
["c9searchresults.text"," i = 0; i < clientDirs.length; i++) {"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t8"], ["c9searchresults.constant.numeric","\t8"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var dir = clientDirs[i];"] ["c9searchresults.text"," "],
["c9searchresults.keyword","var"],
["c9searchresults.text"," dir = clientDirs[i];"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t12"], ["c9searchresults.constant.numeric","\t12"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var name = dir.split(\".\")[1];"] ["c9searchresults.text"," "],
["c9searchresults.keyword","var"],
["c9searchresults.text"," name = dir.split(\".\")[1];"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t16"], ["c9searchresults.constant.numeric","\t16"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var projectDir = (argv.w && path.resolve(process.cwd(), argv.w)) || process.cwd();"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," projectDir = (argv.w && path.resolve(process.cwd(), argv.w)) || process.cwd();"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t17"], ["c9searchresults.constant.numeric","\t17"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var fsUrl = \"/workspace\";"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," fsUrl = \"/workspace\";"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t19"], ["c9searchresults.constant.numeric","\t19"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var port = argv.p || process.env.PORT || 3131;"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," port = argv.p || process.env.PORT || 3131;"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t20"], ["c9searchresults.constant.numeric","\t20"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var host = argv.l || \"localhost\";"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," host = argv.l || \"localhost\";"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t22"], ["c9searchresults.constant.numeric","\t22"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var config = {"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," config = {"]
],[ ],[
"start" ["start",{}]
],[ ],[
"start", ["start",{}],
["string","configs/local.js"], ["string","configs/local.js"],
["text",":"] ["text",":"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t2"], ["c9searchresults.constant.numeric","\t2"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var config = require(\"./default\");"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," config = require(\"./default\");"]
],[ ],[
"start" ["start",{}]
],[ ],[
"start", ["start",{}],
["string","configs/packed.js"], ["string","configs/packed.js"],
["text",":"] ["text",":"]
],[ ],[
"start", ["start",{}],
["c9searchresults.constant.numeric","\t1"], ["c9searchresults.constant.numeric","\t1"],
["c9searchresults.text",": "], ["c9searchresults.text",": "],
["c9searchresults.text","var config = require(\"./default\");"] ["c9searchresults.keyword","var"],
["c9searchresults.text"," config = require(\"./default\");"]
],[ ],[
"start" ["start",{}]
],[ ],[
"start" ["start",{}]
],[ ],[
"start", ["start",{}],
["text","Found 15 matches in 3 files"] ["text","Found "],
["constant.numeric","15"],
["text"," matches in "],
["constant.numeric","3"],
["text"," files"]
]] ]]

View file

@ -32,8 +32,15 @@ define(function(require, exports, module) {
"use strict"; "use strict";
var oop = require("../lib/oop"); var oop = require("../lib/oop");
var lang = require("../lib/lang");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
function safeCreateRegexp(source, flag) {
try {
return new RegExp(source, flag);
} catch(e) {}
}
var C9SearchHighlightRules = function() { var C9SearchHighlightRules = function() {
// regexp must not have capturing parentheses. Use (?:) instead. // regexp must not have capturing parentheses. Use (?:) instead.
@ -41,12 +48,120 @@ var C9SearchHighlightRules = function() {
this.$rules = { this.$rules = {
"start" : [ "start" : [
{ {
token : ["c9searchresults.constant.numeric", "c9searchresults.text", "c9searchresults.text"], tokenNames : ["c9searchresults.constant.numeric", "c9searchresults.text", "c9searchresults.text", "c9searchresults.keyword"],
regex : "(^\\s+[0-9]+)(:\\s*)(.+)" regex : "(^\\s+[0-9]+)(:\\s)(.+)",
onMatch : function(val, state, stack) {
var values = this.splitRegex.exec(val);
var types = this.tokenNames;
var tokens = [{
type: types[0],
value: values[1]
},{
type: types[1],
value: values[2]
}];
var regex = stack[1];
var str = values[3];
if (regex && str)
values = str.split(regex); // this doesn't work on ie8 but we don't care:)
else
values = [str];
for (var i = 0, l = values.length; i < l; i+=2) {
if (values[i])
tokens.push({
type: types[2],
value: values[i]
});
if (values[i+1])
tokens.push({
type: types[3],
value: values[i + 1]
});
}
return tokens;
}
}, },
{ {
token : ["string", "text"], // single line token : ["string", "text"], // single line
regex : "(.+)(:$)" regex : "(\\S.*)(:$)"
},
{
regex : "Searching for .*$",
onMatch: function(val, state, stack) {
var parts = val.split("\x01");
var search = parts[1];
if (parts.length < 3)
return "text";
var options = parts[2] == " in" ? parts[5] : parts[6];
if (!/regex/.test(options))
search = lang.escapeRegExp(search);
if (/whole/.test(options))
search = "\\b" + search + "\\b";
var regex = safeCreateRegexp(
"(" + search + ")",
/ sensitive/.test(options) ? "" : "i"
);
if (regex) {
stack[0] = state;
stack[1] = regex;
}
var i = 0;
var tokens = [
{
value: parts[i++] + "'",
type: "text"
},
{
value: parts[i++],
type: "text" // "c9searchresults.keyword"
},
{
value: "'" + parts[i++],
type: "text"
}
];
// replaced
if (parts[2] !== " in") {
tokens.push({
value: "'" + parts[i++] + "'",
type: "text"
}, {
value: parts[i++],
type: "text"
});
}
// path
tokens.push({
value: " " + parts[i++] + " ",
type: "text"
});
// options
if (parts[i+1]) {
tokens.push({
value: "(" + parts[i+1] + ")",
type: "text"
});
i += 1;
} else {
i -= 1;
}
while (i++ < parts.length)
parts[i] && tokens.push({
value: parts[i],
type: "text"
});
return tokens;
}
},
{
regex : "\\d+",
token: "constant.numeric"
} }
] ]
}; };
@ -56,4 +171,4 @@ oop.inherits(C9SearchHighlightRules, TextHighlightRules);
exports.C9SearchHighlightRules = C9SearchHighlightRules; exports.C9SearchHighlightRules = C9SearchHighlightRules;
}); });

View file

@ -52,7 +52,7 @@ oop.inherits(FoldMode, BaseFoldMode);
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/; this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/; this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
this.getFoldWidgetRange = function(session, foldStyle, row) { this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
var line = session.getLine(row); var line = session.getLine(row);
var match = line.match(this.foldingStartMarker); var match = line.match(this.foldingStartMarker);
if (match) { if (match) {
@ -60,11 +60,20 @@ oop.inherits(FoldMode, BaseFoldMode);
if (match[1]) if (match[1])
return this.openingBracketBlock(session, match[1], row, i); return this.openingBracketBlock(session, match[1], row, i);
return session.getCommentFoldRange(row, i + match[0].length, 1); var range = session.getCommentFoldRange(row, i + match[0].length, 1);
if (range && !range.isMultiLine()) {
if (forceMultiline) {
range = this.getSectionRange(session, row);
} else if (foldStyle != "all")
range = null;
}
return range;
} }
if (foldStyle !== "markbeginend") if (foldStyle === "markbegin")
return; return;
var match = line.match(this.foldingStopMarker); var match = line.match(this.foldingStopMarker);
@ -77,6 +86,38 @@ oop.inherits(FoldMode, BaseFoldMode);
return session.getCommentFoldRange(row, i, -1); return session.getCommentFoldRange(row, i, -1);
} }
}; };
this.getSectionRange = function(session, row) {
var line = session.getLine(row);
var startIndent = line.search(/\S/);
var startRow = row;
var startColumn = line.length;
row = row + 1;
var endRow = row;
var maxRow = session.getLength();
while (++row < maxRow) {
line = session.getLine(row);
var indent = line.search(/\S/);
if (indent === -1)
continue;
if (startIndent > indent)
break;
var subRange = this.getFoldWidgetRange(session, "all", row);
if (subRange) {
if (subRange.start.row <= startRow) {
break;
} else if (subRange.isMultiLine()) {
row = subRange.end.row;
} else if (startIndent == indent) {
break;
}
}
endRow = row;
}
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
};
}).call(FoldMode.prototype); }).call(FoldMode.prototype);

View file

@ -76,6 +76,30 @@ module.exports = {
assert.range(session.getFoldWidgetRange(0), 0, 2, 2, 7); assert.range(session.getFoldWidgetRange(0), 0, 2, 2, 7);
assert.range(session.getFoldWidgetRange(2), 0, 2, 2, 7); assert.range(session.getFoldWidgetRange(2), 0, 2, 2, 7);
},
"test: fold sections": function() {
var session = new EditSession([
'/* section0 */',
'{',
' /* section1 */',
' stuff',
' ',
' /* section2 */',
' ',
' stuff',
' ',
' }',
'foo'
]);
var mode = new JavaScriptMode();
session.setFoldStyle("markbegin");
session.setMode(mode);
assert.range(session.getFoldWidgetRange(0, true), 0, 14, 10, 3);
assert.range(session.getFoldWidgetRange(2, true), 2, 18, 3, 9);
assert.range(session.getFoldWidgetRange(5, true), 5, 18, 7, 9);
} }
}; };

View file

@ -94,7 +94,7 @@ var FoldMode = exports.FoldMode = function() {};
var fw = session.foldWidgets[end.row]; var fw = session.foldWidgets[end.row];
if (fw == null) if (fw == null)
fw = this.getFoldWidget(session, end.row); fw = session.getFoldWidget(end.row);
if (fw == "start" && end.row > start.row) { if (fw == "start" && end.row > start.row) {
end.row --; end.row --;

View file

@ -36,9 +36,11 @@ var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer; var Tokenizer = require("../tokenizer").Tokenizer;
var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules; var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules;
var Range = require("../range").Range; var Range = require("../range").Range;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() { var Mode = function() {
this.HighlightRules = ShHighlightRules; this.HighlightRules = ShHighlightRules;
this.foldingRules = new CStyleFoldMode();
}; };
oop.inherits(Mode, TextMode); oop.inherits(Mode, TextMode);

View file

@ -73,7 +73,7 @@ function FoldHandler(editor) {
var range = data.range || data.firstRange; var range = data.range || data.firstRange;
if (range) { if (range) {
var row = range.start.row; row = range.start.row;
var fold = session.getFoldAt(row, session.getLine(row).length, 1); var fold = session.getFoldAt(row, session.getLine(row).length, 1);
if (fold) { if (fold) {

View file

@ -693,7 +693,7 @@ var Editor = require("./editor").Editor;
var range = sel.toOrientedRange(); var range = sel.toOrientedRange();
if (range.isEmpty()) { if (range.isEmpty()) {
var range = session.getWordRange(range.start.row, range.start.column); range = session.getWordRange(range.start.row, range.start.column);
range.cursor = dir == -1 ? range.start : range.end; range.cursor = dir == -1 ? range.start : range.end;
this.multiSelect.addRange(range); this.multiSelect.addRange(range);
return; return;
@ -703,7 +703,11 @@ var Editor = require("./editor").Editor;
var newRange = find(session, needle, dir); var newRange = find(session, needle, dir);
if (newRange) { if (newRange) {
newRange.cursor = dir == -1 ? newRange.start : newRange.end; newRange.cursor = dir == -1 ? newRange.start : newRange.end;
this.$blockScrolling += 1;
this.session.unfold(newRange);
this.multiSelect.addRange(newRange); this.multiSelect.addRange(newRange);
this.$blockScrolling -= 1;
this.renderer.scrollCursorIntoView(null, 0.5);
} }
if (skip) if (skip)
this.multiSelect.substractPoint(range.cursor); this.multiSelect.substractPoint(range.cursor);
@ -721,11 +725,27 @@ var Editor = require("./editor").Editor;
if (!ranges.length) { if (!ranges.length) {
var range = this.selection.getRange(); var range = this.selection.getRange();
var fr = range.start.row, lr = range.end.row; var fr = range.start.row, lr = range.end.row;
var guessRange = fr == lr;
if (guessRange) {
var max = this.session.getLength();
var line;
do {
line = this.session.getLine(lr);
} while (/[=:]/.test(line) && ++lr < max);
do {
line = this.session.getLine(fr);
} while (/[=:]/.test(line) && --fr > 0);
if (fr < 0) fr = 0;
if (lr >= max) lr = max - 1;
}
var lines = this.session.doc.removeLines(fr, lr); var lines = this.session.doc.removeLines(fr, lr);
lines = this.$reAlignText(lines); lines = this.$reAlignText(lines, guessRange);
this.session.doc.insertLines(fr, lines); this.session.doc.insert({row: fr, column: 0}, lines.join("\n") + "\n");
range.start.column = 0; if (!guessRange) {
range.end.column = lines[lines.length - 1].length; range.start.column = 0;
range.end.column = lines[lines.length - 1].length;
}
this.selection.setRange(range); this.selection.setRange(range);
} else { } else {
// filter out ranges on same row // filter out ranges on same row
@ -771,7 +791,7 @@ var Editor = require("./editor").Editor;
} }
}; };
this.$reAlignText = function(lines) { this.$reAlignText = function(lines, forceLeft) {
var isLeftAligned = true, isRightAligned = true; var isLeftAligned = true, isRightAligned = true;
var startW, textW, endW; var startW, textW, endW;
@ -800,7 +820,8 @@ var Editor = require("./editor").Editor;
endW = m[3].length; endW = m[3].length;
return m; return m;
}).map(isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign); }).map(forceLeft ? alignLeft :
isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
function spaces(n) { function spaces(n) {
return lang.stringRepeat(" ", n); return lang.stringRepeat(" ", n);

View file

@ -32,7 +32,14 @@
.ace-tomorrow-night-bright .ace_marker-layer .ace_bracket { .ace-tomorrow-night-bright .ace_marker-layer .ace_bracket {
margin: -1px 0 0 -1px; margin: -1px 0 0 -1px;
border: 1px solid #343434 border: 1px solid #888888
}
.ace-tomorrow-night-bright .ace_marker-layer .ace_highlight {
border: 1px solid rgb(110, 119, 0);
border-bottom: 0;
box-shadow: inset 0 -1px rgb(110, 119, 0);
margin: -1px 0 0 -1px;
background: rgba(255, 235, 0, 0.1);
} }
.ace-tomorrow-night-bright .ace_marker-layer .ace_active-line { .ace-tomorrow-night-bright .ace_marker-layer .ace_active-line {
@ -48,7 +55,7 @@
} }
.ace-tomorrow-night-bright .ace_marker-layer .ace_selected-word { .ace-tomorrow-night-bright .ace_marker-layer .ace_selected-word {
border: 1px solid #424242 border: 1px solid #888888
} }
.ace-tomorrow-night-bright .ace_invisible { .ace-tomorrow-night-bright .ace_invisible {
@ -123,6 +130,10 @@
color: #969896 color: #969896
} }
.ace-tomorrow-night-bright .ace_c9searchresults.ace_keyword {
color: #C2C280;
}
.ace-tomorrow-night-bright .ace_indent-guide { .ace-tomorrow-night-bright .ace_indent-guide {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYFBXV/8PAAJoAXX4kT2EAAAAAElFTkSuQmCC) right repeat-y; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYFBXV/8PAAJoAXX4kT2EAAAAAElFTkSuQmCC) right repeat-y;
} }

View file

@ -310,7 +310,7 @@ var Tokenizer = function(rules) {
token = { token = {
value: line.substring(lastIndex, lastIndex += 2000), value: line.substring(lastIndex, lastIndex += 2000),
type: "overflow" type: "overflow"
} };
} }
currentState = "start"; currentState = "start";
stack = []; stack = [];

View file

@ -52,14 +52,14 @@ var UndoManager = function() {
(function() { (function() {
/** /**
* Provides a means for implementing your own undo manager. `options` has one property, `args`, an [[Array `Array`]], with two elements: * Provides a means for implementing your own undo manager. `options` has one property, `args`, an [[Array `Array`]], with two elements:
* *
* - `args[0]` is an array of deltas * - `args[0]` is an array of deltas
* - `args[1]` is the document to associate with * - `args[1]` is the document to associate with
* *
* @param {Object} options Contains additional properties * @param {Object} options Contains additional properties
* *
**/ **/
this.execute = function(options) { this.execute = function(options) {
var deltas = options.args[0]; var deltas = options.args[0];
this.$doc = options.args[1]; this.$doc = options.args[1];
@ -78,12 +78,12 @@ var UndoManager = function() {
}; };
/** /**
* [Perform an undo operation on the document, reverting the last change.]{: #UndoManager.undo} * [Perform an undo operation on the document, reverting the last change.]{: #UndoManager.undo}
* @param {Boolean} dontSelect {:dontSelect} * @param {Boolean} dontSelect {:dontSelect}
* *
* *
* @returns {Range} The range of the undo. * @returns {Range} The range of the undo.
**/ **/
this.undo = function(dontSelect) { this.undo = function(dontSelect) {
var deltas = this.$undoStack.pop(); var deltas = this.$undoStack.pop();
var undoSelectionRange = null; var undoSelectionRange = null;
@ -98,11 +98,11 @@ var UndoManager = function() {
}; };
/** /**
* [Perform a redo operation on the document, reimplementing the last change.]{: #UndoManager.redo} * [Perform a redo operation on the document, reimplementing the last change.]{: #UndoManager.redo}
* @param {Boolean} dontSelect {:dontSelect} * @param {Boolean} dontSelect {:dontSelect}
* *
* *
**/ **/
this.redo = function(dontSelect) { this.redo = function(dontSelect) {
var deltas = this.$redoStack.pop(); var deltas = this.$redoStack.pop();
var redoSelectionRange = null; var redoSelectionRange = null;
@ -117,9 +117,9 @@ var UndoManager = function() {
}; };
/** /**
* *
* Destroys the stack of undo and redo redo operations. * Destroys the stack of undo and redo redo operations.
**/ **/
this.reset = function() { this.reset = function() {
this.$undoStack = []; this.$undoStack = [];
this.$redoStack = []; this.$redoStack = [];
@ -127,36 +127,36 @@ var UndoManager = function() {
}; };
/** /**
* *
* Returns `true` if there are undo operations left to perform. * Returns `true` if there are undo operations left to perform.
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.hasUndo = function() { this.hasUndo = function() {
return this.$undoStack.length > 0; return this.$undoStack.length > 0;
}; };
/** /**
* *
* Returns `true` if there are redo operations left to perform. * Returns `true` if there are redo operations left to perform.
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.hasRedo = function() { this.hasRedo = function() {
return this.$redoStack.length > 0; return this.$redoStack.length > 0;
}; };
/** /**
* *
* Marks the current status clean * Marks the current status clean
**/ **/
this.markClean = function() { this.markClean = function() {
this.dirtyCounter = 0; this.dirtyCounter = 0;
}; };
/** /**
* *
* Returns if the current status is clean * Returns if the current status is clean
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.isClean = function() { this.isClean = function() {
return this.dirtyCounter === 0; return this.dirtyCounter === 0;
}; };

View file

@ -134,7 +134,8 @@ var VirtualRenderer = function(container, theme) {
width: 0, width: 0,
height: 0, height: 0,
scrollerHeight: 0, scrollerHeight: 0,
scrollerWidth: 0 scrollerWidth: 0,
$dirty: true
}; };
this.layerConfig = { this.layerConfig = {
@ -223,6 +224,9 @@ var VirtualRenderer = function(container, theme) {
**/ **/
this.setSession = function(session) { this.setSession = function(session) {
this.session = session; this.session = session;
if (this.scrollMargin.top && session.getScrollTop() <= 0)
session.setScrollTop(-this.scrollMargin.top);
this.scroller.className = "ace_scroller"; this.scroller.className = "ace_scroller";
@ -232,7 +236,6 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer.setSession(session); this.$gutterLayer.setSession(session);
this.$textLayer.setSession(session); this.$textLayer.setSession(session);
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
}; };
/** /**
@ -300,6 +303,12 @@ var VirtualRenderer = function(container, theme) {
}; };
this.$changes = 0; this.$changes = 0;
this.$updateSizeAsync = function() {
if (this.$loop.pending)
this.$size.$dirty = true;
else
this.onResize();
};
/** /**
* [Triggers a resize of the editor.]{: #VirtualRenderer.onResize} * [Triggers a resize of the editor.]{: #VirtualRenderer.onResize}
* @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed * @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed
@ -325,7 +334,6 @@ var VirtualRenderer = function(container, theme) {
height = el.clientHeight || el.scrollHeight; height = el.clientHeight || el.scrollHeight;
if (!width) if (!width)
width = el.clientWidth || el.scrollWidth; width = el.clientWidth || el.scrollWidth;
var changes = this.$updateCachedSize(force, gutterWidth, width, height); var changes = this.$updateCachedSize(force, gutterWidth, width, height);
// console.log("resizing to", width, height, JSON.stringify(this.$size)) // console.log("resizing to", width, height, JSON.stringify(this.$size))
@ -342,7 +350,7 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer.$padding = null; this.$gutterLayer.$padding = null;
if (force) if (force)
this.$renderChanges(changes, true); this.$renderChanges(changes | this.$changes, true);
else else
this.$loop.schedule(changes | this.$changes); this.$loop.schedule(changes | this.$changes);
@ -371,7 +379,7 @@ var VirtualRenderer = function(container, theme) {
this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px"; this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
if (this.session) { if (this.session) {
this.session.setScrollTop(this.getScrollTop()); //this.session.setScrollTop(this.getScrollTop());
changes = changes | this.CHANGE_SCROLL; changes = changes | this.CHANGE_SCROLL;
} }
} }
@ -399,6 +407,9 @@ var VirtualRenderer = function(container, theme) {
changes = changes | this.CHANGE_FULL; changes = changes | this.CHANGE_FULL;
} }
if (size.$dirty)
size.$dirty = !width && !height;
if (changes) if (changes)
this._signal("resize", oldSize); this._signal("resize", oldSize);
@ -410,9 +421,11 @@ var VirtualRenderer = function(container, theme) {
if (gutterWidth != this.gutterWidth) if (gutterWidth != this.gutterWidth)
this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height); this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
if (this.session.getUseWrapMode() && this.adjustWrapLimit()) if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
else { } else if (this.$size.$dirty) {
this.$loop.schedule(this.CHANGE_FULL);
} else {
this.$computeLayerConfig(); this.$computeLayerConfig();
this.$loop.schedule(this.CHANGE_MARKER); this.$loop.schedule(this.CHANGE_MARKER);
} }
@ -692,6 +705,8 @@ var VirtualRenderer = function(container, theme) {
sm.left = left|0; sm.left = left|0;
sm.v = sm.top + sm.bottom; sm.v = sm.top + sm.bottom;
sm.h = sm.left + sm.right; sm.h = sm.left + sm.right;
if (sm.top && this.scrollTop <= 0 && this.session)
this.session.setScrollTop(sm.top);
this.updateFull(); this.updateFull();
}; };
@ -744,7 +759,7 @@ var VirtualRenderer = function(container, theme) {
this.$changes |= changes; this.$changes |= changes;
return; return;
} }
if (!this.$size.width) { if (this.$size.$dirty) {
this.$changes |= changes; this.$changes |= changes;
return this.onResize(true); return this.onResize(true);
} }
@ -972,6 +987,7 @@ var VirtualRenderer = function(container, theme) {
this.content.style.height = minHeight + "px"; this.content.style.height = minHeight + "px";
return changes; return changes;
return changes;
}; };
this.$updateLines = function() { this.$updateLines = function() {

View file

@ -13,7 +13,9 @@ var Mirror = exports.Mirror = function(sender) {
var _self = this; var _self = this;
sender.on("change", function(e) { sender.on("change", function(e) {
doc.applyDeltas(e.data); doc.applyDeltas(e.data);
deferredUpdate.schedule(_self.$timeout); if (_self.$timeout)
return deferredUpdate.schedule(_self.$timeout);
_self.onUpdate();
}); });
}; };
@ -38,6 +40,10 @@ var Mirror = exports.Mirror = function(sender) {
// abstract method // abstract method
}; };
this.isPending = function() {
return this.deferredUpdate.isPending();
};
}).call(Mirror.prototype); }).call(Mirror.prototype);
}); });

View file

@ -16,6 +16,10 @@ window.console.trace = window.console;
window.window = window; window.window = window;
window.ace = window; window.ace = window;
window.onerror = function(message, file, line, col, err) {
console.error("Worker " + err.stack);
};
window.normalizeModule = function(parentId, moduleName) { window.normalizeModule = function(parentId, moduleName) {
// normalize plugin requires // normalize plugin requires
if (moduleName.indexOf("!") !== -1) { if (moduleName.indexOf("!") !== -1) {

View file

@ -39,7 +39,6 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this); this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
this.changeListener = this.changeListener.bind(this); this.changeListener = this.changeListener.bind(this);
this.onMessage = this.onMessage.bind(this); this.onMessage = this.onMessage.bind(this);
this.onError = this.onError.bind(this);
// nameToUrl is renamed to toUrl in requirejs 2 // nameToUrl is renamed to toUrl in requirejs 2
if (require.nameToUrl && !require.toUrl) if (require.nameToUrl && !require.toUrl)
@ -69,7 +68,6 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
this.callbackId = 1; this.callbackId = 1;
this.callbacks = {}; this.callbacks = {};
this.$worker.onerror = this.onError;
this.$worker.onmessage = this.onMessage; this.$worker.onmessage = this.onMessage;
}; };
@ -77,11 +75,6 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
oop.implement(this, EventEmitter); oop.implement(this, EventEmitter);
this.onError = function(e) {
window.console && console.log && console.log(e);
throw e;
};
this.onMessage = function(e) { this.onMessage = function(e) {
var msg = e.data; var msg = e.data;
switch(msg.type) { switch(msg.type) {
@ -157,7 +150,7 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
this.changeListener = function(e) { this.changeListener = function(e) {
if (!this.deltaQueue) { if (!this.deltaQueue) {
this.deltaQueue = [e.data]; this.deltaQueue = [e.data];
setTimeout(this.$sendDeltaQueue, 1); setTimeout(this.$sendDeltaQueue, 0);
} else } else
this.deltaQueue.push(e.data); this.deltaQueue.push(e.data);
}; };