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

Allow overrides.json to override default shortcuts. #9858

Merged
merged 2 commits into from
Feb 23, 2021

Conversation

jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Feb 23, 2021

References

Fixes https://discourse.jupyter.org/t/keyboard-shortcuts-with-overrides-json/5751 and https://discourse.jupyter.org/t/some-configs-in-overrides-json-does-not-work-as-i-intended/3955

Code changes

Shortcuts were throwing away any defaults given by the shortcut plugin settings or overrides.json. This adds them back into the default shortcuts, and also allows default shortcuts to disable each other silently. This allows overrides.json to disable default shortcuts as well as add new default shortcuts.

User-facing changes

Users can override default shortcuts with overrides.json.

This behavior is slightly different than the normal overrides.json behavior. Normally, the overrides.json values overwrite the plugin defaults, so the user never sees the plugin defaults. In this PR, we instead add the overrides.json shortcuts, merging them into the existing defaults, rather than overwriting the existing defaults. I think this makes more sense for shortcuts, which are assembled from many different plugins.

To test, you can create a dev_mode/settings/overrides.json file like this:

{
  "@jupyterlab/apputils-extension:themes": {
      "theme": "JupyterLab Dark"
  },
  "@jupyterlab/shortcuts-extension:shortcuts": {
      "shortcuts": [
      {
          "command": "imageviewer:flip-horizontal",
          "keys": [
              "X"
          ],
          "selector": ".jp-ImageViewer"
      },
      {
        "command": "imageviewer:flip-horizontal",
        "keys": [
            "H"
        ],
        "selector": ".jp-ImageViewer",
        "disabled": true
    }
    ]
  }
}

You can know it is active by the default dark theme. Look at the shortcuts, and you'll see the two additional shortcuts, and then try the shortcuts in the imageviewer to verify that "X" now flips horizontally and "H" does not.

Backwards-incompatible changes

Also, make it possible for default shortcuts to have disabled attributes, which will silently disable conflicting disabled shortcuts. This allows overrides.json to disable default shortcuts as well as add new default shortcuts.
@jasongrout jasongrout added this to the 3.1 milestone Feb 23, 2021
@jupyterlab-dev-mode
Copy link

Thanks for making a pull request to JupyterLab!

To try out this branch on binder, follow this link: Binder

@meeseeksmachine
Copy link
Contributor

This pull request has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/keyboard-shortcuts-with-overrides-json/5751/3

@meeseeksmachine
Copy link
Contributor

This pull request has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/some-configs-in-overrides-json-does-not-work-as-i-intended/3955/3

Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Needs a lint pass but otherwise LGTM.

@jasongrout
Copy link
Contributor Author

It adds the shortcut, just as if the user had given it in the user preferences. If you want to disable an existing shortcut, use the disabled: true field, just like you would in the user preferences.

@blink1073 blink1073 added the bug label Jul 21, 2021
@github-actions github-actions bot added the status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Jan 18, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug pkg:settingregistry pkg:shortcuts status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants