From 9f099499c922a5eac5bae374541c83d5cae6e99b Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Sun, 5 Nov 2023 01:19:17 -0700 Subject: [PATCH] Iterate the diffs in each active PR in order --- src/commands.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 278341b9a1..75b192e24e 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1346,16 +1346,20 @@ ${contents} } // Find the next diff in the current file to scroll to - const visibleRange = editor.visibleRanges[0]; + const cursorPosition = editor.selection.active; const iterateThroughDiffs = next ? diffs : diffs.reverse(); for (const diff of iterateThroughDiffs) { const practicalModifiedEndLineNumber = (diff.modifiedEndLineNumber > diff.modifiedStartLineNumber) ? diff.modifiedEndLineNumber : diff.modifiedStartLineNumber as number + 1; const diffRange = new vscode.Range(diff.modifiedStartLineNumber ? diff.modifiedStartLineNumber - 1 : diff.modifiedStartLineNumber, 0, practicalModifiedEndLineNumber, 0); - if (next && (visibleRange.end.line < practicalModifiedEndLineNumber) && (visibleRange.end.line !== (editor.document.lineCount - 1))) { + + // cursorPosition.line is 0-based, diff.modifiedStartLineNumber is 1-based + if (next && cursorPosition.line + 1 < diff.modifiedStartLineNumber) { editor.revealRange(diffRange); + editor.selection = new vscode.Selection(diffRange.start, diffRange.start); return; - } else if (!next && (visibleRange.start.line > diff.modifiedStartLineNumber) && (visibleRange.start.line !== 0)) { + } else if (!next && cursorPosition.line + 1 > diff.modifiedStartLineNumber) { editor.revealRange(diffRange); + editor.selection = new vscode.Selection(diffRange.start, diffRange.start); return; } }