Skip to content

Commit 744e850

Browse files
fix some case for pure diff render
1 parent d5e3bed commit 744e850

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

packages/core/src/change-range.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ export function relativeChanges(stringA: string, stringB: string): { stringARang
6262
stringARange: {
6363
location: _stringA.length,
6464
length: stringA.length - _stringA.length,
65-
newLineSymbol: aEndStr === "\r\n" ? NewLineSymbol.CRLF : NewLineSymbol.LF,
65+
newLineSymbol:
66+
aEndStr === "\r\n" ? NewLineSymbol.CRLF : aEndStr.endsWith("\r") ? NewLineSymbol.CR : NewLineSymbol.LF,
6667
},
6768
stringBRange: {
6869
location: _stringB.length,
6970
length: stringB.length - _stringB.length,
70-
newLineSymbol: bEndStr === "\r\n" ? NewLineSymbol.CRLF : NewLineSymbol.LF,
71+
newLineSymbol:
72+
bEndStr === "\r\n" ? NewLineSymbol.CRLF : bEndStr.endsWith("\r") ? NewLineSymbol.CR : NewLineSymbol.LF,
7173
},
7274
};
7375
}

packages/core/src/diff-file.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ export class DiffFile {
277277
newFileContent += newDiffLine.text;
278278
oldLineNumber = newDiffLine.oldLineNumber ? newDiffLine.oldLineNumber + 1 : oldLineNumber;
279279
} else {
280-
newFileContent += this.#getOldRawLine(oldLineNumber++);
280+
const oldDiffLine = this.#getOldDiffLine(oldLineNumber);
281+
if (!oldDiffLine) {
282+
newFileContent += this.#getOldRawLine(oldLineNumber);
283+
}
284+
oldLineNumber++;
281285
}
282286
}
283287
if (newFileContent === this._oldFileContent) return;
@@ -293,7 +297,11 @@ export class DiffFile {
293297
oldFileContent += oldDiffLine.text;
294298
newLineNumber = oldDiffLine.newLineNumber ? oldDiffLine.newLineNumber + 1 : newLineNumber;
295299
} else {
296-
oldFileContent += this.#getNewRawLine(newLineNumber++);
300+
const newDiffLine = this.#getNewDiffLine(newLineNumber);
301+
if (!newDiffLine) {
302+
oldFileContent += this.#getNewRawLine(newLineNumber);
303+
}
304+
newLineNumber++;
297305
}
298306
}
299307
if (oldFileContent === this._newFileContent) return;

packages/core/src/diff-line.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class DiffLine {
2020
public readonly newLineNumber: number | null,
2121
public readonly noTrailingNewLine: boolean = false,
2222
public needRematch: boolean = false,
23-
public range?: IRange,
23+
public range?: IRange
2424
) {}
2525

2626
public withNoTrailingNewLine(noTrailingNewLine: boolean): DiffLine {

scripts/release.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const release = async (pkgName: keyof typeof pkgNameAlias) => {
6161
};
6262

6363
const run = async () => {
64+
console.log('start release @git-dff-view packages');
6465
await release("@git-diff-view/core");
6566
await release("@git-diff-view/react");
6667
await release("@git-diff-view/vue");

0 commit comments

Comments
 (0)