Skip to content

Commit ca81145

Browse files
fix pure diff render
1 parent d93ae8e commit ca81145

File tree

14 files changed

+230
-192
lines changed

14 files changed

+230
-192
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/core",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.12",
6+
"version": "0.0.13",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

packages/core/src/diff-file.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ export class DiffFile {
129129

130130
unifiedLineLength: number = 0;
131131

132+
fileLineLength: number = 0;
133+
132134
hasExpandSplitAll: boolean = false;
133135

134136
hasExpandUnifiedAll: boolean = false;
@@ -210,10 +212,14 @@ export class DiffFile {
210212

211213
if (this._oldFileContent) {
212214
this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang, this._oldFileName);
215+
216+
this.fileLineLength = Math.max(this.fileLineLength, this.#oldFileResult.maxLineNumber);
213217
}
214218

215219
if (this._newFileContent) {
216220
this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
221+
222+
this.fileLineLength = Math.max(this.fileLineLength, this.#newFileResult.maxLineNumber);
217223
}
218224
}
219225

@@ -271,6 +277,11 @@ export class DiffFile {
271277
this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
272278
this.#oldFilePlaceholderLines = oldFilePlaceholderLines;
273279
this.#newFilePlaceholderLines = newFilePlaceholderLines;
280+
this.fileLineLength = Math.max(
281+
this.fileLineLength,
282+
this.#oldFileResult.maxLineNumber,
283+
this.#newFileResult.maxLineNumber
284+
);
274285
// all of the file just compose by diff, so we can not do the expand action
275286
this.#composeByDiff = true;
276287
} else if (this.#oldFileResult) {
@@ -297,6 +308,7 @@ export class DiffFile {
297308
if (!hasSymbolChanged && newFileContent === this._oldFileContent) return;
298309
this._newFileContent = newFileContent;
299310
this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
311+
this.fileLineLength = Math.max(this.fileLineLength, this.#newFileResult.maxLineNumber);
300312
} else if (this.#newFileResult) {
301313
let oldLineNumber = 1;
302314
let newLineNumber = 1;
@@ -321,6 +333,7 @@ export class DiffFile {
321333
if (!hasSymbolChanged && oldFileContent === this._newFileContent) return;
322334
this._oldFileContent = oldFileContent;
323335
this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang, this._oldFileName);
336+
this.fileLineLength = Math.max(this.fileLineLength, this.#oldFileResult.maxLineNumber);
324337
}
325338

326339
this.#composeRaw();
@@ -1133,6 +1146,7 @@ export class DiffFile {
11331146
const newFilePlaceholderLines = this.#newFilePlaceholderLines;
11341147
const splitLineLength = this.splitLineLength;
11351148
const unifiedLineLength = this.unifiedLineLength;
1149+
const fileLineLength = this.fileLineLength;
11361150
const composeByDiff = this.#composeByDiff;
11371151
const highlighterName = this.#highlighterName;
11381152
const hasSomeLineCollapsed = this.hasSomeLineCollapsed;
@@ -1163,6 +1177,7 @@ export class DiffFile {
11631177
newFilePlaceholderLines,
11641178
splitLineLength,
11651179
unifiedLineLength,
1180+
fileLineLength,
11661181
splitLeftLines,
11671182
splitRightLines,
11681183
splitHunkLines,
@@ -1197,6 +1212,7 @@ export class DiffFile {
11971212
this.#newFilePlaceholderLines = data.newFilePlaceholderLines;
11981213
this.splitLineLength = data.splitLineLength;
11991214
this.unifiedLineLength = data.unifiedLineLength;
1215+
this.fileLineLength = data.fileLineLength;
12001216
this.hasSomeLineCollapsed = data.hasSomeLineCollapsed;
12011217

12021218
this.#splitLeftLines = data.splitLeftLines;

packages/file/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/file",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.12",
6+
"version": "0.0.13",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

packages/lowlight/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/lowlight",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.12",
6+
"version": "0.0.13",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/react",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.12",
6+
"version": "0.0.13",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

packages/react/src/components/DiffSplitViewNormal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
6868

6969
const ref2 = useRef<HTMLDivElement>(null);
7070

71-
const splitLineLength = diffFile.splitLineLength;
71+
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
7272

7373
const { useDiffContext } = useDiffViewContext();
7474

packages/react/src/components/DiffSplitViewWrap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const Style = ({
3838
};
3939

4040
export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) => {
41-
const splitLineLength = diffFile.splitLineLength;
41+
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
4242

4343
const { useDiffContext } = useDiffViewContext();
4444

packages/react/src/components/DiffUnifiedView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
6666
setWidget({});
6767
}, [diffFile, useWidget]);
6868

69-
const unifiedLineLength = diffFile.unifiedLineLength;
69+
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
7070

7171
const _width = useTextWidth({
7272
text: unifiedLineLength.toString(),

packages/shiki/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/shiki",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.12",
6+
"version": "0.0.13",
77
"types": "index.d.ts",
88
"type": "module",
99
"files": [

packages/vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/vue",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.12",
6+
"version": "0.0.13",
77
"main": "index.js",
88
"type": "module",
99
"types": "index.d.ts",

packages/vue/src/components/DiffSplitViewNormal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const DiffSplitViewNormal = defineComponent(
102102
const maxText = ref(props.diffFile.splitLineLength.toString());
103103

104104
useSubscribeDiffFile(props, (diffFile) => {
105-
maxText.value = diffFile.splitLineLength.toString();
105+
maxText.value = Math.max(diffFile.splitLineLength, diffFile.fileLineLength).toString();
106106
});
107107

108108
const initSyncScroll = (onClean: (cb: () => void) => void) => {

packages/vue/src/components/DiffSplitViewWrap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const DiffSplitViewWrap = defineComponent(
6262

6363
useSubscribeDiffFile(props, (diffFile) => {
6464
lines.value = getSplitContentLines(diffFile);
65-
maxText.value = diffFile.splitLineLength.toString();
65+
maxText.value = Math.max(diffFile.splitLineLength, diffFile.fileLineLength).toString();
6666
});
6767

6868
const width = useTextWidth({ text: maxText, font });

packages/vue/src/components/DiffUnifiedView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const DiffUnifiedView = defineComponent(
3232

3333
useSubscribeDiffFile(props, (diffFile) => {
3434
lines.value = getUnifiedContentLine(diffFile);
35-
maxText.value = diffFile.splitLineLength.toString();
35+
maxText.value = Math.max(diffFile.splitLineLength, diffFile.fileLineLength).toString();
3636
});
3737

3838
const fontSize = useFontSize();

0 commit comments

Comments
 (0)