Skip to content

Commit e1e87fd

Browse files
improve performance
1 parent ae89dc7 commit e1e87fd

File tree

8 files changed

+33
-4
lines changed

8 files changed

+33
-4
lines changed

packages/core/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export declare class DiffFile {
116116
unifiedLines: UnifiedLineItem[];
117117
unifiedHunkLines: Record<string, DiffHunkItem>;
118118
highlighterName: string;
119+
highlighterType: string;
119120
composeByDiff: boolean;
120121
hasSomeLineCollapsed: boolean;
121122
version: string;
@@ -156,6 +157,7 @@ export declare class DiffFile {
156157
unifiedLines: UnifiedLineItem[];
157158
unifiedHunkLines: Record<string, DiffHunkItem>;
158159
highlighterName: string;
160+
highlighterType: string;
159161
composeByDiff: boolean;
160162
hasSomeLineCollapsed: boolean;
161163
version: string;

packages/core/src/diff-file.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export class DiffFile {
133133

134134
#highlighterName?: string;
135135

136+
#highlighterType?: string;
137+
136138
#theme: "light" | "dark" = "light";
137139

138140
#_theme?: "light" | "dark";
@@ -598,6 +600,8 @@ export class DiffFile {
598600
initSyntax({ registerHighlighter }: { registerHighlighter?: Omit<DiffHighlighter, "getHighlighterEngine"> } = {}) {
599601
if (this.#hasInitSyntax && (!this.#_theme || this.#theme === this.#_theme)) return;
600602

603+
if (this.#highlighterType === "class") return;
604+
601605
if (this.#composeByMerge && !this.#composeByFullMerge) {
602606
__DEV__ &&
603607
console.error(
@@ -611,6 +615,9 @@ export class DiffFile {
611615
this.#highlighterName =
612616
this.#oldFileResult?.highlighterName || this.#newFileResult?.highlighterName || this.#highlighterName;
613617

618+
this.#highlighterType =
619+
this.#oldFileResult?.highlighterType || this.#newFileResult?.highlighterType || this.#highlighterType;
620+
614621
this.#hasInitSyntax = true;
615622
}
616623

@@ -1285,6 +1292,7 @@ export class DiffFile {
12851292
const fileLineLength = this.fileLineLength;
12861293
const composeByDiff = this.#composeByDiff;
12871294
const highlighterName = this.#highlighterName;
1295+
const highlighterType = this.#highlighterType;
12881296
const hasSomeLineCollapsed = this.hasSomeLineCollapsed;
12891297

12901298
// split
@@ -1322,6 +1330,7 @@ export class DiffFile {
13221330
unifiedHunkLines,
13231331

13241332
highlighterName,
1333+
highlighterType,
13251334
composeByDiff,
13261335
hasSomeLineCollapsed,
13271336

@@ -1340,6 +1349,7 @@ export class DiffFile {
13401349
this.#hasBuildUnified = data.hasBuildUnified;
13411350
this.#composeByDiff = data.composeByDiff;
13421351
this.#highlighterName = data.highlighterName;
1352+
this.#highlighterType = data.highlighterType;
13431353

13441354
this.#oldFileLines = data.oldFileLines;
13451355
this.#oldFileDiffLines = data.oldFileDiffLines;

packages/file/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export declare class DiffFile {
115115
unifiedLines: UnifiedLineItem[];
116116
unifiedHunkLines: Record<string, DiffHunkItem>;
117117
highlighterName: string;
118+
highlighterType: string;
118119
composeByDiff: boolean;
119120
hasSomeLineCollapsed: boolean;
120121
version: string;
@@ -155,6 +156,7 @@ export declare class DiffFile {
155156
unifiedLines: UnifiedLineItem[];
156157
unifiedHunkLines: Record<string, DiffHunkItem>;
157158
highlighterName: string;
159+
highlighterType: string;
158160
composeByDiff: boolean;
159161
hasSomeLineCollapsed: boolean;
160162
version: string;

packages/react/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export declare class DiffFile {
115115
unifiedLines: UnifiedLineItem[];
116116
unifiedHunkLines: Record<string, DiffHunkItem>;
117117
highlighterName: string;
118+
highlighterType: string;
118119
composeByDiff: boolean;
119120
hasSomeLineCollapsed: boolean;
120121
version: string;
@@ -155,6 +156,7 @@ export declare class DiffFile {
155156
unifiedLines: UnifiedLineItem[];
156157
unifiedHunkLines: Record<string, DiffHunkItem>;
157158
highlighterName: string;
159+
highlighterType: string;
158160
composeByDiff: boolean;
159161
hasSomeLineCollapsed: boolean;
160162
version: string;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const DiffSplitHunkLineGitLab = ({
206206
</div>
207207
<div className="diff-split-line w-[1px] flex-shrink-0" style={{ backgroundColor: `var(${borderColorName})` }} />
208208
<div
209-
className="diff-line-hunk-action flex relative w-[1%] min-w-[40px] select-none flex-col items-center justify-center p-[1px]"
209+
className="diff-line-hunk-action relative flex w-[1%] min-w-[40px] select-none flex-col items-center justify-center p-[1px]"
210210
style={{
211211
backgroundColor: `var(${hunkLineNumberBGName})`,
212212
color: `var(${plainLineNumberColorName})`,
@@ -268,7 +268,7 @@ const DiffSplitHunkLineGitLab = ({
268268
)}
269269
</div>
270270
<div
271-
className="diff-line-hunk-content flex relative w-full items-center px-[10px]"
271+
className="diff-line-hunk-content relative flex w-full items-center px-[10px]"
272272
style={{ backgroundColor: `var(${hunkContentBGName})`, color: `var(${hunkContentColorName})` }}
273273
>
274274
{currentHunk.splitInfo?.plainText || currentHunk.text}

packages/vue/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export declare class DiffFile {
115115
unifiedLines: UnifiedLineItem[];
116116
unifiedHunkLines: Record<string, DiffHunkItem>;
117117
highlighterName: string;
118+
highlighterType: string;
118119
composeByDiff: boolean;
119120
hasSomeLineCollapsed: boolean;
120121
version: string;
@@ -155,6 +156,7 @@ export declare class DiffFile {
155156
unifiedLines: UnifiedLineItem[];
156157
unifiedHunkLines: Record<string, DiffHunkItem>;
157158
highlighterName: string;
159+
highlighterType: string;
158160
composeByDiff: boolean;
159161
hasSomeLineCollapsed: boolean;
160162
version: string;

packages/vue/src/hooks/useSyncHeight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const useSyncHeight = ({
2929
const timer = setTimeout(() => {
3030
const container = document.querySelector(`#diff-root${id.value}`);
3131

32-
const elements = Array.from(container?.querySelectorAll(selector.value));
32+
const elements = Array.from(container?.querySelectorAll(selector.value) || []);
3333

3434
const wrappers = Array.from(container?.querySelectorAll(wrapper?.value) || []);
3535

ui/vue-example/src/App.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ const diffFile = ref<DiffFile>();
1414
1515
const wrap = ref(true);
1616
17+
const dark = ref(false);
18+
1719
const mode = ref(DiffModeEnum.Split);
1820
1921
const toggleHighlight = () => (highlight.value = !highlight.value);
2022
23+
const toggleTheme = () => (dark.value = !dark.value);
24+
2125
const toggleWrap = () => (wrap.value = !wrap.value);
2226
2327
const toggleMode = () => {
@@ -55,7 +59,7 @@ watch(
5559
watch(
5660
_data,
5761
() => {
58-
worker.postMessage({ data: _data.value, theme: "dark" });
62+
worker.postMessage({ data: _data.value });
5963
},
6064
{ immediate: true }
6165
);
@@ -92,6 +96,12 @@ const resetV = () => (v.value = "");
9296
>
9397
{{ highlight ? "Toggle to disable highlight" : "Toggle to enable highlight" }}
9498
</button>
99+
<button
100+
class="rounded-full bg-sky-500 px-5 py-2 text-sm font-semibold leading-5 text-white hover:bg-sky-700"
101+
@click="toggleTheme"
102+
>
103+
{{ dark ? "Toggle to light theme" : "Toggle to dark theme" }}
104+
</button>
95105
<button
96106
class="rounded-full bg-sky-500 px-5 py-2 text-sm font-semibold leading-5 text-white hover:bg-sky-700"
97107
@click="toggleMode"
@@ -108,6 +118,7 @@ const resetV = () => (v.value = "");
108118
:diff-view-highlight="highlight"
109119
:diff-view-add-widget="true"
110120
ref="instance"
121+
:diff-view-theme="dark ? 'dark' : 'light'"
111122
:diff-view-wrap="wrap"
112123
@on-add-widget-click="resetV"
113124
:extend-data="extendData"

0 commit comments

Comments
 (0)