VSCode - Event that fires when a non-text file has been opened / selected

Viewed 563

In VSCode there is an event when the active text editor has been changed: onDidChangeActiveTextEditor, it doesn't fire when a file that isn't a text file is opened (for example an image). I searched the VSCode API, and googled it, but didn't find anything.

Although the onDidChangeActiveTextEditor event does fire when a text file is selected and then you select an image file, it doesn't fire when you have an image file selected and you select another image file.

So my question is is there an event that will fire when any file is selected in the explorer, or am I overlooking something with onDidChangeActiveTextEditor?

EDIT: Looks like there is an open issue for this: https://github.com/Microsoft/vscode/issues/15178

2 Answers

To make it clear this question has been answered, I'm using the OP's edited question information to make a proper answer:

  • There is currently (VSCode 1.37.1) no such event to listen for changes to active non-text editors.
  • There is an open VSCode issue, 15178, that ostensibly tracks this request.
  • However, in my opinion, 14483 is really the right issue, and closing it as a duplicate was a mistake. (15178 is about enumerating open editors, while only 14483 specifically addresses notification events.)

The proposed api, see vscode.proposed.tabs.d.ts, does provide two event listeners that do work for whatever the file type opened or closed in my testing:

vscode.window.onDidChangeActiveTab(tab => {  
  console.log(`tab : ${tab}`);         
});

vscode.window.onDidChangeTabs(tabs => {  
  console.log(`tabs : ${tabs}`);          
})

Currently, this is just a proposed api but you can test it in the Insiders Build easily and report any issues. I specifically tried it with image files (gif and jpg) and it worked. There were issues of where the events fired too many times for a single open or close though.

Related