Skip to content

Add a a general Toggle and Cycle commands for keybinding #166631

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

Closed
GilShoshan94 opened this issue Nov 17, 2022 · 6 comments
Closed

Add a a general Toggle and Cycle commands for keybinding #166631

GilShoshan94 opened this issue Nov 17, 2022 · 6 comments
Assignees

Comments

@GilShoshan94
Copy link

Hi,
Toggling configs is usefull, and having a general solution is great for users and for extension developpers as well.

The feature is just a cycle command that get in the "args" property an array of n settings objects.
The settings objects have to have the same schema, and activating the cycle command apply the the settings defined in the next object of the array until it reach the last member and cycle back to the first member.

The second feature is just a toggle command the is exactly the same than cycle, just the special case of an array of 2 settings objects excatly (and will complain if it's not exactly 2 members). It's just syntax sugar.


It would looks like this:

// # keybindings.json
[
    {
        "key": "ctrl+i",
        "command": "toggle"
        "when": "editorTextFocus"
        "args": {
                "id": "Zen", // id must be unique
                "values": [
                        // Must have 2 settings objects with the same schema
                        {
                                "workbench.statusBar.visible": true,
                                "workbench.activityBar.visible": true,
                                "workbench.editor.showTabs": false,
                                "editor.minimap.enabled": true,
                        },
                        {
                                "workbench.statusBar.visible": false,
                                "workbench.activityBar.visible": false,
                                "workbench.editor.showTabs": true,
                                "editor.minimap.enabled": false,
                        }
                ]
        }, 
    },
    {
        "key": "ctrl+shift+i",
        "command": "cycle"
        "when": "editorTextFocus"
        "args": {
                "id": "Theme and Font", // id must be unique
                "values": [
                        // As many settings objects as desired, with the same schema
                        {
                                "workbench.colorTheme": "Default Light+",
                                "editor.fontFamily": "Consolas, monospace",
                        },
                        {
                                "workbench.colorTheme": "Default Dark+",
                                "editor.fontFamily": "'Cascadia Code', monospace",
                        },
                        {
                                "workbench.colorTheme": "Default High Contrast",
                                "editor.fontFamily": "'Fira Code', monospace",
                        }
                ]
        }, 
    }
]

The reason for the unique id is to make the implementation easier, even if it could be generated, the advantage of letting the user set it, it that it can be used as a the name of the command to be display in the Command Palette: Toggle <"id"> and Cycle <"id">.
So with the current example, we would have "Toggle Zen" and "Cycle Theme and Font" in the Command Palette.


After reading the article Toggle any setting in VS Code using keyboard shortcut arguments by @rebornix and looking at his extension Toggle (marketplace, repo) I find it very usefull to have a toggle command for keybinding.

(I use it to toggle editor.inlayHints.enabled between on and off with the keybinding I like, which effectively solve #163201, #149019 and #154962)

One issue with the Toggle extension is that it appears closed source on the marketplace because the url to the repo is missing from the package.json file. Beside that it seems simple and super effective.

There is also another extension mentioned in the article called Settings Cycler (marketplace, repo) from @hoovercj. I didn't try it but it seems more general than Toggle by taking into account the user settings and workspace settings and detecting workspace settings collisions.

It seems like a neat feature for vscode and would be great if it's built in.

Have a nice day.

@sandy081
Copy link
Member

I do not think this can be a core feature as it is a sugar coating on top which can be done by extensions.

@GilShoshan94
Copy link
Author

GilShoshan94 commented Nov 23, 2022

@sandy081
A lot of things can be done by extensions, the difference when it's built-in is that it's maintained by the vscode team and won't break after an update. Also, it's less extensions the end user have to install and managed.

Both extensions that effectively fulfill the toggle and cycle commands where not updated in 6 and 2 years, which shows some stability since it's still working, but also they also do have open issues from 2018.

Those extensions were developed by Microsoft members, so it should be good.

As I explained, those commands being built-in would solves problems for end users by providing a way to personalize keys binding and help a lot other extensions, I gave examples.

I see those commands (which in reality is only one command and one special case where N=2) as core.
They are general enough that they should be built-in and extension developers should be able to depends on it in my opinion.

@sandy081
Copy link
Member

CC @isidorn

@StarSapien
Copy link

This issue should still be open. I ended up in this thread because I couldn't find toggle keybindings for Rust Analyzer in VSCode settings. The ability to toggle settings with keybindings is such an obvious feature I'm rather surprised that VSCode can't do this out of the millions of things it can. Assignable keybindings and an activity bar settings toggle feature would do the trick.

@GilShoshan94
Copy link
Author

@sandy081
Hi, can this issue be reopen in the meantime please ?

@eflukx
Copy link

eflukx commented Dec 7, 2022

I do not think this can be a core feature as it is a sugar coating on top which can be done by extensions.

Strong disagree. Basic features like this should not be reliant on an external extension. Having a lot of small extensions doing very basic stuff (or worse different extensions doing similar, but not the same stuff) doesn't lead to an integral ergonomic 'VSCode' way of doing things. IMO this harms usability and in the end the VSCode product.

To illustrate why this is a bad idea:
What about ditching the File>Open functionality from core? You can use one of the many existing extensions that implement local storage IO-provider functionality for opening files...

@github-actions github-actions bot locked and limited conversation to collaborators Jan 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants