I'm using an extension that calls commands.executeCommand('revealInExplorer');. This switches the left sidebar to the file explorer and then reveals the current file in the file tree. However, I want this to happen only when the explorer is currently visible. E.g. when I'm in the search view, I don't want the extension to call commands.executeCommand('revealInExplorer');. How can I do this?
The extension is "Auto-Collapse Explorer":
const { window, commands } = require('vscode');
const COLLAPSE = 'workbench.files.action.collapseExplorerFolders';
const REVEAL = 'revealInExplorer';
function activate(context) {
const subscription = window.onDidChangeActiveTextEditor(showOnlyCurrentFile);
context.subscriptions.push(subscription);
showOnlyCurrentFile();
}
async function showOnlyCurrentFile() {
await commands.executeCommand(COLLAPSE);
await commands.executeCommand(REVEAL);
if (!window.activeTextEditor) return;
window.showTextDocument(window.activeTextEditor.document);
}
function deactivate() {}
module.exports = {
activate,
deactivate
};
from VS Code: check whether the file explorer is shown?
No comments:
Post a Comment