diff --git a/package.json b/package.json index d5bbb5c..ba3aea0 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,9 @@ "href": "https://github.com/tjx666/power-edit" } ], - "activationEvents": [], + "activationEvents": [ + "onStartupFinished" + ], "contributes": { "commands": [ { diff --git a/src/extension.ts b/src/extension.ts index 14205af..77b96bd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,8 @@ import vscode from 'vscode'; export function activate(context: vscode.ExtensionContext) { + import('./features/autoKeepTempEditor').then((mod) => mod.autoKeepTempEditor(context)); + const { commands } = vscode; const registerTextEditorCommand = ( diff --git a/src/features/autoKeepTempEditor.ts b/src/features/autoKeepTempEditor.ts new file mode 100644 index 0000000..09c2020 --- /dev/null +++ b/src/features/autoKeepTempEditor.ts @@ -0,0 +1,16 @@ +import type { ExtensionContext } from 'vscode'; +import vscode from 'vscode'; + +export function autoKeepTempEditor(context: ExtensionContext) { + vscode.workspace.onDidOpenTextDocument( + async (document) => { + const { uri } = document; + const isGitErrorEditor = uri.scheme === 'git-output' && /\/git-error-/.test(uri.fsPath); + if (isGitErrorEditor) { + await vscode.commands.executeCommand('workbench.action.keepEditor'); + } + }, + null, + context.subscriptions, + ); +}