Store the top scroll top in the document

This commit is contained in:
Fabian Jakobs 2010-04-20 17:25:48 +02:00
commit 150ab68452
4 changed files with 19 additions and 1 deletions

View file

@ -34,7 +34,6 @@
#controls { #controls {
width: 100%; width: 100%;
height: 55px; height: 55px;
margin: 0;
} }
</style> </style>

View file

@ -80,6 +80,18 @@ ace.Document.prototype.getMode = function() {
return this._mode; return this._mode;
}; };
ace.Document.prototype._scrollTop = 0;
ace.Document.prototype.setScrollTopRow = function(scrollTopRow) {
if (this._scrollTop === scrollTopRow) return;
this._scrollTop = scrollTopRow;
this.$dispatchEvent("changeScrollTop");
};
ace.Document.prototype.getScrollTopRow = function() {
return this._scrollTop;
};
ace.Document.prototype.getWidth = function() { ace.Document.prototype.getWidth = function() {
if (this.modified) { if (this.modified) {
this.modified = false; this.modified = false;

View file

@ -38,6 +38,8 @@ ace.Editor.prototype.setDocument = function(doc) {
var selection = this.doc.getSelection(); var selection = this.doc.getSelection();
this.selection.removeEventListener("changeCursor", this._onCursorChange); this.selection.removeEventListener("changeCursor", this._onCursorChange);
this.selection.removeEventListener("changeSelection", this._onSelectionChange); this.selection.removeEventListener("changeSelection", this._onSelectionChange);
this.doc.setScrollTopRow(this.renderer.getScrollTopRow());
} }
this.doc = doc; this.doc = doc;
@ -66,6 +68,7 @@ ace.Editor.prototype.setDocument = function(doc) {
this.renderer.draw(); this.renderer.draw();
this.onCursorChange(); this.onCursorChange();
this.onSelectionChange(); this.onSelectionChange();
this.renderer.scrollToRow(doc.getScrollTopRow());
}; };
ace.Editor.prototype.getDocument = function() { ace.Editor.prototype.getDocument = function() {

View file

@ -198,6 +198,10 @@ ace.VirtualRenderer.prototype.getScrollTop = function() {
return this.scrollTop; return this.scrollTop;
}; };
ace.VirtualRenderer.prototype.getScrollTopRow = function() {
return this.scrollTop / this.lineHeight;
};
ace.VirtualRenderer.prototype.scrollToRow = function(row) { ace.VirtualRenderer.prototype.scrollToRow = function(row) {
this.scrollToY(row * this.lineHeight); this.scrollToY(row * this.lineHeight);
}; };