Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling Ctrl+P or other browser shortcuts #21

Closed
BrendanMartin opened this issue Dec 28, 2020 · 7 comments
Closed

Disabling Ctrl+P or other browser shortcuts #21

BrendanMartin opened this issue Dec 28, 2020 · 7 comments

Comments

@BrendanMartin
Copy link

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
Copy link
Collaborator

ianhi commented Dec 30, 2020

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 🙃

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
Copy link
Author

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
Copy link

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
Copy link

filyp commented Apr 13, 2021

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
Copy link
Collaborator

ianhi commented Mar 12, 2022

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
Copy link
Collaborator

firai commented Oct 1, 2023

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
Copy link
Collaborator

firai commented Oct 7, 2023

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

  • Ctrl+P – I understand that the desire to block this binding is due to occasional typos, and it does not seem appropriate for the extension to block the browser shortcut by default due to this. However, a way to disable this in the user preferences is provided in Disabling Ctrl+P or other browser shortcuts #21 (comment).
  • Shift+Esc – This browser key binding has been blocked by default in Jupyter Command mode since v4.0.2, and an option to disable the blocking key binding has been introduced in v4.1. Furthermore, the need to use Shift+Esc should reduce in the future, since Esc will be able to escape from vim Normal mode to Jupyter Command mode in v4.1.
  • Ctrl+O – This key binding only applies in vim mode, and the key binding already auto-blocks the browser shortcut in this mode; repeated pressing of Ctrl+O in vim mode inserts cells above. If someone wishes to disable it in Jupyter Command mode for whatever reason, they can use the suggestion in Disabling Ctrl+P or other browser shortcuts #21 (comment) to do so.

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.

@firai firai closed this as completed Oct 7, 2023
@firai firai changed the title Disabling CTRL-P Disabling Ctrl+P or other browser shortcuts Oct 7, 2023
@firai firai pinned this issue Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants