Skip to content

Commit 5e1d97e

Browse files
update
1 parent ee2aba0 commit 5e1d97e

File tree

14 files changed

+104
-9
lines changed

14 files changed

+104
-9
lines changed

packages/react/src/components/DiffSplitViewNormal.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
diffFontSizeName,
77
borderColorName,
88
diffAsideWidthName,
9+
getDiffIdFromElement,
910
} from "@git-diff-view/utils";
1011
import { Fragment, memo, useEffect, useRef } from "react";
1112
import * as React from "react";
@@ -137,6 +138,12 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
137138
return;
138139
}
139140

141+
const id = getDiffIdFromElement(ele as HTMLElement);
142+
143+
if (id && id !== `diff-root${diffFile.getId()}`) {
144+
return;
145+
}
146+
140147
while (ele && ele instanceof HTMLElement) {
141148
const state = ele.getAttribute("data-state");
142149
const side = ele.getAttribute("data-side");

packages/react/src/components/DiffSplitViewWrap.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import { type DiffFile, getSplitContentLines } from "@git-diff-view/core";
3-
import { diffAsideWidthName, diffFontSizeName, removeAllSelection } from "@git-diff-view/utils";
3+
import { diffAsideWidthName, diffFontSizeName, getDiffIdFromElement, removeAllSelection } from "@git-diff-view/utils";
44
import { Fragment, memo, useMemo, useRef } from "react";
55
import * as React from "react";
66
// SEE https://github.com/facebook/react/pull/25231
@@ -65,6 +65,12 @@ export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) =>
6565
return;
6666
}
6767

68+
const id = getDiffIdFromElement(ele as HTMLElement);
69+
70+
if (id && id !== `diff-root${diffFile.getId()}`) {
71+
return;
72+
}
73+
6874
while (ele && ele instanceof HTMLElement) {
6975
const state = ele.getAttribute("data-state");
7076
const side = ele.getAttribute("data-side");

packages/react/src/components/DiffUnifiedView.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import { getUnifiedContentLine, SplitSide } from "@git-diff-view/core";
3-
import { diffFontSizeName, removeAllSelection, diffAsideWidthName } from "@git-diff-view/utils";
3+
import { diffFontSizeName, removeAllSelection, diffAsideWidthName, getDiffIdFromElement } from "@git-diff-view/utils";
44
import * as React from "react";
55
import { Fragment, memo, useEffect, useMemo, useRef } from "react";
66
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
@@ -85,6 +85,12 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
8585
return;
8686
}
8787

