Handle added and deleted files correctly

This commit is contained in:
René Pfeuffer
2020-05-28 19:51:51 +02:00
parent abca9e9746
commit 2efd21d466
4 changed files with 115 additions and 17 deletions

View File

@@ -32,26 +32,34 @@ class DiffExpander {
}
hunkCount = () => {
return this.file.hunks.length;
if (this.file.hunks) {
return this.file.hunks.length;
} else {
return 0;
}
};
minLineNumber = (n: number) => {
return this.file.hunks[n].newStart;
minLineNumber: (n: number) => number = (n: number) => {
return this.file.hunks![n]!.newStart!;
};
maxLineNumber = (n: number) => {
return this.file.hunks[n].newStart + this.file.hunks[n].newLines;
maxLineNumber: (n: number) => number = (n: number) => {
return this.file.hunks![n]!.newStart! + this.file.hunks![n]!.newLines!;
};
computeMaxExpandHeadRange = (n: number) => {
if (n === 0) {
if (this.file.type === "delete") {
return 0;
} else if (n === 0) {
return this.minLineNumber(n) - 1;
}
return this.minLineNumber(n) - this.maxLineNumber(n - 1);
};
computeMaxExpandBottomRange = (n: number) => {
if (n === this.file.hunks.length - 1) {
if (this.file.type === "add" || this.file.type === "delete") {
return 0;
} else if (n === this.file!.hunks!.length - 1) {
return Number.MAX_SAFE_INTEGER;
}
return this.minLineNumber(n + 1) - this.maxLineNumber(n);
@@ -67,7 +75,7 @@ class DiffExpander {
expandBottom: () => {
return this;
},
hunk: this.file.hunks[n]
hunk: this.file?.hunks![n]
};
};
}