Skip to content

Commit

Permalink
Iterate the diffs in each active PR in order (#5437)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Nov 6, 2023
1 parent 1536326 commit ec532a6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit ec532a6

Please sign in to comment.