Plugin to keep the cursor centered when using the up/down arrow keys


#1

Hello, everyone. I finally scratched my own itch here. I find myself arrowing through my documents a line at a time, and I’ve wished FoldingText would keep the cursor centered as I do this. I don’t know how to upload a plugin here, but this is the simple code I created, based on the template. This is the entirety of “main.js”:

define(function(require, exports, module) {
var Extensions = require('ft/core/extensions').Extensions;
Extensions.addInit(function (editor) {
    editor.addKeyMap({
        'Up' : function (editor) {
          editor.performCommand('moveUp');
          editor.performCommand('centerSelectionInVisibleArea');
        },
        'Down' : function (editor) {
          editor.performCommand('moveDown');
          editor.performCommand('centerSelectionInVisibleArea');
        }
    });
});
});

Loading this as a plugin just modifies the Up and Down arrow keys so that, after they move the cursor, they center the cursor’s new location in the window (if you’re not at the very edges of the document).

Seems to work great for me, and I really find this useful for keeping my focus on where I’m working.

May it bring you joy.