Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Add more comments to explain logic in getNextSelectionRange
Browse files Browse the repository at this point in the history
Co-Authored-By: Vanessa Yuen <vanessayuenn@users.noreply.github.com>
  • Loading branch information
kuychaco and vanessayuenn committed Nov 16, 2018
1 parent 8be43e5 commit c4d0dec
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/models/patch/multi-file-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default class MultiFilePatch {

let lastSelectionIndex = 0;
// counts unselected lines in changed regions from the old patch
// until we get to the bottom-most selected line from the old patch.
// until we get to the bottom-most selected line from the old patch (lastMax).
patchLoop: for (const lastFilePatch of lastMultiFilePatch.getFilePatches()) {
for (const hunk of lastFilePatch.getHunks()) {
let includesMax = false;
Expand All @@ -160,13 +160,18 @@ export default class MultiFilePatch {
}
}

// Iterate over changed lines in new patch in order to find the
// new row to be selected based on the last selection index.
// As we walk through the changed lines, we whittle down the
// remaining lines until we reach the row that corresponds to the
// last selected index

let newSelectionRow = 0;
let remainingChangedLines = lastSelectionIndex;

let foundRow = false;
let lastChangedRow;

// counts the same number of lines but backwards in the new patch.
patchLoop: for (const filePatch of this.getFilePatches()) {
for (const hunk of filePatch.getHunks()) {
for (const change of hunk.getChanges()) {
Expand All @@ -182,7 +187,10 @@ export default class MultiFilePatch {
}
}

if (!foundRow) { // the selected line was the last changed line
// If we never got to the last selected index, that means it is
// no longer present in the new patch (ie. we staged the last line of the file).
// In this case we want the next selected line to be the last changed row in the file
if (!foundRow) {
newSelectionRow = lastChangedRow;
}

Expand Down

0 comments on commit c4d0dec

Please sign in to comment.