【问题标题】:VS Code: check whether the file explorer is shown?VS Code:检查文件资源管理器是否显示?
【发布时间】: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


【解决方案1】:

我发现在 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 设置(“配置”)

不确定这是否适合您,希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 2019-09-10
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多