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

Commit 1685484

Browse files
Add logic to getNextSelectionRange so that selection remains at bottom when last line is staged
Co-Authored-By: Vanessa Yuen <[email protected]>
1 parent a0dafda commit 1685484

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/models/patch/multi-file-patch.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,30 @@ export default class MultiFilePatch {
162162

163163
let newSelectionRow = 0;
164164
let remainingChangedLines = lastSelectionIndex;
165+
166+
let foundRow = false;
167+
let lastChangedRow;
168+
165169
// counts the same number of lines but backwards in the new patch.
166170
patchLoop: for (const filePatch of this.getFilePatches()) {
167171
for (const hunk of filePatch.getHunks()) {
168172
for (const change of hunk.getChanges()) {
169173
if (remainingChangedLines < change.bufferRowCount()) {
170174
newSelectionRow = change.getStartBufferRow() + remainingChangedLines;
175+
foundRow = true;
171176
break patchLoop;
172177
} else {
173178
remainingChangedLines -= change.bufferRowCount();
179+
lastChangedRow = change.getEndBufferRow();
174180
}
175181
}
176182
}
177183
}
178184

185+
if (!foundRow) { // the selected line was the last changed line
186+
newSelectionRow = lastChangedRow;
187+
}
188+
179189
return Range.fromObject([[newSelectionRow, 0], [newSelectionRow, Infinity]]);
180190
}
181191

0 commit comments

Comments
 (0)