VSpaceCode / VSpaceCode

Spacemacs like keybindings for Visual Studio Code

Home Page:https://vspacecode.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

whichkey bindings for notebook cells

dboeckenhoff opened this issue · comments

Problem

In ipynb/notebook files I want to have some major mode options for any cell language (conditioning when on ipynb extensions).

Solution

Allow to duplicate/clone certain which-key keybindings by key of others.

Alternatives

Copy the definitions in your setting.json file but that would be bad for many reasons.

Additional context

Thanks for the nice work!

This may not be that easy. The text editing area of a cell is just like a regular text editor that has a language settings. The extension get the language just like a regular text editor.

Can you elaborate a little about your use case? The way I understand is that if you would like to have different bindings when the editor is part of a notebook?

Yes, I want to have the same keybinding for all types of cells conditioned on "is a jupyter notebook cell" without copying settings. I have it running currently but maintenance is horrible with copies.

There isn't direct API from vscode that we can use AFAIK. But there is a workaround for it that uses conditional bindings https://vspacecode.github.io/docs/whichkey/extra#when.

settings.json:

  "vspacecode.bindingOverrides": [
      {
        "keys": ["m", "when:isNotebook"],
        "name": "Go to",
        "type": "command",
        "command": "workbench.action.gotoLine",
        "position": 0
      }
  ],

Due to conditional matching logic, it matches the any condition that match first; hence, we have to put the conditional before other bindings. Addition, the api we have doesn't allow insertion -- we have to override the condition bindings at 0 index (languageId:agda)

keybindings.json

	{
		"key": "m",
		"command": "whichkey.triggerKey",
		"args": {
			"key": "m",
			"when": "isNotebook"
		  },
		"when": "whichkeyVisible && activeEditor == 'workbench.editor.notebook'"
	},

This should allow you to have a specific binding for cells in notebook