Fixed gotoLine to consider wrapped lines when calculating where to scroll to
I have created a new method VirtualRenderer#scrollToLine to do for lines what scrollToRow does for absolute rows in the editor. Previously gotoLine called scrollToRow which would jump to the nth row, but with line wraps this may not be the nth line. scrollToLine also takes an additional parameter to tell it whether to scroll the line to the top or center of the editor.
This commit is contained in:
parent
9226825600
commit
438339167f
2 changed files with 17 additions and 1 deletions
|
|
@ -790,6 +790,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();
|
||||
|
|
@ -820,7 +823,7 @@ var Editor =function(renderer, session) {
|
|||
this.$blockScrolling = false;
|
||||
|
||||
if (!this.isRowVisible(this.getCursorPosition().row)) {
|
||||
this.scrollToRow(lineNumber - 1 - Math.floor(this.getVisibleRowCount() / 2));
|
||||
this.scrollToLine(lineNumber, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue