Skip to content

Commit 85532e2

Browse files
Merge #5480
5480: Fix snippetTextEdits applying to other files r=matklad a=TimoFreiberg Fixes #4551 `vscode.window.visibleTextEditors` only contains editors whose contents are being displayed at the moment, so the previous logic only worked if the other file for which a snippetTextEdit is being received was visible in a separate split. I feel that this is a hacky approach, so feel free to reject it for something nicer :) Co-authored-by: Timo Freiberg <[email protected]>
2 parents 803f361 + 1b5a74e commit 85532e2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

editors/code/src/snippets.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
66
assert(edit.entries().length === 1, `bad ws edit: ${JSON.stringify(edit)}`);
77
const [uri, edits] = edit.entries()[0];
88

9+
if (vscode.window.activeTextEditor?.document.uri !== uri) {
10+
// `vscode.window.visibleTextEditors` only contains editors whose contents are being displayed
11+
await vscode.window.showTextDocument(uri, {});
12+
}
913
const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString());
1014
if (!editor) return;
1115
await applySnippetTextEdits(editor, edits);

0 commit comments

Comments
 (0)