Skip to content

Commit a9c4ee4

Browse files
fix
1 parent 9fe3a7a commit a9c4ee4

File tree

9 files changed

+49
-20
lines changed

9 files changed

+49
-20
lines changed

packages/core/src/parse/diff-tool.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { diffChanges, relativeChanges } from "./change-range";
2-
import { DiffLineType } from "./diff-line";
2+
import { DiffLineType, DiffLine } from "./diff-line";
33
import { DiffHunkExpansionType } from "./raw-diff";
44
import {
55
getEnableFastDiffTemplate,
@@ -10,7 +10,6 @@ import {
1010
} from "./template";
1111

1212
import type { SyntaxLineWithTemplate } from "../file";
13-
import type { DiffLine } from "./diff-line";
1413
import type { DiffHunk, DiffHunkHeader } from "./raw-diff";
1514

1615
/** How many new lines will be added to a diff hunk by default. */
@@ -122,8 +121,14 @@ export const getDiffRange = (
122121
if (!addition.changes || !deletion.changes) {
123122
// use the original text content to computed diff range
124123
// fix: get diff with ignoreWhiteSpace config
125-
const _addition = addition.clone(getAdditionRaw(addition.newLineNumber) || addition.text || "");
126-
const _deletion = deletion.clone(getDeletionRaw(deletion.oldLineNumber) || deletion.text || "");
124+
const _addition = DiffLine.prototype.clone.call(
125+
addition,
126+
getAdditionRaw(addition.newLineNumber) || addition.text || ""
127+
);
128+
const _deletion = DiffLine.prototype.clone.call(
129+
deletion,
130+
getDeletionRaw(deletion.oldLineNumber) || deletion.text || ""
131+
);
127132
const { addRange, delRange } = relativeChanges(_addition, _deletion);
128133
addition.changes = addRange;
129134
deletion.changes = delRange;
@@ -154,8 +159,14 @@ export const getDiffRange = (
154159
});
155160
}
156161
} else {
157-
const _addition = addition.clone(getAdditionRaw(addition.newLineNumber) || addition.text || "");
158-
const _deletion = deletion.clone(getDeletionRaw(deletion.oldLineNumber) || deletion.text || "");
162+
const _addition = DiffLine.prototype.clone.call(
163+
addition,
164+
getAdditionRaw(addition.newLineNumber) || addition.text || ""
165+
);
166+
const _deletion = DiffLine.prototype.clone.call(
167+
deletion,
168+
getDeletionRaw(deletion.oldLineNumber) || deletion.text || ""
169+
);
159170
const { addRange, delRange } = diffChanges(_addition, _deletion);
160171
addition.diffChanges = addRange;
161172
deletion.diffChanges = delRange;

packages/solid/src/components/DiffView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ const InternalDiffView = <T extends unknown>(props: DiffViewProps<T>) => {
181181
currentDiffFile.initRaw();
182182
currentDiffFile.buildSplitDiffLines();
183183
currentDiffFile.buildUnifiedDiffLines();
184+
// 看起来solid的 effect 调用无法保证顺序?
185+
currentDiffFile.notifyAll();
184186
}
185187
};
186188

packages/svelte/src/lib/components/DiffSplitExtendLineNormal.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
1616
let props: Props = $props();
1717
18+
let lineDom = $state<HTMLElement | null>(null);
19+
1820
const extendData = $derived.by(getExtend());
1921
2022
const renderExtend = $derived.by(getRenderExtend());
@@ -67,13 +69,13 @@
6769
selector: () => lineSelector,
6870
wrapper: () => lineWrapperSelector,
6971
side: () => extendSide,
70-
enable: () => currentIsShow
72+
enable: () => Boolean(currentIsShow && lineDom)
7173
});
7274
7375
const width = $derived.by(
7476
useDomWidth({
7577
selector: () => wrapperSelector,
76-
enable: () => currentEnable
78+
enable: () => Boolean(currentEnable && lineDom)
7779
})
7880
);
7981
</script>
@@ -84,6 +86,7 @@
8486
data-state="extend"
8587
data-side={SplitSide[props.side]}
8688
class="diff-line diff-line-extend"
89+
{@attach (l) => (lineDom = l)}
8790
>
8891
{#if !!renderExtend && currentExtend}
8992
<td class={`diff-line-extend-${SplitSide[props.side]}-content p-0`} colspan={2}>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
2323
let props: Props = $props();
2424
25+
let lineDom = $state<HTMLElement | null>(null);
26+
2527
const currentHunk = $derived.by(() => props.diffFile.getSplitHunkLine(props.index));
2628
2729
const enableExpand = $derived.by(() => props.diffFile.getExpandEnabled());
@@ -94,7 +96,7 @@
9496
selector: () => lineSelector,
9597
wrapper: () => lineSelector,
9698
side: () => currentSyncHeightSide,
97-
enable: () => currentEnableSyncHeight
99+
enable: () => Boolean(currentEnableSyncHeight && lineDom)
98100
});
99101
</script>
100102

