support page down/up navigation

This commit is contained in:
Fabian Jakobs 2010-04-09 18:16:46 +02:00
commit 03d5b56989
2 changed files with 42 additions and 0 deletions

View file

@ -3,6 +3,8 @@ var keys = {
RIGHT: 39, RIGHT: 39,
DOWN: 40, DOWN: 40,
LEFT: 37, LEFT: 37,
PAGEUP: 33,
PAGEDOWN: 34,
POS1: 36, POS1: 36,
END: 35, END: 35,
DELETE: 46, DELETE: 46,
@ -67,6 +69,14 @@ function KeyBinding(element, host)
} }
return lib.stopEvent(e); 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: case keys.POS1:
if (e.shiftKey) { if (e.shiftKey) {
host.selectLineStart(); host.selectLineStart();
@ -350,6 +360,26 @@ function Editor(doc, renderer)
this.removeLeft(); 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() navigateUp : function()
{ {
this.clearSelection(); this.clearSelection();

View file

@ -46,6 +46,14 @@ VirtualRenderer.prototype.getContainerElement = function() {
return this.container; 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) VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
{ {
var layerConfig = this.layerConfig; var layerConfig = this.layerConfig;
@ -157,6 +165,10 @@ VirtualRenderer.prototype.getScrollTop = function() {
return this.scrollTop; return this.scrollTop;
}; };
VirtualRenderer.prototype.scrollToRow = function(row) {
this.scrollToY(row*this.lineHeight);
}
VirtualRenderer.prototype.scrollToY = function(scrollTop) VirtualRenderer.prototype.scrollToY = function(scrollTop)
{ {
var maxHeight = this.lines.length * this.lineHeight - this.scroller.clientHeight; var maxHeight = this.lines.length * this.lineHeight - this.scroller.clientHeight;