From 6d2c85ca5a4b23ff933ea2c8d4abab7de8cd6a84 Mon Sep 17 00:00:00 2001 From: winterdrive <90021888+winterdrive@users.noreply.github.com> Date: Tue, 7 Jul 2026 07:09:30 +0800 Subject: [PATCH] fix(commands): clamp bookmark position to document bounds in jumpToBookmark Bookmarked line/character can exceed the current document if the file was edited (lines removed) since the bookmark was created, leaving the jump-to-bookmark selection/reveal to operate on an invalid position. --- src/commands.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index c5df813..7ec1922 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1188,10 +1188,13 @@ export function registerCommands( const document = await vscode.workspace.openTextDocument(item.fileUri); const editor = await vscode.window.showTextDocument(document); - const position = new vscode.Position( + // Clamp to the document's current bounds: the file may have been + // edited (lines removed) since the bookmark was created, which would + // otherwise leave selection/reveal operating on an invalid position. + const position = document.validatePosition(new vscode.Position( item.bookmark.line, item.bookmark.character || 0 - ); + )); const range = new vscode.Range(position, position);