Merge remote branch 'jpallen/master'

This commit is contained in:
Fabian Jakobs 2011-02-11 17:42:39 +01:00
commit 08a783d050
2 changed files with 17 additions and 1 deletions

View file

@ -769,6 +769,9 @@ var Editor =function(renderer, session) {
this.renderer.scrollToRow(row);
};
this.scrollToLine = function(line, center) {
this.renderer.scrollToLine(line, center);
};
this.getCursorPosition = function() {
return this.selection.getCursor();
@ -806,7 +809,7 @@ var Editor =function(renderer, session) {
this.$blockScrolling -= 1;
if (!this.isRowVisible(this.getCursorPosition().row)) {
this.scrollToRow(lineNumber - 1 - Math.floor(this.getVisibleRowCount() / 2));
this.scrollToLine(lineNumber, true);
}
},

View file

@ -592,6 +592,19 @@ var VirtualRenderer = function(container, theme) {
this.scrollToY(row * this.lineHeight);
};
this.scrollToLine = function(line, center) {
var lineHeight = { lineHeight: this.lineHeight };
var offset = 0;
for (var l = 1; l < line; l++) {
offset += this.session.getRowHeight(lineHeight, l-1);
}
if (center) {
offset -= this.$size.scrollerHeight / 2;
}
this.scrollToY(offset);
};
this.scrollToY = function(scrollTop) {
var maxHeight = this.session.getScreenLength() * this.lineHeight - this.$size.scrollerHeight;
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));