Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"cli diff component"
],
"dependencies": {
"@git-diff-view/core": "^0.0.35",
"@git-diff-view/core": "^0.0.36",
"@types/hast": "^3.0.0",
"highlight.js": "^11.11.0",
"lowlight": "^3.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ export declare class DiffFile {
getSplitLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getSplitRightLine: (index: number) => SplitLineItem;
getSplitHunkLine: (index: number) => DiffHunkItem;
onSplitHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onSplitHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
getUnifiedLine: (index: number) => UnifiedLineItem;
getUnifiedLineByLineNumber: (lienNumber: number, side: SplitSide) => UnifiedLineItem;
getUnifiedLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getUnifiedHunkLine: (index: number) => DiffHunkItem;
onUnifiedHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onUnifiedHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
onAllExpand: (mode: "split" | "unified") => void;
get hasExpandSplitAll(): boolean;
get hasExpandUnifiedAll(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"diff parse"
],
"dependencies": {
"@git-diff-view/lowlight": "^0.0.35",
"@git-diff-view/lowlight": "^0.0.36",
"highlight.js": "^11.11.0",
"lowlight": "^3.3.0",
"fast-diff": "^1.3.0"
Expand Down
72 changes: 68 additions & 4 deletions packages/core/src/diff-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ export class DiffFile {
return this.#splitHunksLines?.[index];
};

onSplitHunkExpand = (dir: "up" | "down" | "all", index: number, needTrigger = true) => {
onSplitHunkExpand = (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger = true) => {
const current = this.#splitHunksLines?.[index];
if (!current || !current.splitInfo) return;

Expand Down Expand Up @@ -1197,7 +1197,19 @@ export class DiffFile {
plainText: `@@ -${current.splitInfo.oldStartIndex},${current.splitInfo.oldLength} +${current.splitInfo.newStartIndex},${current.splitInfo.newLength}`,
};
}
} else {
} else if (dir === "down-all") {
for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.endHiddenIndex; i++) {
const leftLine = this.#splitLeftLines[i];
const rightLine = this.#splitRightLines[i];
if (leftLine?.isHidden) leftLine.isHidden = false;
if (rightLine?.isHidden) rightLine.isHidden = false;
}
current.splitInfo = {
...current.splitInfo,
plainText: "",
startHiddenIndex: current.splitInfo.endHiddenIndex,
};
} else if (dir === "up") {
if (current.isLast) {
if (__DEV__) {
console.error("the last hunk can not expand up!");
Expand Down Expand Up @@ -1226,6 +1238,28 @@ export class DiffFile {

delete this.#splitHunksLines?.[index];

this.#splitHunksLines![current.splitInfo.endHiddenIndex] = current;
} else if (dir === "up-all") {
if (current.isLast) {
if (__DEV__) {
console.error("the last hunk can not expand up!");
}
return;
}
for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.endHiddenIndex; i++) {
const leftLine = this.#splitLeftLines[i];
const rightLine = this.#splitRightLines[i];
if (leftLine?.isHidden) leftLine.isHidden = false;
if (rightLine?.isHidden) rightLine.isHidden = false;
}
current.splitInfo = {
...current.splitInfo,
plainText: "",
endHiddenIndex: current.splitInfo.startHiddenIndex,
};

delete this.#splitHunksLines?.[index];

this.#splitHunksLines![current.splitInfo.endHiddenIndex] = current;
}

Expand Down Expand Up @@ -1259,7 +1293,7 @@ export class DiffFile {
};

// TODO! support rollback?
onUnifiedHunkExpand = (dir: "up" | "down" | "all", index: number, needTrigger = true) => {
onUnifiedHunkExpand = (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger = true) => {
if (this.#composeByDiff) return;

const current = this.#unifiedHunksLines?.[index];
Expand Down Expand Up @@ -1296,7 +1330,17 @@ export class DiffFile {
plainText: `@@ -${current.unifiedInfo.oldStartIndex},${current.unifiedInfo.oldLength} +${current.unifiedInfo.newStartIndex},${current.unifiedInfo.newLength}`,
};
}
} else {
} else if (dir === "down-all") {
for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.endHiddenIndex; i++) {
const unifiedLine = this.#unifiedLines[i];
if (unifiedLine?.isHidden) unifiedLine.isHidden = false;
}
current.unifiedInfo = {
...current.unifiedInfo,
plainText: "",
startHiddenIndex: current.unifiedInfo.endHiddenIndex,
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "down-all" implementation is missing the plainText property update. Compare with the "down" case (lines 1325-1329) which updates plainText when !current.isLast. The plainText should be updated to reflect the new hunk header after expanding all lines downward.

Suggested change
startHiddenIndex: current.unifiedInfo.endHiddenIndex,
startHiddenIndex: current.unifiedInfo.endHiddenIndex,
plainText: `@@ -${current.unifiedInfo.oldStartIndex},${current.unifiedInfo.oldLength} +${current.unifiedInfo.newStartIndex},${current.unifiedInfo.newLength}`,

Copilot uses AI. Check for mistakes.
};
} else if (dir === "up") {
if (current.isLast) {
if (__DEV__) {
console.error("the last hunk can not expand up!");
Expand All @@ -1323,6 +1367,26 @@ export class DiffFile {

delete this.#unifiedHunksLines?.[index];

this.#unifiedHunksLines![current.unifiedInfo.endHiddenIndex] = current;
} else if (dir === "up-all") {
if (current.isLast) {
if (__DEV__) {
console.error("the last hunk can not expand up!");
}
return;
}
for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.endHiddenIndex; i++) {
const unifiedLine = this.#unifiedLines[i];
if (unifiedLine?.isHidden) unifiedLine.isHidden = false;
}
current.unifiedInfo = {
...current.unifiedInfo,
plainText: "",
endHiddenIndex: current.unifiedInfo.startHiddenIndex,
};

delete this.#unifiedHunksLines?.[index];

this.#unifiedHunksLines![current.unifiedInfo.endHiddenIndex] = current;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/parse/diff-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export class DiffParser {
while ((c = this.parseLinePrefix(this.peek()))) {
const line = this.readLine(false);

if (!line) {
if (line === null) {
throw new Error("Expected unified diff line but reached end of diff");
}

Expand Down
4 changes: 2 additions & 2 deletions packages/file/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ export declare class DiffFile {
getSplitLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getSplitRightLine: (index: number) => SplitLineItem;
getSplitHunkLine: (index: number) => DiffHunkItem;
onSplitHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onSplitHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
getUnifiedLine: (index: number) => UnifiedLineItem;
getUnifiedLineByLineNumber: (lienNumber: number, side: SplitSide) => UnifiedLineItem;
getUnifiedLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getUnifiedHunkLine: (index: number) => DiffHunkItem;
onUnifiedHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onUnifiedHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
onAllExpand: (mode: "split" | "unified") => void;
get hasExpandSplitAll(): boolean;
get hasExpandUnifiedAll(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"diff parse"
],
"dependencies": {
"@git-diff-view/core": "^0.0.35",
"@git-diff-view/core": "^0.0.36",
"diff": "^8.0.2",
"highlight.js": "^11.11.0",
"lowlight": "^3.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ export declare class DiffFile {
getSplitLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getSplitRightLine: (index: number) => SplitLineItem;
getSplitHunkLine: (index: number) => DiffHunkItem;
onSplitHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onSplitHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
getUnifiedLine: (index: number) => UnifiedLineItem;
getUnifiedLineByLineNumber: (lienNumber: number, side: SplitSide) => UnifiedLineItem;
getUnifiedLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getUnifiedHunkLine: (index: number) => DiffHunkItem;
onUnifiedHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onUnifiedHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
onAllExpand: (mode: "split" | "unified") => void;
get hasExpandSplitAll(): boolean;
get hasExpandUnifiedAll(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"react diff component"
],
"dependencies": {
"@git-diff-view/core": "^0.0.35",
"@git-diff-view/core": "^0.0.36",
"@types/hast": "^3.0.0",
"fast-diff": "^1.3.0",
"highlight.js": "^11.11.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/solid/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ export declare class DiffFile {
getSplitLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getSplitRightLine: (index: number) => SplitLineItem;
getSplitHunkLine: (index: number) => DiffHunkItem;
onSplitHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onSplitHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
getUnifiedLine: (index: number) => UnifiedLineItem;
getUnifiedLineByLineNumber: (lienNumber: number, side: SplitSide) => UnifiedLineItem;
getUnifiedLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getUnifiedHunkLine: (index: number) => DiffHunkItem;
onUnifiedHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onUnifiedHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
onAllExpand: (mode: "split" | "unified") => void;
get hasExpandSplitAll(): boolean;
get hasExpandUnifiedAll(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"solid diff component"
],
"dependencies": {
"@git-diff-view/core": "^0.0.35",
"@git-diff-view/core": "^0.0.36",
"@types/hast": "^3.0.0",
"highlight.js": "^11.11.0",
"lowlight": "^3.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"./package.json": "./package.json"
},
"dependencies": {
"@git-diff-view/core": "^0.0.35",
"@git-diff-view/core": "^0.0.36",
"@types/hast": "^3.0.0",
"highlight.js": "^11.11.0",
"lowlight": "^3.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ export declare class DiffFile {
getSplitLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getSplitRightLine: (index: number) => SplitLineItem;
getSplitHunkLine: (index: number) => DiffHunkItem;
onSplitHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onSplitHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
getUnifiedLine: (index: number) => UnifiedLineItem;
getUnifiedLineByLineNumber: (lienNumber: number, side: SplitSide) => UnifiedLineItem;
getUnifiedLineIndexByLineNumber: (lineNumber: number, side: SplitSide) => number;
getUnifiedHunkLine: (index: number) => DiffHunkItem;
onUnifiedHunkExpand: (dir: "up" | "down" | "all", index: number, needTrigger?: boolean) => void;
onUnifiedHunkExpand: (dir: "up" | "down" | "all" | "up-all" | "down-all", index: number, needTrigger?: boolean) => void;
onAllExpand: (mode: "split" | "unified") => void;
get hasExpandSplitAll(): boolean;
get hasExpandUnifiedAll(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"vue diff component"
],
"dependencies": {
"@git-diff-view/core": "^0.0.35",
"@git-diff-view/core": "^0.0.36",
"@types/hast": "^3.0.0",
"highlight.js": "^11.11.0",
"lowlight": "^3.3.0",
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/react-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --force",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
Expand Down