监听 vscode 扩展名中文件的打开
Listen to opening of files in vscode extension
目前我正在使用以下几行来检测用户是否打开了文件:
vscode.workspace.onDidOpenTextDocument((file) => {
//
})
但是,对于“在后台”打开的 tsconfig.json
或 .git
文件之类的内容也会调用此方法。
是否有一种方法/挂钩/事件只侦听“活动编辑器”文件更改?
是的,有一个 vscode.window.onDidChangeActiveTextEditor
事件。
An event which fires when the active editor has changed. Note that the event also fires when the active editor changes to undefined
.
目前我正在使用以下几行来检测用户是否打开了文件:
vscode.workspace.onDidOpenTextDocument((file) => {
//
})
但是,对于“在后台”打开的 tsconfig.json
或 .git
文件之类的内容也会调用此方法。
是否有一种方法/挂钩/事件只侦听“活动编辑器”文件更改?
是的,有一个 vscode.window.onDidChangeActiveTextEditor
事件。
An event which fires when the active editor has changed. Note that the event also fires when the active editor changes to
undefined
.