jwkvam / jupyterlab-vim

:neckbeard: Vim notebook cell bindings for JupyterLab
MIT License
975 stars 73 forks source link

ctrl-n/p for moving in autocompletion menus #50

Open joelostblom opened 6 years ago

joelostblom commented 6 years ago

Hi, Is it possible to add support for using ctrl-n/p (or maybe ctrl-j/k) to navigate down and up the tab autocompletion menus?

ah- commented 6 years ago

I had an initial go at this, but couldn't yet make it work. Maybe someone else is interested at picking this up, so here's where I got to:

Source for the autocompletion menu is here: https://github.com/jupyterlab/jupyterlab/tree/master/packages/completer/src Cycling through the menu works via KeyEvents being processed in https://github.com/jupyterlab/jupyterlab/blob/master/packages/completer/src/widget.ts#L133. The widget just directly checks key codes at the moment.

I've then tried to somehow get a handle onto the completer widget so we could maybe inject a KeyEvent, via something like this:

        commands.addCommand('log-test', {
            label: 'Log Test',
            execute: args => {
                const current = getCurrent(args);

                console.log(current);
            },
            isEnabled
        });

        commands.addKeyBinding({
            selector: '.jp-Completer',
            keys: ['Ctrl N'],
            command: 'log-test'
        });

However, it seems that selector doesn't match anything and my logging function never gets called. It works with other selectors, like .jp-Notebook.jp-mod-editMode.

So I've run out of time/ideas for tonight, but it'd be really nice to get this working.

joelostblom commented 5 years ago

There is also an issue about this on the jupyterlab issue tracker https://github.com/jupyterlab/jupyterlab/issues/5863