From 3e43197c232723018a65e99821b04fc00bbc33e4 Mon Sep 17 00:00:00 2001 From: Patrick Regnouf Date: Sun, 15 Mar 2026 08:55:08 +0000 Subject: [PATCH] Fix openfile navigation jumping to wrong line vscode.Position uses 0-based line numbers but cqsearch returns 1-based line numbers. Also added editor.selection to actually move the cursor, not just scroll the viewport. Without setting the selection, the cursor stayed at its previous position while the view scrolled, causing apparent random offsets of 20-30 lines. --- src/cqtreedataprov.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cqtreedataprov.ts b/src/cqtreedataprov.ts index 8d78ac1..87da115 100644 --- a/src/cqtreedataprov.ts +++ b/src/cqtreedataprov.ts @@ -38,9 +38,10 @@ export default class CQResultsProvider implements vscode.TreeDataProvider { vscode.window.showTextDocument(doc).then(editor => { - var linenum1 = parseInt(linenum, 10); - var remaining = editor.document.lineCount - linenum1; - editor.revealRange(this.calcRange(linenum1, remaining)); + var linenum1 = parseInt(linenum, 10) - 1; + var pos = new vscode.Position(linenum1, 0); + editor.selection = new vscode.Selection(pos, pos); + editor.revealRange(new vscode.Range(pos, pos), vscode.TextEditorRevealType.InCenter); }); }); }