【发布时间】:2020-12-20 00:48:21
【问题描述】:
我正在使用调用commands.executeCommand('revealInExplorer'); 的扩展程序。这会将左侧边栏切换到文件资源管理器,然后在文件树中显示当前文件。但是,我希望仅在资源管理器当前可见时才发生这种情况。例如。当我在搜索视图中时,我不希望分机调用commands.executeCommand('revealInExplorer');。我该怎么做?
扩展名为“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
};
【问题讨论】:
-
我觉得不可能,你被浏览器隔离了……
标签: javascript visual-studio-code