Skip to content

Commit 32f1c89

Browse files
dev check diff and content
1 parent 7dc918b commit 32f1c89

File tree

15 files changed

+108
-65
lines changed

15 files changed

+108
-65
lines changed

packages/core/index.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ declare class File$1 {
1818
rawFile: Record<number, string>;
1919
hasDoRaw: boolean;
2020
rawLength?: number;
21-
syntaxFile: Record<number, SyntaxLineWithTemplate>;
22-
plainFile: Record<number, {
21+
syntaxFile: Record<number | string, SyntaxLineWithTemplate>;
22+
plainFile: Record<number | string, {
2323
value: string;
2424
template?: string;
2525
}>;
@@ -164,21 +164,21 @@ export declare class DiffFile {
164164
hasBuildUnified: boolean;
165165
oldFileLines: Record<number, string>;
166166
oldFileDiffLines: Record<string, DiffLineItem>;
167-
oldFilePlainLines: Record<number, {
167+
oldFilePlainLines: Record<string | number, {
168168
value: string;
169169
template?: string;
170170
}>;
171-
oldFileSyntaxLines: Record<number, SyntaxLine & {
171+
oldFileSyntaxLines: Record<string | number, SyntaxLine & {
172172
template?: string;
173173
}>;
174174
oldFilePlaceholderLines: Record<string, boolean>;
175175
newFileLines: Record<number, string>;
176176
newFileDiffLines: Record<string, DiffLineItem>;
177-
newFilePlainLines: Record<number, {
177+
newFilePlainLines: Record<string | number, {
178178
value: string;
179179
template?: string;
180180
}>;
181-
newFileSyntaxLines: Record<number, SyntaxLine & {
181+
newFileSyntaxLines: Record<string | number, SyntaxLine & {
182182
template?: string;
183183
}>;
184184
newFilePlaceholderLines: Record<string, boolean>;
@@ -226,21 +226,21 @@ export declare class DiffFile {
226226
hasBuildUnified: boolean;
227227
oldFileLines: Record<number, string>;
228228
oldFileDiffLines: Record<string, DiffLineItem>;
229-
oldFilePlainLines: Record<number, {
229+
oldFilePlainLines: Record<string | number, {
230230
value: string;
231231
template?: string;
232232
}>;
233-
oldFileSyntaxLines: Record<number, SyntaxLine & {
233+
oldFileSyntaxLines: Record<string | number, SyntaxLine & {
234234
template?: string;
235235
}>;
236236
oldFilePlaceholderLines: Record<string, boolean>;
237237
newFileLines: Record<number, string>;
238238
newFileDiffLines: Record<string, DiffLineItem>;
239-
newFilePlainLines: Record<number, {
239+
newFilePlainLines: Record<string | number, {
240240
value: string;
241241
template?: string;
242242
}>;
243-
newFileSyntaxLines: Record<number, SyntaxLine & {
243+
newFileSyntaxLines: Record<string | number, SyntaxLine & {
244244
template?: string;
245245
}>;
246246
newFilePlaceholderLines: Record<string, boolean>;

packages/core/src/diff-file.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,40 @@ export class DiffFile {
449449
}
450450

451451
this.#composeRaw();
452+
453+
if (__DEV__) {
454+
this.#checkFile();
455+
}
456+
}
457+
458+
// check the fileContent is match the diff result or not
459+
#checkFile() {
460+
for (const line in this.#oldFileDiffLines) {
461+
const diffLine = this.#oldFileDiffLines[line];
462+
const fileLine = this.#oldFilePlainLines[line];
463+
if (
464+
(this.#oldFilePlaceholderLines ? !this.#oldFilePlaceholderLines[line] : true) &&
465+
diffLine.text !== fileLine.value
466+
) {
467+
console.warn(
468+
`there are some mismatch from the 'oldFileContent' and 'diff' at line: ${line}, please make sure the 'oldFileContent' is correct`
469+
);
470+
break;
471+
}
472+
}
473+
for (const line in this.#newFileDiffLines) {
474+
const diffLine = this.#newFileDiffLines[line];
475+
const fileLine = this.#newFilePlainLines[line];
476+
if (
477+
(this.#newFilePlaceholderLines ? !this.#newFilePlaceholderLines[line] : true) &&
478+
diffLine.text !== fileLine.value
479+
) {
480+
console.warn(
481+
`there are some mismatch from the 'newFileContent' and 'diff' at line: ${line}, please make sure the 'newFileContent' is correct`
482+
);
483+
break;
484+
}
485+
}
452486
}
453487

454488
#composeDiff() {

packages/core/src/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export class File {
4040

4141
rawLength?: number;
4242

43-
syntaxFile: Record<number, SyntaxLineWithTemplate> = {};
43+
syntaxFile: Record<number | string, SyntaxLineWithTemplate> = {};
4444

45-
plainFile: Record<number, { value: string; template?: string }> = {};
45+
plainFile: Record<number | string, { value: string; template?: string }> = {};
4646

4747
hasDoSyntax: boolean = false;
4848

packages/file/index.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ declare class File$1 {
1717
rawFile: Record<number, string>;
1818
hasDoRaw: boolean;
1919
rawLength?: number;
20-
syntaxFile: Record<number, SyntaxLineWithTemplate>;
21-
plainFile: Record<number, {
20+
syntaxFile: Record<number | string, SyntaxLineWithTemplate>;
21+
plainFile: Record<number | string, {
2222
value: string;
2323
template?: string;
2424
}>;
@@ -162,21 +162,21 @@ export declare class DiffFile {
162162
hasBuildUnified: boolean;
163163
oldFileLines: Record<number, string>;
164164
oldFileDiffLines: Record<string, DiffLineItem>;
165-
oldFilePlainLines: Record<number, {
165+
oldFilePlainLines: Record<string | number, {
166166
value: string;
167167
template?: string;
168168
}>;
169-
oldFileSyntaxLines: Record<number, SyntaxLine & {
169+
oldFileSyntaxLines: Record<string | number, SyntaxLine & {
170170
template?: string;
171171
}>;
172172
oldFilePlaceholderLines: Record<string, boolean>;
173173
newFileLines: Record<number, string>;
174174
newFileDiffLines: Record<string, DiffLineItem>;
175-
newFilePlainLines: Record<number, {
175+
newFilePlainLines: Record<string | number, {
176176
value: string;
177177
template?: string;
178178
}>;
179-
newFileSyntaxLines: Record<number, SyntaxLine & {
179+
newFileSyntaxLines: Record<string | number, SyntaxLine & {
180180
template?: string;
181181
}>;
182182
newFilePlaceholderLines: Record<string, boolean>;
@@ -224,21 +224,21 @@ export declare class DiffFile {
224224
hasBuildUnified: boolean;
225225
oldFileLines: Record<number, string>;
226226
oldFileDiffLines: Record<string, DiffLineItem>;
227-
oldFilePlainLines: Record<number, {
227+
oldFilePlainLines: Record<string | number, {
228228
value: string;
229229
template?: string;
230230
}>;
231-
oldFileSyntaxLines: Record<number, SyntaxLine & {
231+
oldFileSyntaxLines: Record<string | number, SyntaxLine & {
232232
template?: string;
233233
}>;
234234
oldFilePlaceholderLines: Record<string, boolean>;
235235
newFileLines: Record<number, string>;
236236
newFileDiffLines: Record<string, DiffLineItem>;
237-
newFilePlainLines: Record<number, {
237+
newFilePlainLines: Record<string | number, {
238238
value: string;
239239
template?: string;
240240
}>;
241-
newFileSyntaxLines: Record<number, SyntaxLine & {
241+
newFileSyntaxLines: Record<string | number, SyntaxLine & {
242242
template?: string;
243243
}>;
244244
newFilePlaceholderLines: Record<string, boolean>;

packages/react/index.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ declare class File$1 {
1717
rawFile: Record<number, string>;
1818
hasDoRaw: boolean;
1919
rawLength?: number;
20-
syntaxFile: Record<number, SyntaxLineWithTemplate>;
21-
plainFile: Record<number, {
20+
syntaxFile: Record<number | string, SyntaxLineWithTemplate>;
21+
plainFile: Record<number | string, {
2222
value: string;
2323
template?: string;
2424
}>;
@@ -162,21 +162,21 @@ export declare class DiffFile {
162162
hasBuildUnified: boolean;
163163
oldFileLines: Record<number, string>;
164164
oldFileDiffLines: Record<string, DiffLineItem>;
165-
oldFilePlainLines: Record<number, {
165+
oldFilePlainLines: Record<string | number, {
166166
value: string;
167167
template?: string;
168168
}>;
169-
oldFileSyntaxLines: Record<number, SyntaxLine & {
169+
oldFileSyntaxLines: Record<string | number, SyntaxLine & {
170170
template?: string;
171171
}>;
172172
oldFilePlaceholderLines: Record<string, boolean>;
173173
newFileLines: Record<number, string>;
174174
newFileDiffLines: Record<string, DiffLineItem>;
175-
newFilePlainLines: Record<number, {
175+
newFilePlainLines: Record<string | number, {
176176
value: string;
177177
template?: string;
178178
}>;
179-
newFileSyntaxLines: Record<number, SyntaxLine & {
179+
newFileSyntaxLines: Record<string | number, SyntaxLine & {
180180
template?: string;
181181
}>;
182182
newFilePlaceholderLines: Record<string, boolean>;
@@ -224,21 +224,21 @@ export declare class DiffFile {
224224
hasBuildUnified: boolean;
225225
oldFileLines: Record<number, string>;
226226
oldFileDiffLines: Record<string, DiffLineItem>;
227-
oldFilePlainLines: Record<number, {
227+
oldFilePlainLines: Record<string | number, {
228228
value: string;
229229
template?: string;
230230
}>;
231-
oldFileSyntaxLines: Record<number, SyntaxLine & {
231+
oldFileSyntaxLines: Record<string | number, SyntaxLine & {
232232
template?: string;
233233
}>;
234234
oldFilePlaceholderLines: Record<string, boolean>;
235235
newFileLines: Record<number, string>;
236236
newFileDiffLines: Record<string, DiffLineItem>;
237-
newFilePlainLines: Record<number, {
237+
newFilePlainLines: Record<string | number, {
238238
value: string;
239239
template?: string;
240240
}>;
241-
newFileSyntaxLines: Record<number, SyntaxLine & {
241+
newFileSyntaxLines: Record<string | number, SyntaxLine & {
242242
template?: string;
243243
}>;
244244
newFilePlaceholderLines: Record<string, boolean>;

packages/react/src/components/DiffSplitHunkLineNormal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ const InternalDiffSplitHunkLineGitLab = ({
163163

164164
useSyncHeight({
165165
selector: `tr[data-line="${lineNumber}-hunk"]`,
166-
side: SplitSide[side],
167-
enable: true,
166+
side: SplitSide[SplitSide.old],
167+
enable: side === SplitSide.new,
168168
});
169169

170170
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;

packages/react/src/components/v2/DiffSplitHunkLineNormal_v2.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ const InternalDiffSplitHunkLineGitLab = ({
154154

155155
useSyncHeight({
156156
selector: `div[data-state="hunk"][data-line="${lineNumber}-hunk"]`,
157-
side: SplitSide[side],
158-
enable: true,
157+
side: SplitSide[SplitSide.old],
158+
enable: side === SplitSide.new,
159159
});
160160

161161
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;

packages/solid/index.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ declare class File$1 {
1717
rawFile: Record<number, string>;
1818
hasDoRaw: boolean;
1919
rawLength?: number;
20-
syntaxFile: Record<number, SyntaxLineWithTemplate>;
21-
plainFile: Record<number, {
20+
syntaxFile: Record<number | string, SyntaxLineWithTemplate>;
21+
plainFile: Record<number | string, {
2222
value: string;
2323
template?: string;
2424
}>;
@@ -162,21 +162,21 @@ export declare class DiffFile {
162162
hasBuildUnified: boolean;
163163
oldFileLines: Record<number, string>;
164164
oldFileDiffLines: Record<string, DiffLineItem>;
165-
oldFilePlainLines: Record<number, {
165+
oldFilePlainLines: Record<string | number, {
166166
value: string;
167167
template?: string;
168168
}>;
169-
oldFileSyntaxLines: Record<number, SyntaxLine & {
169+
oldFileSyntaxLines: Record<string | number, SyntaxLine & {
170170
template?: string;
171171
}>;
172172
oldFilePlaceholderLines: Record<string, boolean>;
173173
newFileLines: Record<number, string>;
174174
newFileDiffLines: Record<string, DiffLineItem>;
175-
newFilePlainLines: Record<number, {
175+
newFilePlainLines: Record<string | number, {
176176
value: string;
177177
template?: string;
178178
}>;
179-
newFileSyntaxLines: Record<number, SyntaxLine & {
179+
newFileSyntaxLines: Record<string | number, SyntaxLine & {
180180
template?: string;
181181
}>;
182182
newFilePlaceholderLines: Record<string, boolean>;
@@ -224,21 +224,21 @@ export declare class DiffFile {
224224
hasBuildUnified: boolean;
225225
oldFileLines: Record<number, string>;
226226
oldFileDiffLines: Record<string, DiffLineItem>;
227-
oldFilePlainLines: Record<number, {
227+
oldFilePlainLines: Record<string | number, {
228228
value: string;
229229
template?: string;
230230
}>;
231-
oldFileSyntaxLines: Record<number, SyntaxLine & {
231+
oldFileSyntaxLines: Record<string | number, SyntaxLine & {
232232
template?: string;
233233
}>;
234234
oldFilePlaceholderLines: Record<string, boolean>;
235235
newFileLines: Record<number, string>;
236236
newFileDiffLines: Record<string, DiffLineItem>;
237-
newFilePlainLines: Record<number, {
237+
newFilePlainLines: Record<string | number, {
238238
value: string;
239239
template?: string;
240240
}>;
241-
newFileSyntaxLines: Record<number, SyntaxLine & {
241+
newFileSyntaxLines: Record<string | number, SyntaxLine & {
242242
template?: string;
243243
}>;
244244
newFilePlaceholderLines: Record<string, boolean>;

packages/solid/src/components/DiffSplitHunkLineNormal.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ const DiffSplitHunkLineGitHub = (props: { index: number; side: SplitSide; diffFi
6868

6969
const currentSyncHeightSide = createMemo(() => SplitSide[SplitSide.old]);
7070

71-
const currentEnableSyncHeight = createMemo(() => props.side === SplitSide.new && !!currentIsShow());
71+
const currentEnableSyncHeight = createMemo(
72+
() => props.side === SplitSide.new && (!!currentIsShow() || currentIsPureHunk())
73+
);
7274

7375
useSyncHeight({
7476
selector: lineSelector,
@@ -218,7 +220,9 @@ const DiffSplitHunkLineGitLab = (props: { index: number; side: SplitSide; diffFi
218220

219221
const currentSyncHeightSide = createMemo(() => SplitSide[SplitSide.old]);
220222

221-
const currentEnableSyncHeight = createMemo(() => props.side === SplitSide.new && !!currentIsShow());
223+
const currentEnableSyncHeight = createMemo(
224+
() => props.side === SplitSide.new && (!!currentIsShow() || currentIsPureHunk())
225+
);
222226

223227
createEffect(() => {
224228
const init = () => {

packages/svelte/src/lib/components/DiffSplitHunkLineNormalGitHub.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
const currentSyncHeightSide = $derived.by(() => SplitSide[SplitSide.old]);
9090
9191
const currentEnableSyncHeight = $derived.by(
92-
() => props.side === SplitSide.new && !!currentIsShow
92+
() => props.side === SplitSide.new && (!!currentIsShow || currentIsPureHunk)
9393
);
9494
9595
useSyncHeight({

0 commit comments

Comments
 (0)