Vscode: Git: Provide single shortcut for "Stage Changes"/"Unstage Changes"

Created on 27 Feb 2018  Â·  13Comments  Â·  Source: microsoft/vscode

I personally prefer to use the same keyboard shortcut for both "Stage Changes" and "Unstage Changes".

If I set the same keyboard shortcut for both, only one of them (namely, "Stage Changes") is enabled.

*out-of-scope feature-request git help wanted

Most helpful comment

I actually wanted to see whether there are hidden when clauses we could be used to detect which mode we are in, and set keybindings accordingly... Something like:

[
    {
        "key": "ctrl+t",
        "command": "git.stage",
        "when": "inDiffEditor" // only for illustrative purposes, i don't know if there is a when clause for this mode
    },
    {
        "key": "ctrl+t",
        "command": "git.unstage",
        "when": "inDiffEditor && inStagedView" // only for illustrative purposes, i don't know if there is a when clause for this mode
    }
]

All 13 comments

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@birgersp How did you configure those keybindings? Can you show me your keybindings.json?

@joaomoreno Thanks for getting back to me so quickly! I configured the keybindings by opening the keybindings editor with "File"->"Preferences"->"Keyboard Shortcuts".

Then I double-clicked the "Stage Changes" command, and pressed CTRL+T followed by ENTER to assign it. Did the same for "Unstage Changes".

My keybindings.json file looks like this:

// Place your key bindings in this file to overwrite the defaults
[
    {
        "key": "ctrl+t",
        "command": "git.stage"
    },
    {
        "key": "ctrl+u",
        "command": "git.unstage"
    }
]

Got it. What would your prefer to happen if the file is both staged and modified in the working tree?

I am thinking wheter it should be staged or unstaged depends on the current selection. Meaning;

When the command is invoked, and

  • If the file is selected among unstaged files: stage it
  • If the file is selected among staged files: unstage it

For instance, pressing the keyboard shortcut here, would cause the file to be unstaged (since it is selected as a staged file):
screenshot from 2018-02-28 09-43-33

Notice that the command doesn't know about selection, only about the currently opened file. There's no current API to get a hold of that selection.

Understood. Personally, I don't have any opinion as to what should happen if the file is both staged and unstaged.

I suggest we just stage it.

I actually wanted to see whether there are hidden when clauses we could be used to detect which mode we are in, and set keybindings accordingly... Something like:

[
    {
        "key": "ctrl+t",
        "command": "git.stage",
        "when": "inDiffEditor" // only for illustrative purposes, i don't know if there is a when clause for this mode
    },
    {
        "key": "ctrl+t",
        "command": "git.unstage",
        "when": "inDiffEditor && inStagedView" // only for illustrative purposes, i don't know if there is a when clause for this mode
    }
]

I actually wanted to see whether there are hidden when clauses we could be used to detect which mode we are in, and set keybindings accordingly

@kumarharsh: Found anything about that when clause?

Nopes ☹. The core team needs to answer this.

@kumarharsh Maybe try something like resourceScheme == git.

This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding and happy coding!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

biij5698 picture biij5698  Â·  3Comments

omidgolparvar picture omidgolparvar  Â·  3Comments

sirius1024 picture sirius1024  Â·  3Comments

DovydasNavickas picture DovydasNavickas  Â·  3Comments

v-pavanp picture v-pavanp  Â·  3Comments