I want to use keyboard shortcuts such as “Shift Enter” in my JupyterLab extension, however I get the console warning “Skipping this shortcut because it collides with another shortcut.” From looking at the code I see that shortcuts which are considered “default” will throw this warning, and I understand that “Shift Enter” is used in the notebook extension and thus is probably considered “default”.
However, my question remains how I can use such a shortcut and avoid this conflict? It seems reasonable to me that this should be possible: JupyterLab could check which is the active extension/widget and take the appropriate action…
The extension I’m working on right now is a split-panel notebook: right hand side is a notebook, left hand side is a “canvas” where the user can drop nodes that represent python functions/classes. It works alongside the default notebook (at least for now – we’re also thinking about integrating with the default notebook but was having some difficulty overriding the content area of the NotebookPanel).
So, I need for all of the regular notebook commands to work in both the default notebook, as well as my split-panel notebook.
In the screenshot below I’m showing the “split panel” notebook next to the default notebook.
Thanks for sharing. Can you continue explaining exactly what keyboard shortcut you are registering, and what keyboard shortcut it is complaining about? In particular, what are the selectors for these shortcuts?
From your explanation above, I’m inferring that you are trying to reuse a notebook css class for your notebook, where you should maybe be setting up shortcuts for your new notebook yourself. Or perhaps you can reuse the notebook css class, but you have to be really careful about how you do so.
What we’ve done is copy the notebook-extension, and then change the shortcut names. The result is that our split panel notebook now “steals” the shortcuts: they now only work in the split panel notebook, but not the default notebook. I think you’re saying that in the “tracker.json” below I should change the selectors to also be different – not .jp-Notebook:focus, for example…?
Yes. A shortcut is identified by the (keys, selector) pair - that is what the system needs to identify for a given key press on a given DOM element what command to run. You are adding new shortcuts with the same (keys, selector) pairs, so the system wouldn’t know what to do - your command or the default command. The way to disambiguate is to recognize that your shortcuts apply to a completely different thing in the DOM, your widget, and so you should have your own selector, not reuse the existing selector.
That fixed the shortcut conflict issue for me. Thank you.
One follow-up is that I’m also having trouble getting the Completer to work in my split panel notebook – no errors, it just tabs over instead of triggering the Completer. Do you have any recommendations for how to approach this?
I was thinking that I could just copy this portion of the Completer Extension, but I’m wondering if there’s a simpler way…
One further follow-up is that I’m having trouble getting ipywidgets to work in my extension. I get the error below Object 'jupyter.widget' not found in registry. Could you please provide some guidance as to what I might need to do to get ipywidgets to work in my extension?