Merge branch 'master' of github.com:ajaxorg/ace

This commit is contained in:
Eddy Bruel 2010-11-03 17:27:57 +01:00
commit 6df42adcba
9 changed files with 65 additions and 40 deletions

View file

@ -120,8 +120,11 @@ var BackgroundTokenizer = function(tokenizer, editor) {
this.lines[row] = tokens; this.lines[row] = tokens;
} }
} }
else else {
rows.push(this.lines[row]); var tokens = this.lines[row];
state = tokens.state;
rows.push(tokens);
}
} }
return rows; return rows;
}; };

View file

@ -513,9 +513,7 @@ var Document = function(text, mode) {
this.$remove(range, fromUndo); this.$remove(range, fromUndo);
this.fireChangeEvent(range.start.row, this.fireChangeEvent(range.start.row, range.isMultiLine() ? undefined : range.start.row);
!range.isMultiLine() ? range.start.row
: undefined);
return range.start; return range.start;
}; };
@ -634,7 +632,8 @@ var Document = function(text, mode) {
this.moveLinesUp = function(firstRow, lastRow) { this.moveLinesUp = function(firstRow, lastRow) {
if (firstRow <= 0) return 0; if (firstRow <= 0) return 0;
var removed = this.lines.splice(firstRow, lastRow-firstRow+1); var removed = this.lines.slice(firstRow, lastRow + 1);
this.$remove(new Range(firstRow, 0, lastRow + 1, 0));
this.$insertLines(firstRow - 1, removed); this.$insertLines(firstRow - 1, removed);
this.fireChangeEvent(firstRow - 1, lastRow); this.fireChangeEvent(firstRow - 1, lastRow);
@ -644,7 +643,8 @@ var Document = function(text, mode) {
this.moveLinesDown = function(firstRow, lastRow) { this.moveLinesDown = function(firstRow, lastRow) {
if (lastRow >= this.lines.length-1) return 0; if (lastRow >= this.lines.length-1) return 0;
var removed = this.lines.splice(firstRow, lastRow-firstRow+1); var removed = this.lines.slice(firstRow, lastRow + 1);
this.$remove(new Range(firstRow, 0, lastRow + 1, 0));
this.$insertLines(firstRow+1, removed); this.$insertLines(firstRow+1, removed);
this.fireChangeEvent(firstRow, lastRow + 1); this.fireChangeEvent(firstRow, lastRow + 1);

View file

@ -913,7 +913,6 @@ var Editor =function(renderer, doc) {
}; };
this.replace = function(replacement, options) { this.replace = function(replacement, options) {
console.log("replacing with " + replacement);
if (options) if (options)
this.$search.set(options); this.$search.set(options);

View file

@ -16,6 +16,8 @@ var RenderLoop = function(onRender) {
(function() { (function() {
this.schedule = function(change) { this.schedule = function(change) {
// this.onRender(change);
// return;
this.changes = this.changes | change; this.changes = this.changes | change;
if (!this.pending) { if (!this.pending) {
this.pending = true; this.pending = true;

View file

@ -260,11 +260,13 @@ var Selection = function(doc) {
var row = this.selectionLead.row; var row = this.selectionLead.row;
var column = this.selectionLead.column; var column = this.selectionLead.column;
var beforeCursor = this.doc.getLine(row).slice(0, column); var beforeCursor = this.doc.getLine(row).slice(0, column);
var leadingSpace = beforeCursor.match(/^\s+/); var leadingSpace = beforeCursor.match(/^\s*/);
if (!leadingSpace || leadingSpace[0].length >= column) if (leadingSpace[0].length == 0)
this.moveCursorTo(this.selectionLead.row, 0); this.moveCursorTo(row, this.doc.getLine(row).match(/^\s*/)[0].length);
else if (leadingSpace[0].length >= column)
this.moveCursorTo(row, 0);
else else
this.moveCursorTo(this.selectionLead.row, leadingSpace[0].length); this.moveCursorTo(row, leadingSpace[0].length);
}; };
this.moveCursorLineEnd = function() { this.moveCursorLineEnd = function() {

View file

@ -84,10 +84,11 @@ var VirtualRenderer = function(container, theme) {
scrollerWidth: 0 scrollerWidth: 0
}; };
this.$updatePrintMargin();
this.$loop = new RenderLoop(lang.bind(this.$renderChanges, this)); this.$loop = new RenderLoop(lang.bind(this.$renderChanges, this));
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
this.$updatePrintMargin();
this.setPadding(4);
}; };
(function() { (function() {
@ -119,6 +120,9 @@ var VirtualRenderer = function(container, theme) {
* Triggers partial update of the text layer * Triggers partial update of the text layer
*/ */
this.updateLines = function(firstRow, lastRow) { this.updateLines = function(firstRow, lastRow) {
if (lastRow === undefined)
lastRow = Infinity;
if (!this.$changedLines) { if (!this.$changedLines) {
this.$changedLines = { this.$changedLines = {
firstRow: firstRow, firstRow: firstRow,
@ -132,8 +136,6 @@ var VirtualRenderer = function(container, theme) {
if (this.$changedLines.lastRow < lastRow) if (this.$changedLines.lastRow < lastRow)
this.$changedLines.lastRow = lastRow; this.$changedLines.lastRow = lastRow;
} }
if (this.$changedLines.lastRow === undefined)
this.$changedLines.lastRow = Infinity;
this.$loop.schedule(this.CHANGE_LINES); this.$loop.schedule(this.CHANGE_LINES);
}; };
@ -185,6 +187,7 @@ var VirtualRenderer = function(container, theme) {
}; };
this.setTokenizer = function(tokenizer) { this.setTokenizer = function(tokenizer) {
this.$tokenizer = tokenizer;
this.$textLayer.setTokenizer(tokenizer); this.$textLayer.setTokenizer(tokenizer);
this.$loop.schedule(this.CHANGE_TEXT); this.$loop.schedule(this.CHANGE_TEXT);
}; };
@ -283,17 +286,24 @@ var VirtualRenderer = function(container, theme) {
return (this.layerConfig || {}).lastRow || 0; return (this.layerConfig || {}).lastRow || 0;
}; };
this.$padding = null;
this.setPadding = function(padding) {
this.$padding = padding;
this.content.style.padding = "0 " + padding + "px";
this.$loop.schedule(this.CHANGE_FULL);
};
this.onScroll = function(e) { this.onScroll = function(e) {
this.scrollToY(e.data); this.scrollToY(e.data);
}; };
this.$updateScrollBar = function() { this.$updateScrollBar = function() {
this.scrollBar.setInnerHeight(this.doc.getLength() * this.lineHeight); this.scrollBar.setInnerHeight(this.doc.getLength() * this.lineHeight + this.$padding);
this.scrollBar.setScrollTop(this.scrollTop); this.scrollBar.setScrollTop(this.scrollTop);
}; };
this.$renderChanges = function(changes) { this.$renderChanges = function(changes) {
if (!changes) if (!changes || !this.doc || !this.$tokenizer)
return; return;
// text, scrolling and resize changes can cause the view port size to change // text, scrolling and resize changes can cause the view port size to change
@ -368,11 +378,12 @@ var VirtualRenderer = function(container, theme) {
var widthChanged = !this.layerConfig ? true : (this.layerConfig.width != longestLine); var widthChanged = !this.layerConfig ? true : (this.layerConfig.width != longestLine);
var lineCount = Math.ceil(minHeight / this.lineHeight); var lineCount = Math.ceil(minHeight / this.lineHeight);
var firstRow = Math.round((this.scrollTop - offset) / this.lineHeight); var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
var lastRow = Math.min(this.lines.length, firstRow + lineCount) - 1; var lastRow = Math.min(this.lines.length, firstRow + lineCount) - 1;
var layerConfig = this.layerConfig = { var layerConfig = this.layerConfig = {
width : longestLine, width : longestLine,
padding : this.$padding,
firstRow : firstRow, firstRow : firstRow,
lastRow : lastRow, lastRow : lastRow,
lineHeight : this.lineHeight, lineHeight : this.lineHeight,
@ -392,16 +403,14 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer.element.style.marginTop = (-offset) + "px"; this.$gutterLayer.element.style.marginTop = (-offset) + "px";
this.content.style.marginTop = (-offset) + "px"; this.content.style.marginTop = (-offset) + "px";
this.content.style.width = longestLine + "px";
this.content.style.height = minHeight + "px"; this.content.style.height = minHeight + "px";
}; };
this.$updateLines = function() { this.$updateLines = function() {
var firstRow = this.$changedLines.firstRow; var firstRow = this.$changedLines.firstRow;
var lastRow = this.$changedLines.lastRow; var lastRow = this.$changedLines.lastRow;
this.$changedLines = { this.$changedLines = null;
firstRow: 0,
lastRow: Infinity
};
var layerConfig = this.layerConfig; var layerConfig = this.layerConfig;
@ -428,7 +437,7 @@ var VirtualRenderer = function(container, theme) {
if (this.$showInvisibles) if (this.$showInvisibles)
charCount += 1; charCount += 1;
return Math.max(this.$size.scrollerWidth, Math.round(charCount * this.characterWidth)); return Math.max(this.$size.scrollerWidth - this.$padding * 2, Math.round(charCount * this.characterWidth));
}; };
this.addMarker = function(range, clazz, type) { this.addMarker = function(range, clazz, type) {
@ -473,7 +482,7 @@ var VirtualRenderer = function(container, theme) {
this.scrollCursorIntoView = function() { this.scrollCursorIntoView = function() {
var pos = this.$cursorLayer.getPixelPosition(); var pos = this.$cursorLayer.getPixelPosition();
var left = pos.left; var left = pos.left + this.$padding;
var top = pos.top; var top = pos.top;
if (this.getScrollTop() > top) { if (this.getScrollTop() > top) {
@ -486,13 +495,13 @@ var VirtualRenderer = function(container, theme) {
} }
if (this.scroller.scrollLeft > left) { if (this.scroller.scrollLeft > left) {
this.scroller.scrollLeft = left; this.scrollToX(left);
} }
if (this.scroller.scrollLeft + this.$size.scrollerWidth < left if (this.scroller.scrollLeft + this.$size.scrollerWidth < left
+ this.characterWidth) { + this.characterWidth) {
this.scroller.scrollLeft = Math.round(left + this.characterWidth this.scrollToX(Math.round(left + this.characterWidth
- this.$size.scrollerWidth); - this.$size.scrollerWidth));
} }
}, },
@ -513,7 +522,10 @@ var VirtualRenderer = function(container, theme) {
}; };
this.scrollToY = function(scrollTop) { this.scrollToY = function(scrollTop) {
var maxHeight = this.lines.length * this.lineHeight - this.$size.scrollerHeight; var maxHeight = this.lines.length * this.lineHeight - this.$size.scrollerHeight + this.$padding;
if (scrollTop >= maxHeight - this.$padding)
scrollTop = maxHeight;
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop)); var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
if (this.scrollTop !== scrollTop) { if (this.scrollTop !== scrollTop) {
@ -522,15 +534,22 @@ var VirtualRenderer = function(container, theme) {
} }
}; };
this.scrollToX = function(scrollLeft) {
if (scrollLeft <= this.$padding)
scrollLeft = 0;
this.scroller.scrollLeft = scrollLeft;
};
this.scrollBy = function(deltaX, deltaY) { this.scrollBy = function(deltaX, deltaY) {
deltaY && this.scrollToY(this.scrollTop + deltaY); deltaY && this.scrollToY(this.scrollTop + deltaY);
deltaX && (this.scroller.scrollLeft += deltaX); deltaX && this.scrollToX(this.scroller.scrollLeft + deltaX);
}; };
this.screenToTextCoordinates = function(pageX, pageY) { this.screenToTextCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect(); var canvasPos = this.scroller.getBoundingClientRect();
var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left) var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left - this.$padding)
/ this.characterWidth); / this.characterWidth);
var row = Math.floor((pageY + this.scrollTop - canvasPos.top) var row = Math.floor((pageY + this.scrollTop - canvasPos.top)
/ this.lineHeight); / this.lineHeight);
@ -544,7 +563,7 @@ var VirtualRenderer = function(container, theme) {
this.textToScreenCoordinates = function(row, column) { this.textToScreenCoordinates = function(row, column) {
var canvasPos = this.scroller.getBoundingClientRect(); var canvasPos = this.scroller.getBoundingClientRect();
var x = Math.round(this.doc.documentToScreenColumn(row, column) * this.characterWidth); var x = this.padding + Math.round(this.doc.documentToScreenColumn(row, column) * this.characterWidth);
var y = row * this.lineHeight; var y = row * this.lineHeight;
return { return {

View file

@ -26,7 +26,7 @@ return {
"selectup": "Shift-Up", "selectup": "Shift-Up",
"golineup": "Up", "golineup": "Up",
"copylinesdown": "Command-Option-Down", "copylinesdown": "Command-Option-Down",
"movelinsedown": "Option-Down", "movelinesdown": "Option-Down",
"selecttoend": "Command-Shift-Down", "selecttoend": "Command-Shift-Down",
"gotoend": "Command-End|Command-Down", "gotoend": "Command-End|Command-Down",
"selectdown": "Shift-Down", "selectdown": "Shift-Down",

View file

@ -26,7 +26,7 @@ return {
"selectup": "Shift-Up", "selectup": "Shift-Up",
"golineup": "Up", "golineup": "Up",
"copylinesdown": "Ctrl-Alt-Down", "copylinesdown": "Ctrl-Alt-Down",
"movelinsedown": "Alt-Down", "movelinesdown": "Alt-Down",
"selecttoend": "Ctrl-Shift-Down", "selecttoend": "Ctrl-Shift-Down",
"gotoend": "Ctrl-End|Ctrl-Down", "gotoend": "Ctrl-End|Ctrl-Down",
"selectdown": "Shift-Down", "selectdown": "Shift-Down",

View file

@ -41,7 +41,7 @@ oop.inherits(DocCommentHighlightRules, TextHighlightRules);
this.getStartRule = function(start) { this.getStartRule = function(start) {
return { return {
token : "comment.doc", // doc comment token : "comment.doc", // doc comment
regex : "\\/\\*\\*", regex : "\\/\\*(?=\\*)",
next: start next: start
}; };
}; };