From 40fa64995d29f07a8fd34d03eadba447b7ac2eb9 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 12 Apr 2010 08:46:06 +0200 Subject: [PATCH] add page up/down selection support --- Editor.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Editor.js b/Editor.js index c1415702..95df4afc 100644 --- a/Editor.js +++ b/Editor.js @@ -70,11 +70,19 @@ function KeyBinding(element, host) return lib.stopEvent(e); case keys.PAGEDOWN: - host.scrollPageDown(); + if (e.shiftKey) { + host.selectPageDown(); + } else { + host.scrollPageDown(); + } return lib.stopEvent(e); case keys.PAGEUP: - host.scrollPageUp(); + if (e.shiftKey) { + host.selectPageUp(); + } else { + host.scrollPageUp(); + } return lib.stopEvent(e); case keys.POS1: @@ -360,6 +368,14 @@ function Editor(doc, renderer) this.removeLeft(); }, + getFirstVisibleRow : function() { + return this.renderer.getFirstVisibleRow(); + }, + + getLastVisibleRow : function() { + return this.renderer.getLastVisibleRow(); + }, + getPageDownRow : function() { return this.renderer.getLastVisibleRow() - 1; }, @@ -600,6 +616,30 @@ function Editor(doc, renderer) this._moveSelection(this.moveCursorLineEnd); }, + selectPageDown : function() + { + var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow(); + var row = this.getPageDownRow() + Math.round(visibleRows / 2); + + this.scrollPageDown(); + + this._moveSelection(function() { + this.moveCursorTo(row, this.cursor.column); + }); + }, + + selectPageUp : function() + { + var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow(); + var row = this.getPageUpRow() + Math.round(visibleRows / 2); + + this.scrollPageUp(); + + this._moveSelection(function() { + this.moveCursorTo(row, this.cursor.column); + }); + }, + selectCurrentLine : function() { this.setSelectionAnchor(this.cursor.row, 0);