Skip to content

Commit

Permalink
fix pure diff render
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Apr 22, 2024
1 parent d93ae8e commit ca81145
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 192 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "@git-diff-view/core",
"author": "MrWangJustToDo",
"license": "MIT",
"version": "0.0.12",
"version": "0.0.13",
"main": "index.js",
"types": "index.d.ts",
"files": [
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/diff-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export class DiffFile {

unifiedLineLength: number = 0;

fileLineLength: number = 0;

hasExpandSplitAll: boolean = false;

hasExpandUnifiedAll: boolean = false;
Expand Down Expand Up @@ -210,10 +212,14 @@ export class DiffFile {

if (this._oldFileContent) {
this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang, this._oldFileName);

this.fileLineLength = Math.max(this.fileLineLength, this.#oldFileResult.maxLineNumber);
}

if (this._newFileContent) {
this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);

this.fileLineLength = Math.max(this.fileLineLength, this.#newFileResult.maxLineNumber);
}
}

Expand Down Expand Up @@ -271,6 +277,11 @@ export class DiffFile {
this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
this.#oldFilePlaceholderLines = oldFilePlaceholderLines;
this.#newFilePlaceholderLines = newFilePlaceholderLines;
this.fileLineLength = Math.max(
this.fileLineLength,
this.#oldFileResult.maxLineNumber,
this.#newFileResult.maxLineNumber
);
// all of the file just compose by diff, so we can not do the expand action
this.#composeByDiff = true;
} else if (this.#oldFileResult) {
Expand All @@ -297,6 +308,7 @@ export class DiffFile {
if (!hasSymbolChanged && newFileContent === this._oldFileContent) return;
this._newFileContent = newFileContent;
this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
this.fileLineLength = Math.max(this.fileLineLength, this.#newFileResult.maxLineNumber);
} else if (this.#newFileResult) {
let oldLineNumber = 1;
let newLineNumber = 1;
Expand All @@ -321,6 +333,7 @@ export class DiffFile {
if (!hasSymbolChanged && oldFileContent === this._newFileContent) return;
this._oldFileContent = oldFileContent;
this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang, this._oldFileName);
this.fileLineLength = Math.max(this.fileLineLength, this.#oldFileResult.maxLineNumber);
}

this.#composeRaw();
Expand Down Expand Up @@ -1133,6 +1146,7 @@ export class DiffFile {
const newFilePlaceholderLines = this.#newFilePlaceholderLines;
const splitLineLength = this.splitLineLength;
const unifiedLineLength = this.unifiedLineLength;
const fileLineLength = this.fileLineLength;
const composeByDiff = this.#composeByDiff;
const highlighterName = this.#highlighterName;
const hasSomeLineCollapsed = this.hasSomeLineCollapsed;
Expand Down Expand Up @@ -1163,6 +1177,7 @@ export class DiffFile {
newFilePlaceholderLines,
splitLineLength,
unifiedLineLength,
fileLineLength,
splitLeftLines,
splitRightLines,
splitHunkLines,
Expand Down Expand Up @@ -1197,6 +1212,7 @@ export class DiffFile {
this.#newFilePlaceholderLines = data.newFilePlaceholderLines;
this.splitLineLength = data.splitLineLength;
this.unifiedLineLength = data.unifiedLineLength;
this.fileLineLength = data.fileLineLength;
this.hasSomeLineCollapsed = data.hasSomeLineCollapsed;

this.#splitLeftLines = data.splitLeftLines;
Expand Down
2 changes: 1 addition & 1 deletion packages/file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "@git-diff-view/file",
"author": "MrWangJustToDo",
"license": "MIT",
"version": "0.0.12",
"version": "0.0.13",
"main": "index.js",
"types": "index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/lowlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "@git-diff-view/lowlight",
"author": "MrWangJustToDo",
"license": "MIT",
"version": "0.0.12",
"version": "0.0.13",
"main": "index.js",
"types": "index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "@git-diff-view/react",
"author": "MrWangJustToDo",
"license": "MIT",
"version": "0.0.12",
"version": "0.0.13",
"main": "index.js",
"types": "index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/DiffSplitViewNormal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =

const ref2 = useRef<HTMLDivElement>(null);

const splitLineLength = diffFile.splitLineLength;
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);

const { useDiffContext } = useDiffViewContext();

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/DiffSplitViewWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Style = ({
};

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

const { useDiffContext } = useDiffViewContext();

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/DiffUnifiedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
setWidget({});
}, [diffFile, useWidget]);

const unifiedLineLength = diffFile.unifiedLineLength;
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);

const _width = useTextWidth({
text: unifiedLineLength.toString(),
Expand Down
2 changes: 1 addition & 1 deletion packages/shiki/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "@git-diff-view/shiki",
"author": "MrWangJustToDo",
"license": "MIT",
"version": "0.0.12",
"version": "0.0.13",
"types": "index.d.ts",
"type": "module",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "@git-diff-view/vue",
"author": "MrWangJustToDo",
"license": "MIT",
"version": "0.0.12",
"version": "0.0.13",
"main": "index.js",
"type": "module",
"types": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/components/DiffSplitViewNormal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const DiffSplitViewNormal = defineComponent(
const maxText = ref(props.diffFile.splitLineLength.toString());

useSubscribeDiffFile(props, (diffFile) => {
maxText.value = diffFile.splitLineLength.toString();
maxText.value = Math.max(diffFile.splitLineLength, diffFile.fileLineLength).toString();
});

const initSyncScroll = (onClean: (cb: () => void) => void) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/components/DiffSplitViewWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const DiffSplitViewWrap = defineComponent(

useSubscribeDiffFile(props, (diffFile) => {
lines.value = getSplitContentLines(diffFile);
maxText.value = diffFile.splitLineLength.toString();
maxText.value = Math.max(diffFile.splitLineLength, diffFile.fileLineLength).toString();
});

const width = useTextWidth({ text: maxText, font });
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/components/DiffUnifiedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const DiffUnifiedView = defineComponent(

useSubscribeDiffFile(props, (diffFile) => {
lines.value = getUnifiedContentLine(diffFile);
maxText.value = diffFile.splitLineLength.toString();
maxText.value = Math.max(diffFile.splitLineLength, diffFile.fileLineLength).toString();
});

const fontSize = useFontSize();
Expand Down
Loading

0 comments on commit ca81145

Please sign in to comment.