diff --git a/Editor.js b/Editor.js index a77136bd..c1415702 100644 --- a/Editor.js +++ b/Editor.js @@ -3,6 +3,8 @@ var keys = { RIGHT: 39, DOWN: 40, LEFT: 37, + PAGEUP: 33, + PAGEDOWN: 34, POS1: 36, END: 35, DELETE: 46, @@ -67,6 +69,14 @@ function KeyBinding(element, host) } return lib.stopEvent(e); + case keys.PAGEDOWN: + host.scrollPageDown(); + return lib.stopEvent(e); + + case keys.PAGEUP: + host.scrollPageUp(); + return lib.stopEvent(e); + case keys.POS1: if (e.shiftKey) { host.selectLineStart(); @@ -350,6 +360,26 @@ function Editor(doc, renderer) this.removeLeft(); }, + getPageDownRow : function() { + return this.renderer.getLastVisibleRow() - 1; + }, + + getPageUpRow : function() + { + var firstRow = this.renderer.getFirstVisibleRow(); + var lastRow = this.renderer.getLastVisibleRow(); + + return firstRow - (lastRow-firstRow) + 1; + }, + + scrollPageDown : function() { + this.renderer.scrollToRow(this.getPageDownRow()); + }, + + scrollPageUp : function() { + this.renderer.scrollToRow(this.getPageUpRow()); + }, + navigateUp : function() { this.clearSelection(); diff --git a/VirtualRenderer.js b/VirtualRenderer.js index 385fcecd..fdc6967f 100644 --- a/VirtualRenderer.js +++ b/VirtualRenderer.js @@ -46,6 +46,14 @@ VirtualRenderer.prototype.getContainerElement = function() { return this.container; }; +VirtualRenderer.prototype.getFirstVisibleRow = function() { + return this.layerConfig.firstRow || 0; +}; + +VirtualRenderer.prototype.getLastVisibleRow = function() { + return this.layerConfig.lastRow || 0; +}; + VirtualRenderer.prototype.updateLines = function(firstRow, lastRow) { var layerConfig = this.layerConfig; @@ -157,6 +165,10 @@ VirtualRenderer.prototype.getScrollTop = function() { return this.scrollTop; }; +VirtualRenderer.prototype.scrollToRow = function(row) { + this.scrollToY(row*this.lineHeight); +} + VirtualRenderer.prototype.scrollToY = function(scrollTop) { var maxHeight = this.lines.length * this.lineHeight - this.scroller.clientHeight;