@@ -105,6 +107,7 @@
105107
data-side={SplitSide[props.side]}
106108
style={`background-color: var(${hunkContentBGName})`}
107109
class="diff-line diff-line-hunk"
110+
{@attach (l) => (lineDom = l)}
108111
>
109112
{#if currentShowExpand}
110113
<td

packages/svelte/src/lib/components/DiffSplitHunkLineNormalGitLab.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
2323
let props: Props = $props();
2424
25+
let lineDom = $state<HTMLElement | null>(null);
26+
2527
const currentHunk = $derived.by(() => props.diffFile.getSplitHunkLine(props.index));
2628
2729
const enableExpand = $derived.by(() => props.diffFile.getExpandEnabled());
@@ -92,7 +94,7 @@
9294
selector: () => lineSelector,
9395
wrapper: () => lineSelector,
9496
side: () => currentSyncHeightSide,
95-
enable: () => currentEnableSyncHeight
97+
enable: () => Boolean(currentEnableSyncHeight && lineDom)
9698
});
9799
</script>
98100

@@ -103,6 +105,7 @@
103105
data-side={SplitSide[props.side]}
104106
style={`background-color: var(${hunkContentBGName})`}
105107
class="diff-line diff-line-hunk"
108+
{@attach (l) => (lineDom = l)}
106109
>
107110
<td
108111
class="diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]"

packages/svelte/src/lib/components/DiffSplitWidgetLineNormal.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
1616
let props: Props = $props();
1717
18+
let lineDom = $state<HTMLElement | null>(null);
19+
1820
const renderWidget = $derived.by(getRenderWidget());
1921
2022
const widget = $derived.by(getWidget());
@@ -75,13 +77,13 @@
7577
selector: () => lineSelector,
7678
wrapper: () => lineWrapperSelector,
7779
side: () => observeSide,
78-
enable: () => currentIsShow
80+
enable: () => Boolean(currentIsShow && lineDom)
7981
});
8082
8183
const width = $derived.by(
8284
useDomWidth({
8385
selector: () => wrapperSelector,
84-
enable: () => currentEnable
86+
enable: () => Boolean(currentEnable && lineDom)
8587
})
8688
);
8789
</script>
@@ -92,6 +94,7 @@
9294
data-state="widget"
9395
data-side={SplitSide[props.side]}
9496
class="diff-line diff-line-widget"
97+
{@attach (l) => (lineDom = l)}
9598
>
9699
{#if currentWidget}
97100
<td class={`diff-line-widget-${SplitSide[props.side]}-content p-0`} colspan={2}>

packages/svelte/src/lib/hooks/useDomWidth.svelte.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export const useDomWidth = ({
2525
const observeWidth = () => {
2626
if (!isMounted) return;
2727

28-
cancel.current?.();
29-
3028
if (enable()) {
3129
const container = document.querySelector(`#diff-root${id}`);
3230

@@ -79,7 +77,11 @@ export const useDomWidth = ({
7977
}
8078
};
8179

82-
$effect(observeWidth);
80+
$effect(() => {
81+
observeWidth();
82+
83+
return () => cancel.current?.();
84+
});
8385

8486
return () => width;
8587
};

packages/svelte/src/lib/hooks/useSyncHeight.svelte.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export const useSyncHeight = ({
2222
const unSubscribe = { current: () => {} };
2323

2424
const observeHeight = () => {
25-
unSubscribe.current();
26-
2725
if (!isMounted) return;
2826

2927
if (enable()) {
@@ -100,5 +98,9 @@ export const useSyncHeight = ({
10098
}
10199
};
102100

103-
$effect(observeHeight);
101+
$effect(() => {
102+
observeHeight();
103+
104+
return () => unSubscribe.current?.();
105+
});
104106
};

scripts/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ const start = async () => {
121121
process.exit(0);
122122
};
123123

124-
start();
124+
// start();
125125

126126
// buildCli();
127127

128-
// buildSvelte();
128+
buildSvelte();

0 commit comments

Comments
 (0)