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 separate when clauses for each command in a keybinding with multiple commands #184288

Open
User087 opened this issue Jun 4, 2023 · 2 comments
Assignees
Labels
feature-request Request for new features or functionality runCommands Issues related to command 'runCommands'
Milestone

Comments

@User087
Copy link

User087 commented Jun 4, 2023

Currently, it seems that 'when' clauses in keybindings are associated with an entire keybinding rather than the individual commands within it. I suggest associating when clauses with commands so that it would be possible in a keybinding with multiple commands to have separate when clauses for each, and whether each command is run in a particular instance depends on whether its respective when clause is fulfilled.

So a keybinding would look something like:

{
    "key": "key",
    "command": "runCommands",
    "args": {
        "commands": [
            {
                "command": "command1",
                "args": {
                    "arg1": "value1",
                    "arg2": "value2"
                },
                "when": "condition1"
            },
            {
                "command": "command2",
                "when": "condition2"
            },
            {
                "command": "command3",
                "when": "condition3",
            },
        ]
    }
}

so upon pressing key, if only condition2 is fulfilled and not condition1 and condition3, then only command2 gets run, and if condition1 and condition2 are both fulfilled and not condition3, then command1 gets run, and then command2 gets run (i.e. sequentially as usual), etc.

@deepak1556 deepak1556 assigned ulugbekna and unassigned deepak1556 Jun 5, 2023
@ulugbekna ulugbekna added feature-request Request for new features or functionality runCommands Issues related to command 'runCommands' labels Jun 5, 2023
@ulugbekna ulugbekna added this to the Backlog milestone Jun 5, 2023
@ulugbekna ulugbekna modified the milestones: Backlog, August 2023 Aug 14, 2023
@ulugbekna ulugbekna modified the milestones: August 2023, September 2023 Aug 31, 2023
@ulugbekna ulugbekna modified the milestones: October 2023, November 2023 Oct 26, 2023
@ulugbekna ulugbekna modified the milestones: November 2023, December 2023 Nov 30, 2023
@aiday-mar aiday-mar modified the milestones: December / January 2024, February 2024 Jan 25, 2024
@sandiiarov
Copy link

I am trying to use j and k in source control to focus on the file and open the diff. The problem is the command selectAndPreserveFocus also triggers the collapse/expand state on folders or other collapsible elements. To prevent that I just need to apply a condition only to selectAndPreserveFocus command. So it should focus down, but it should not run selectAndPreserveFocus.

  {
    "key": "j",
    "command": "runCommands",
    "args": {
      "commands": [
        { "command": "list.focusDown" },
        { "command": "list.selectAndPreserveFocus", "when": "!treeElementCanCollapse || !treeElementCanExpand" }
      ]
    },
    "when": "workbench.scm.active && listFocus"
  },
  {
    "key": "k",
    "command": "runCommands",
    "args": {
      "commands": [
        { "command": "list.focusUp" },
        { "command": "list.selectAndPreserveFocus", "when": "!treeElementCanCollapse || !treeElementCanExpand" }
      ]
    },
    "when": "workbench.scm.active && listFocus"
  }

@ulugbekna ulugbekna modified the milestones: February 2024, On Deck Feb 22, 2024
@starball5
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality runCommands Issues related to command 'runCommands'
Projects
None yet
Development

No branches or pull requests

7 participants