88+
const id = getDiffIdFromElement(ele as HTMLElement);
89+
90+
if (id && id !== `diff-root${diffFile.getId()}`) {
91+
return;
92+
}
93+
8894
while (ele && ele instanceof HTMLElement) {
8995
const state = ele.getAttribute("data-state");
9096
if (state) {

packages/solid/src/components/DiffSplitViewNormal.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
borderColorName,
44
diffAsideWidthName,
55
diffFontSizeName,
6+
getDiffIdFromElement,
67
removeAllSelection,
78
syncScroll,
89
} from "@git-diff-view/utils";
@@ -49,6 +50,12 @@ const DiffSplitViewTable = (props: {
4950
return;
5051
}
5152

53+
const id = getDiffIdFromElement(ele as HTMLElement);
54+
55+
if (id && id !== `diff-root${props.diffFile.getId()}`) {
56+
return;
57+
}
58+
5259
while (ele && ele instanceof HTMLElement) {
5360
const state = ele.getAttribute("data-state");
5461
if (state) {

packages/solid/src/components/DiffSplitViewWrap.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import { getSplitContentLines, SplitSide } from "@git-diff-view/core";
3-
import { diffAsideWidthName, diffFontSizeName, removeAllSelection } from "@git-diff-view/utils";
3+
import { diffAsideWidthName, diffFontSizeName, getDiffIdFromElement, removeAllSelection } from "@git-diff-view/utils";
44
import { createEffect, createMemo, createSignal, onCleanup, For } from "solid-js";
55

66
import { useFontSize, useTextWidth } from "../hooks";
@@ -59,6 +59,12 @@ export const DiffSplitViewWrap = (props: { diffFile: DiffFile }) => {
5959
return;
6060
}
6161

62+
const id = getDiffIdFromElement(ele as HTMLElement);
63+
64+
if (id && id !== `diff-root${props.diffFile.getId()}`) {
65+
return;
66+
}
67+
6268
while (ele && ele instanceof HTMLElement) {
6369
const state = ele.getAttribute("data-state");
6470
const side = ele.getAttribute("data-side");

packages/solid/src/components/DiffUnifiedView.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getUnifiedContentLine, type DiffFile } from "@git-diff-view/core";
2-
import { diffAsideWidthName, diffFontSizeName, removeAllSelection } from "@git-diff-view/utils";
2+
import { diffAsideWidthName, diffFontSizeName, getDiffIdFromElement, removeAllSelection } from "@git-diff-view/utils";
33
import { createEffect, createMemo, createSignal, onCleanup, For } from "solid-js";
44

55
import { useEnableWrap, useFontSize, useTextWidth } from "../hooks";
@@ -56,6 +56,12 @@ export const DiffUnifiedView = (props: { diffFile: DiffFile }) => {
5656
return;
5757
}
5858

59+
const id = getDiffIdFromElement(ele as HTMLElement);
60+
61+
if (id && id !== `diff-root${props.diffFile.getId()}`) {
62+
return;
63+
}
64+
5965
while (ele && ele instanceof HTMLElement) {
6066
const state = ele.getAttribute("data-state");
6167
if (state) {

packages/svelte/src/lib/components/DiffSplitViewNormalTable.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { getSplitContentLines, SplitSide, type DiffFile } from '@git-diff-view/core';
3-
import { removeAllSelection } from '$lib/utils/dom.js';
3+
import { getDiffIdFromElement, removeAllSelection } from '$lib/utils/dom.js';
44
55
import DiffSplitContentLine from './DiffSplitContentLineNormal.svelte';
66
import DiffSplitExtendLine from './DiffSplitExtendLineNormal.svelte';
@@ -49,6 +49,12 @@
4949
return;
5050
}
5151
52+
const id = getDiffIdFromElement(ele as HTMLElement);
53+
54+
if (id && id !== `diff-root${props.diffFile.getId()}`) {
55+
return;
56+
}
57+
5258
while (ele && ele instanceof HTMLElement) {
5359
const state = ele.getAttribute('data-state');
5460
if (state) {

packages/svelte/src/lib/components/DiffSplitViewWrap.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useTextWidth } from '$lib/hooks/useTextWidth.svelte.js';
44
import { getSplitContentLines, SplitSide, type DiffFile } from '@git-diff-view/core';
55
import { diffAsideWidthName, diffFontSizeName } from '$lib/utils/size.js';
6-
import { removeAllSelection } from '$lib/utils/dom.js';
6+
import { getDiffIdFromElement, removeAllSelection } from '$lib/utils/dom.js';
77
88
import DiffSplitContentLine from './DiffSplitContentLineWrap.svelte';
99
import DiffSplitExtendLine from './DiffSplitExtendLineWrap.svelte';
@@ -72,6 +72,12 @@
7272
return;
7373
}
7474
75+
const id = getDiffIdFromElement(ele as HTMLElement);
76+
77+
if (id && id !== `diff-root${props.diffFile.getId()}`) {
78+
return;
79+
}
80+
7581
while (ele && ele instanceof HTMLElement) {
7682
const state = ele.getAttribute('data-state');
7783
const side = ele.getAttribute('data-side');

packages/svelte/src/lib/components/DiffUnifiedView.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { useTextWidth } from '$lib/hooks/useTextWidth.svelte.js';
55
import { getUnifiedContentLine, type DiffFile } from '@git-diff-view/core';
66
import { diffAsideWidthName, diffFontSizeName } from '$lib/utils/size.js';
7-
import { removeAllSelection } from '$lib/utils/dom.js';
7+
import { getDiffIdFromElement, removeAllSelection } from '$lib/utils/dom.js';
88
99
import DiffUnifiedContentLine from './DiffUnifiedContentLine.svelte';
1010
import DiffUnifiedExtendLine from './DiffUnifiedExtendLine.svelte';
@@ -58,6 +58,12 @@
5858
return;
5959
}
6060
61+
const id = getDiffIdFromElement(ele as HTMLElement);
62+
63+
if (id && id !== `diff-root${props.diffFile.getId()}`) {
64+
return;
65+
}
66+
6167
while (ele && ele instanceof HTMLElement) {
6268
const state = ele.getAttribute('data-state');
6369
if (state) {

packages/utils/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export declare const getLineNumberBG: (isAdded: boolean, isDelete: boolean, hasD
3636
export declare const removeAllSelection: () => void;
3737
export declare const syncScroll: (left: HTMLElement, right: HTMLElement) => () => void;
3838
export declare const getElementRoot: (element?: HTMLElement) => Document | ShadowRoot;
39+
export declare const getDiffIdFromElement: (element?: HTMLElement) => string;
3940
export declare const diffFontSizeName = "--diff-font-size--";
4041
export declare const diffAsideWidthName = "--diff-aside-width--";
4142
export declare const memoFunc: <T extends Function>(func: T) => T;

0 commit comments

Comments
 (0)