Skip to content

Commit

Permalink
perf: focus text document not open when text document was opened
Browse files Browse the repository at this point in the history
  • Loading branch information
sz-p committed Nov 25, 2024
1 parent f1edfed commit b6981a8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ const saveData = () => {
}
};

const focusOnFile = async function (filePath) {

const openEditors = vscode.window.visibleTextEditors;
const targetEditor = openEditors.find(editor => editor.document.uri.fsPath === filePath);

if (targetEditor) {
await vscode.window.showTextDocument(targetEditor.document, { viewColumn: targetEditor.viewColumn });
} else {
const uri = vscode.Uri.file(filePath);
const doc = await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside);
}

}

export const command_focusOnNode = vscode.commands.registerCommand(
"dependencygraph.focusOnNode",
(fileName, ancestors) => {
Expand Down Expand Up @@ -103,10 +118,8 @@ export const command_openFile = vscode.commands.registerCommand(
} else {
_absolutePath = absoluteFilePath.absolutePath;
}
let uri = vscode.Uri.file(_absolutePath);
vscode.workspace.openTextDocument(uri).then((doc) => {
vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside);
});

focusOnFile(_absolutePath);
}
);

Expand Down

0 comments on commit b6981a8

Please sign in to comment.