jupyterlab-contrib / jupyterlab-vim

Vim notebook cell bindings for JupyterLab
https://jupyterlab-contrib.github.io/jupyterlab-vim.html
MIT License
676 stars 43 forks source link

Disabling `Ctrl+P` or other browser shortcuts #21

Closed BrendanMartin closed 12 months ago

BrendanMartin commented 3 years ago

In insert mode, I sometimes hit CTRL-P when trying to hit CTRL-[ to leave insert mode. Unfortunately, Chrome launches the print dialog if you hit CTRL-P.

Right now I'm using this script as a bookmark to intercept it:

document.addEventListener('keydown', function(event) {
  if(event.ctrlKey && event.keyCode == 80) {
    event.preventDefault(); 
  }
});

But was wondering if this is something we could integrate into this extension.

ianhi commented 3 years ago

Your proposed fix has the downside of preventing of the print dialog from working, which if implemented would almost certainly create bug reports that this extension broke printing :upside_down_face:

Admittedly using ctrl-P to just print the jlab interface is a pretty niche use case. But it still seems that a modification like this to prevent the occasional typo is outside the scope of this extension. In general unless a keyboard shortcut directly conflicts with a known vim keybinding then I don't think it's the role of this extension to mess with the browser's default behavior.

Maybe something like https://chrome.google.com/webstore/detail/shortkeys-custom-keyboard/logpjaacgmcbpdkdchjiaagddngobkck would work in order to inject your js automatically?

BrendanMartin commented 3 years ago

My idea would be to allow the disabling of these kinds of browser shortcuts. So if someone uses the print shortcut often, they can just leave it on.

lorenzncode commented 3 years ago

I accidently hit Shift-Escape sometimes when I am already out of vim mode. This opens the Chrome Task Manager and then one time I also went on to trigger End process by mistake too...

filyp commented 3 years ago

I have a similar problem with ctrl+o in firefox. I agree that it would be invasive if this extension changed browser shortcuts, but at least we could document in README some way to this manually. @BrendanMartin could you give more details on how you run this script?

ianhi commented 2 years ago

Now that we have a real settings file I'm open to re-considering this as an opt-in setting. If anyone wants to have a go at PR for something like this it's ok to @ me for a review

firai commented 1 year ago

JupyterLab now allows you to do this in your user preferences by adding following to the keyboard shortcut settings (Settings menu → Settings Editor → JSON Settings Editor [in the upper right hand corner] → Keyboard Shortcuts). However, as mentioned above, I don't think blocking browser shortcuts should become a default for the extension itself unless it directly conflicts with a keyboard shortcut used by the extension.

Block Ctrl+P in vim Normal mode (Replace "Ctrl P" below with any other shortcut key as desired.)

{
    "shortcuts": [
        Starts here
        {
            "command": "",
            "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook.jp-mod-editMode",
            "keys": ["Ctrl P"]
        }
        Ends here
    ]
}

Block Ctrl+P in Jupyter Command mode (Again, replace "Ctrl P" below with any other shortcut key as desired.)

{
    "shortcuts": [
        Starts here
        {
            "command": "",
            "selector": ".jp-Notebook.jp-mod-commandMode",
            "keys": ["Ctrl P"]
        }
        Ends here
    ]
}
firai commented 12 months ago

A summary of browser key bindings that have been suggested here to be blocked by the extension:

Based on the above, I will close this issue as completed and pin this issue. If you would like to suggest another key binding that we should consider blocking, please open a new issue.