Leo*_*ang 7 javascript visual-studio-code
我正在使用一个名为commands.executeCommand('revealInExplorer');
. 这会将左侧边栏切换到文件资源管理器,然后在文件树中显示当前文件。但是,我希望仅当资源管理器当前可见时才会发生这种情况。例如,当我在搜索视图中时,我不希望扩展调用commands.executeCommand('revealInExplorer');
. 我怎样才能做到这一点?
扩展名是“自动折叠浏览器”:
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
};
Run Code Online (Sandbox Code Playgroud)
小智 0
我发现在 settings.json 中有一个 openEditors 常量,当设置为 0 时,意味着编辑器不应显示在文件资源管理器中。因此,您可以创建一个任务来提取 openEditors 的变量值,并在命令中为 openEditors != 0 添加 if 语句,然后添加commands.executeCommand('revealInExplorer');
https://code.visualstudio.com/docs/editor/variables-reference#_configuration-variables
您可以通过 ${config:Name} 语法(例如 ${config:editor.fontSize})引用 VS Code 设置(“配置”)
不确定这是否是您想要的,希望它有所帮助。
归档时间: |
|
查看次数: |
145 次 |
最近记录: |