diff --git a/demo/editor.html b/demo/editor.html
index 11e53d7f..e93d2bee 100644
--- a/demo/editor.html
+++ b/demo/editor.html
@@ -34,7 +34,6 @@
#controls {
width: 100%;
height: 55px;
- margin: 0;
}
diff --git a/src/Document.js b/src/Document.js
index 2a7855b3..9806ad06 100644
--- a/src/Document.js
+++ b/src/Document.js
@@ -80,6 +80,18 @@ ace.Document.prototype.getMode = function() {
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() {
if (this.modified) {
this.modified = false;
diff --git a/src/Editor.js b/src/Editor.js
index b094a05e..a7881fd7 100644
--- a/src/Editor.js
+++ b/src/Editor.js
@@ -38,6 +38,8 @@ ace.Editor.prototype.setDocument = function(doc) {
var selection = this.doc.getSelection();
this.selection.removeEventListener("changeCursor", this._onCursorChange);
this.selection.removeEventListener("changeSelection", this._onSelectionChange);
+
+ this.doc.setScrollTopRow(this.renderer.getScrollTopRow());
}
this.doc = doc;
@@ -66,6 +68,7 @@ ace.Editor.prototype.setDocument = function(doc) {
this.renderer.draw();
this.onCursorChange();
this.onSelectionChange();
+ this.renderer.scrollToRow(doc.getScrollTopRow());
};
ace.Editor.prototype.getDocument = function() {
diff --git a/src/VirtualRenderer.js b/src/VirtualRenderer.js
index 18ee8451..ee3ed56b 100644
--- a/src/VirtualRenderer.js
+++ b/src/VirtualRenderer.js
@@ -198,6 +198,10 @@ ace.VirtualRenderer.prototype.getScrollTop = function() {
return this.scrollTop;
};
+ace.VirtualRenderer.prototype.getScrollTopRow = function() {
+ return this.scrollTop / this.lineHeight;
+};
+
ace.VirtualRenderer.prototype.scrollToRow = function(row) {
this.scrollToY(row * this.lineHeight);
};