emacs recenter-top-bottom

This commit is contained in:
nightwing 2012-09-08 16:26:42 +04:00
commit 393e42b439
2 changed files with 19 additions and 2 deletions

View file

@ -212,7 +212,8 @@ exports.emacsKeys = {
"S-C-Home" : "selecttostart",
"S-C-End" : "selecttoend",
"C-l|M-s" : "centerselection",
"C-l" : "recenterTopBottom",
"M-s" : "centerselection",
"M-g": "gotoline",
"C-x C-p": "selectall",
@ -270,6 +271,20 @@ exports.emacsKeys = {
exports.handler.bindKeys(exports.emacsKeys);
exports.handler.addCommands({
recenterTopBottom: function(editor) {
var renderer = editor.renderer;
var pos = renderer.$cursorLayer.getPixelPosition();
var h = renderer.$size.scrollerHeight - renderer.lineHeight;
var scrollTop = renderer.scrollTop;
if (Math.abs(pos.top - scrollTop) < 2) {
scrollTop = pos.top - h;
} else if (Math.abs(pos.top - scrollTop - h * 0.5) < 2) {
scrollTop = pos.top;
} else {
scrollTop = pos.top - h * 0.5;
}
editor.session.setScrollTop(scrollTop);
},
selectRectangularRegion: function(editor) {
editor.multiSelect.toggleBlockSelection();
},

View file

@ -1038,9 +1038,11 @@ var VirtualRenderer = function(container, theme) {
cursor = {row: cursor, column: 0};
var pos = this.$cursorLayer.getPixelPosition(cursor);
var offset = pos.top - this.$size.scrollerHeight * (alignment || 0);
var h = this.$size.scrollerHeight - this.lineHeight;
var offset = pos.top - h * (alignment || 0);
this.session.setScrollTop(offset);
return offset;
};
this.STEPS = 8;