fcahoon
fcahoon

Reputation: 73

Is there a vscode keybinding 'when' clause to detect focus on an output channel?

I'm writing a vscode extension which can run a particular subprocess and direct the output to an output channel. I'm adding a keybinding for the command to kill the subprocess if necessary.

I'd like to use ctrl+c, as one would do in a terminal, but only when the focus is in the output channel.

I did not see how I could specify this in the 'when' clause for my keybinding. Is it possible?

Upvotes: 0

Views: 971

Answers (2)

If you want to check which output channel is selected, you can additionally query resourceExtname, e.g.:

  {
    "command": "MyApp.RefreshLogChannel",
    "key": "f5",
    "when": "focusedView == 'workbench.panel.output' && resourceExtname == '.myapp-#2-MyApp Log'"
  }

To find out what's the resourceExtname of your output channel, you can do the following:

  • Open the VSCode Developer Tools via Help -> Toggle Developer Tools
  • Go back to the VSCode window
  • Hit Ctrl+Shift+P and search for "Inspect Context Keys"
  • Go to the developer tools window and take a look at the console output

Upvotes: 0

Kasper
Kasper

Reputation: 330

You can check if the focusedView is set to the output panel, like so:

{
    "key": "ctrl+k",
    "command": "workbench.output.action.clearOutput",
    "when": "focusedView == 'workbench.panel.output'"
}

Upvotes: 4

Related Questions