首页 > 解决方案 > 无法在其他视图列中获得可见的文本编辑器

问题描述

我正在尝试在新的视图列中打开活动文件,然后折叠标签。折叠命令可以正常工作activeTextEditor

// Fold based on linenumber
let range = editor.document.lineAt(lineNumber).range;
editor.selection = new vscode.Selection(range.start, range.end);
editor.revealRange(range);
commands.executeCommand('editor.fold');

现在我想在新打开的文件中做同样的事情:

// Open the same file in a new column
// at this time editor.ViewColum is One
commands.executeCommand('vscode.open', Uri.file(editor.document.fileName), ViewColumn.Two);

// Try to get that editor
let newEditor = vscode.window.visibleTextEditors.find(x=> x.viewColumn===viewColumn.Two && x.document.fileName===fileName)

问题是newEditor没有找到,因为新打开的文档有ViewColumn undefined.

知道如何解决这个问题吗?

谢谢

标签: visual-studio-codevscode-extensions

解决方案


vs 命令返回一个承诺。需要等待,一切正常。


推荐阅读