From 2b88ca2c71f02521980ea3ba106644c82299547f Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 12 Apr 2010 12:43:45 +0200 Subject: [PATCH] support start of file and end of file scrolling --- src/Editor.js | 54 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/src/Editor.js b/src/Editor.js index 59697511..b37c0476 100644 --- a/src/Editor.js +++ b/src/Editor.js @@ -34,7 +34,9 @@ var KeyBinding = function(element, host) break; case keys.UP: - if (e.shiftKey) { + if (e.metaKey) { + host.navigateFileStart(); + } if (e.shiftKey) { host.selectUp(); } else { host.navigateUp(); @@ -42,9 +44,11 @@ var KeyBinding = function(element, host) return ace.stopEvent(e); case keys.DOWN: - if (e.shiftKey) { + if (e.metaKey) { + host.navigateFileEnd(); + } if (e.shiftKey) { host.selectDown(); - } else { + } else{ host.navigateDown(); } return ace.stopEvent(e); @@ -391,13 +395,17 @@ ace.Editor.prototype.getPageUpRow = function() }; ace.Editor.prototype.scrollPageDown = function() { - this.renderer.scrollToRow(this.getPageDownRow()); + this.scrollToRow(this.getPageDownRow()); }; ace.Editor.prototype.scrollPageUp = function() { this.renderer.scrollToRow(this.getPageUpRow()); }; +ace.Editor.prototype.scrollToRow = function(row) { + this.renderer.scrollToRow(row); +}; + ace.Editor.prototype.navigateUp = function() { this.clearSelection(); @@ -451,6 +459,20 @@ ace.Editor.prototype.navigateLineEnd = function() this.renderer.scrollCursorIntoView(); }; +ace.Editor.prototype.navigateFileEnd = function() +{ + this.clearSelection(); + this.moveCursorFileEnd(); + this.renderer.scrollCursorIntoView(); +}, + +ace.Editor.prototype.navigateFileStart = function() +{ + this.clearSelection(); + this.moveCursorFileStart(); + this.renderer.scrollCursorIntoView(); +}, + ace.Editor.prototype.moveCursorUp = function() { this.moveCursorBy(-1, 0); }; @@ -479,18 +501,24 @@ ace.Editor.prototype.moveCursorRight = function() } else { this.moveCursorBy(0, 1); } - this.renderer.scrollCursorIntoView(); }; -ace.Editor.prototype.moveCursorLineStart = function() -{ +ace.Editor.prototype.moveCursorLineStart = function() { this.moveCursorTo(this.cursor.row, 0); - this.renderer.scrollCursorIntoView(); }; ace.Editor.prototype.moveCursorLineEnd = function() { this.moveCursorTo(this.cursor.row, this.doc.getLine(this.cursor.row).length); - this.renderer.scrollCursorIntoView(); +}; + +ace.Editor.prototype.moveCursorFileEnd = function() { + var row = this.doc.getLength() - 1; + var column = this.doc.getLine(row).length; + this.moveCursorTo(row, column); +}; + +ace.Editor.prototype.moveCursorFileStart = function() { + this.moveCursorTo(0, 0); }; ace.Editor.prototype.moveCursorBy = function(rows, chars) { @@ -512,6 +540,14 @@ ace.Editor.prototype.moveCursorTo = function(row, column) this.updateCursor(); }; +ace.Editor.prototype.getCursorPosition = function() +{ + return { + row: this.cursor.row, + column: this.cursor.column + } +}; + ace.Editor.prototype.hasSelection = function() { return !!this.selectionLead; };