Fix expanding diffs without 'normal' line at the end

This commit is contained in:
René Pfeuffer
2020-06-01 17:00:47 +02:00
parent 2ad3773340
commit 4b54597e26
3 changed files with 112 additions and 8 deletions

View File

@@ -61,10 +61,16 @@ class DiffExpander {
computeMaxExpandBottomRange = (n: number) => {
if (this.file.type === "add" || this.file.type === "delete") {
return 0;
} else if (n === this.file!.hunks!.length - 1) {
return this.file!.hunks![this.file!.hunks!.length - 1].fullyExpanded ? 0 : -1;
}
return this.minLineNumber(n + 1) - this.maxLineNumber(n) - 1;
const changes = this.file.hunks![n].changes;
if (changes[changes.length - 1].type === "normal") {
if (n === this.file!.hunks!.length - 1) {
return this.file!.hunks![this.file!.hunks!.length - 1].fullyExpanded ? 0 : -1;
}
return this.minLineNumber(n + 1) - this.maxLineNumber(n) - 1;
} else {
return 0;
}
};
expandHead = (n: number, count: number, callback: (newFile: File) => void) => {
@@ -146,8 +152,8 @@ class DiffExpander {
lines.pop();
}
const newChanges = [...hunk.changes];
let oldLineNumber: number = newChanges[newChanges.length - 1].oldLineNumber!;
let newLineNumber: number = newChanges[newChanges.length - 1].newLineNumber!;
let oldLineNumber: number = this.getMaxOldLineNumber(newChanges);
let newLineNumber: number = this.getMaxNewLineNumber(newChanges);
lines.forEach(line => {
oldLineNumber += 1;
@@ -180,6 +186,16 @@ class DiffExpander {
callback(newFile);
};
getMaxOldLineNumber = (newChanges: Change[]) => {
const lastChange = newChanges[newChanges.length - 1];
return lastChange.oldLineNumber || lastChange.lineNumber!;
};
getMaxNewLineNumber = (newChanges: Change[]) => {
const lastChange = newChanges[newChanges.length - 1];
return lastChange.newLineNumber || lastChange.lineNumber!;
};
getHunk: (n: number) => ExpandableHunk = (n: number) => {
return {
maxExpandHeadRange: this.computeMaxExpandHeadRange(n),