Skip to content

Commit 17f2a29

Browse files
update
1 parent c236d82 commit 17f2a29

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@git-diff-view/svelte": "workspace:*",
3535
"@git-diff-view/utils": "workspace:*",
3636
"@git-diff-view/cli": "workspace:*",
37+
"@git-diff-view/shiki": "workspace:*",
3738
"@rollup/plugin-alias": "^5.1.1",
3839
"@swc/core": "^1.10.15",
3940
"@types/lodash": "^4.17.15",

packages/cli/src/components/DiffView.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { DiffUnifiedView } from "./DiffUnifiedView";
1111
import { DiffViewContext } from "./DiffViewContext";
1212
import { createDiffConfigStore } from "./tools";
1313

14-
import type { DiffHighlighterLang } from "@git-diff-view/core";
14+
import type { DiffHighlighter, DiffHighlighterLang } from "@git-diff-view/core";
1515

1616
_cacheMap.name = "@git-diff-view/cli";
1717

@@ -26,6 +26,7 @@ export type DiffViewProps = {
2626
diffFile?: DiffFile;
2727
diffViewMode?: DiffModeEnum;
2828
diffViewTheme?: "light" | "dark";
29+
registerHighlighter?: Omit<DiffHighlighter, "getHighlighterEngine">;
2930
diffViewHighlight?: boolean;
3031
};
3132

@@ -102,7 +103,7 @@ const InternalDiffView = (
102103
const MemoedInternalDiffView = memo(InternalDiffView);
103104

104105
const DiffViewWithRef = (props: DiffViewProps) => {
105-
const { data, diffViewTheme, diffFile: _diffFile, ...restProps } = props;
106+
const { registerHighlighter, data, diffViewTheme, diffFile: _diffFile, ...restProps } = props;
106107

107108
const diffFile = useMemo(() => {
108109
if (_diffFile) {
@@ -155,10 +156,10 @@ const DiffViewWithRef = (props: DiffViewProps) => {
155156
useEffect(() => {
156157
if (!diffFile) return;
157158
if (props.diffViewHighlight) {
158-
diffFile.initSyntax();
159-
diffFile.notifyAll();
159+
diffFile.initSyntax({ registerHighlighter: registerHighlighter });
160160
}
161-
}, [diffFile, props.diffViewHighlight, props.diffViewTheme]);
161+
diffFile.notifyAll();
162+
}, [diffFile, props.diffViewHighlight, props.diffViewTheme, registerHighlighter]);
162163

163164
// fix react strict mode error
164165
useUnmount(() => (__DEV__ ? diffFile?._destroy?.() : diffFile?.clear?.()), [diffFile]);

packages/cli/test/index.mjs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getDiffViewHighlighter } from "@git-diff-view/shiki";
12
// import { createElement } from "@my-react/react";
23
// import { render } from "@my-react/react-terminal";
34
import { render } from "ink";
@@ -58,11 +59,23 @@ index 5b301628..15aac42f 100644
5859
}
5960
`;
6061

61-
render(
62-
createElement(DiffView, {
63-
data: { hunks: [hunks], newFile: { fileLang: "tsx" } },
64-
diffViewTheme: "light",
65-
diffViewHighlight: true,
66-
diffViewMode: DiffModeEnum.SplitGitLab
67-
})
68-
);
62+
getDiffViewHighlighter().then((highlighter) => {
63+
render(
64+
createElement(DiffView, {
65+
data: { hunks: [hunks], newFile: { fileLang: "tsx" } },
66+
diffViewTheme: "light",
67+
diffViewHighlight: true,
68+
registerHighlighter: highlighter,
69+
diffViewMode: DiffModeEnum.SplitGitLab,
70+
})
71+
);
72+
});
73+
74+
// render(
75+
// createElement(DiffView, {
76+
// data: { hunks: [hunks], newFile: { fileLang: "tsx" } },
77+
// diffViewTheme: "light",
78+
// diffViewHighlight: true,
79+
// diffViewMode: DiffModeEnum.SplitGitLab,
80+
// })
81+
// );

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)