refactor: format diff line counts through one shared helper (#17948)

This commit is contained in:
maria authored and GitHub committed 2026-10-10 22:13:45 -03:00
1 parent 75c439f4ec
commit 0f36a11769
13 files changed
+84 -30

No files matched your search

@@ -1,4 +1,5 @@
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
import { ScreenHeader } from "../../components/ScreenHeader";
@@ -282,9 +283,11 @@ const ReviewFileNavigatorRow = memo(function ReviewFileNavigatorRow(props: {
</Text>
<View className="mt-1 flex-row gap-2">
<Text className="text-2xs font-t3-bold text-adaptive-emerald-700-300">
+{file.additions}
+{formatDiffCount(file.additions)}
</Text>
<Text className="text-2xs font-t3-bold text-adaptive-rose-700-300">
-{formatDiffCount(file.deletions)}
</Text>
<Text className="text-2xs font-t3-bold text-adaptive-rose-700-300">-{file.deletions}</Text>
</View>
</Pressable>
);
@@ -1,4 +1,5 @@
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import { countReviewCommentContexts, parseReviewInlineComments } from "./reviewCommentSelection";
import { getCachedNativeReviewDiffData } from "./nativeReviewDiffAdapter";
@@ -109,12 +110,15 @@ export function formatHeaderDiffSummary(
} {
if (files) {
return {
additions: `+${files.reduce((total, file) => total + file.additions, 0)}`,
deletions: `-${files.reduce((total, file) => total + file.deletions, 0)}`,
additions: `+${formatDiffCount(files.reduce((total, file) => total + file.additions, 0))}`,
deletions: `-${formatDiffCount(files.reduce((total, file) => total + file.deletions, 0))}`,
};
}
if (parsedDiff.kind !== "files") return { additions: null, deletions: null };
return { additions: `+${parsedDiff.additions}`, deletions: `-${parsedDiff.deletions}` };
return {
additions: `+${formatDiffCount(parsedDiff.additions)}`,
deletions: `-${formatDiffCount(parsedDiff.deletions)}`,
};
}
export function useReviewDiffData(input: {
@@ -1,6 +1,7 @@
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
import { useCallback, useState } from "react";
import { Platform, Pressable, ScrollView, useWindowDimensions, View } from "react-native";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AndroidSheetHeader } from "../../../components/AndroidScreenHeader";
@@ -134,7 +135,8 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
Files
</Text>
<Text className="text-foreground-muted text-xs leading-normal">
{selectedFiles.length} selected · +{selectedInsertions} / -{selectedDeletions}
{selectedFiles.length} selected · +{formatDiffCount(selectedInsertions)} / -
{formatDiffCount(selectedDeletions)}
</Text>
</View>
<View className="flex-row items-center gap-2">
@@ -171,10 +173,10 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
{file.path}
</Text>
<Text className="text-xs font-t3-bold text-adaptive-emerald-700-300">
+{file.insertions}
+{formatDiffCount(file.insertions)}
</Text>
<Text className="text-xs font-t3-bold text-adaptive-rose-700-300">
-{file.deletions}
-{formatDiffCount(file.deletions)}
</Text>
</View>
))}
@@ -250,10 +252,10 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
</View>
<View className="items-end gap-1">
<Text className="text-xs font-t3-bold text-adaptive-emerald-700-300">
+{file.insertions}
+{formatDiffCount(file.insertions)}
</Text>
<Text className="text-xs font-t3-bold text-adaptive-rose-700-300">
-{file.deletions}
-{formatDiffCount(file.deletions)}
</Text>
</View>
</View>
@@ -1,5 +1,6 @@
import type { V2ItemSupport } from "@t3tools/client-runtime/state/item-support";
import { toolItemForDisplay } from "@t3tools/client-runtime/work-log/presentation";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import type { ThreadId } from "@t3tools/contracts";
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
import * as DateTime from "effect/DateTime";
@@ -160,7 +161,7 @@ export function buildThreadActivityInspector(
if (item.additions !== undefined || item.deletions !== undefined) {
fields.push({
label: "Changes",
value: `+${item.additions ?? 0} −${item.deletions ?? 0}`,
value: `+${formatDiffCount(item.additions ?? 0)} −${formatDiffCount(item.deletions ?? 0)}`,
});
}
break;
@@ -206,7 +207,10 @@ export function buildThreadActivityInspector(
blocks,
"Files",
item.files
.map((file) => `${file.path} +${file.additions} −${file.deletions} ${file.kind}`)
.map(
(file) =>
`${file.path} +${formatDiffCount(file.additions)} −${formatDiffCount(file.deletions)} ${file.kind}`,
)
.join("\n"),
);
break;
@@ -80,7 +80,9 @@ vi.mock("~/state/query", () => ({
isDefaultRef: false,
hasPrimaryRemote: true,
hasWorkingTreeChanges: true,
workingTree: { files: [{ path: "file.ts", status: "modified" }] },
workingTree: {
files: [{ path: "file.ts", status: "modified", insertions: 1, deletions: 0 }],
},
},
error: null,
}),
@@ -125,6 +125,7 @@ import {
} from "./chat/threadDetailsPanelStyles";
import { getSourceControlPresentation, sourceControlIcon } from "~/sourceControlPresentation";
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import { useOpenLink } from "~/browser/useOpenLink";
interface GitActionsControlProps {
@@ -1910,8 +1911,10 @@ export default function GitActionsControl({
<FileDiffIcon className={THREAD_DETAILS_PANEL_ICON_CLASS} aria-hidden />
<span className={cn("flex-1 text-left", THREAD_DETAILS_PANEL_LABEL_CLASS)}>Changes</span>
<span className="flex items-center gap-1 font-mono text-2xs tabular-nums">
<span className="text-success">+{changesTotals?.insertions ?? 0}</span>
<span className="text-destructive">-{changesTotals?.deletions ?? 0}</span>
<span className="text-success">+{formatDiffCount(changesTotals?.insertions ?? 0)}</span>
<span className="text-destructive">
-{formatDiffCount(changesTotals?.deletions ?? 0)}
</span>
</span>
</ThreadDetailsControl>
) : null}
@@ -2021,11 +2024,11 @@ export default function GitActionsControl({
) : (
<>
<span className="text-diff-addition">
+{file.insertions}
+{formatDiffCount(file.insertions)}
</span>
<span className="text-muted-foreground"> / </span>
<span className="text-diff-deletion">
-{file.deletions}
-{formatDiffCount(file.deletions)}
</span>
</>
)}
@@ -2039,11 +2042,11 @@ export default function GitActionsControl({
</div>
<div className="flex justify-end font-mono">
<span className="text-diff-addition">
+{selectedFiles.reduce((sum, f) => sum + f.insertions, 0)}
+{formatDiffCount(selectedFiles.reduce((sum, f) => sum + f.insertions, 0))}
</span>
<span className="text-muted-foreground"> / </span>
<span className="text-diff-deletion">
-{selectedFiles.reduce((sum, f) => sum + f.deletions, 0)}
-{formatDiffCount(selectedFiles.reduce((sum, f) => sum + f.deletions, 0))}
</span>
</div>
</div>
+7 -2
View File
@@ -33,6 +33,7 @@ import {
threadWokeAt,
} from "@t3tools/client-runtime/state/thread-settled";
import { createInboxReturnTracker } from "@t3tools/client-runtime/state/thread-inbox";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import {
resolveSettledThreadTimestamp,
sortSettledThreads,
@@ -2186,8 +2187,12 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
{prBadge}
{diff ? (
<span className="shrink-0 font-mono">
<span className="text-diff-addition-foreground">+{diff.insertions}</span>{" "}
<span className="text-diff-deletion-foreground">−{diff.deletions}</span>
<span className="text-diff-addition-foreground">
+{formatDiffCount(diff.insertions)}
</span>{" "}
<span className="text-diff-deletion-foreground">
−{formatDiffCount(diff.deletions)}
</span>
</span>
) : null}
<span
@@ -11,6 +11,7 @@ import {
turnItemOutputImages,
turnItemOutputText,
} from "@t3tools/client-runtime/work-log/item-detail";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import { ExternalLinkIcon, GitBranchIcon, RotateCcwIcon } from "lucide-react";
import { memo, Suspense, use, useMemo } from "react";
@@ -261,8 +262,8 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
</span>
{item.additions !== undefined || item.deletions !== undefined ? (
<span>
<span className="text-success">+{item.additions ?? 0}</span>{" "}
<span className="text-destructive">-{item.deletions ?? 0}</span>
<span className="text-success">+{formatDiffCount(item.additions ?? 0)}</span>{" "}
<span className="text-destructive">-{formatDiffCount(item.deletions ?? 0)}</span>
</span>
) : null}
{item.runId !== null ? (
@@ -9,6 +9,7 @@ import type {
PullRequestReviewDecision,
PullRequestState,
} from "@t3tools/contracts";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import {
CircleCheckIcon,
CircleDashedIcon,
@@ -524,8 +525,8 @@ export function PullRequestDiffStat({
}
return (
<span className={cn("inline-flex items-baseline gap-1 tabular-nums", className)}>
<span className="text-diff-addition-foreground">+{additions.toLocaleString()}</span>
<span className="text-diff-deletion">-{deletions.toLocaleString()}</span>
<span className="text-diff-addition-foreground">+{formatDiffCount(additions)}</span>
<span className="text-diff-deletion">-{formatDiffCount(deletions)}</span>
</span>
);
}
+4
View File
@@ -383,6 +383,10 @@
"types": "./src/device/duoControl.ts",
"default": "./src/device/duoControl.ts"
},
"./diff-count": {
"types": "./src/diffCount.ts",
"default": "./src/diffCount.ts"
},
"./mcp-apps": {
"types": "./src/mcpApps/host.ts",
"default": "./src/mcpApps/host.ts"
+6
View File
@@ -0,0 +1,6 @@
const DIFF_COUNT_FORMAT = new Intl.NumberFormat();
/** Formats a diff line count with the viewer's digit grouping, so `83065` reads `83,065`. */
export function formatDiffCount(count: number): string {
return DIFF_COUNT_FORMAT.format(count);
}
+19
View File
@@ -970,6 +970,25 @@ index 84c7915..d1930bf 100644
if (hasCustomHeader) managedOptions.renderCustomHeader = noopRender;
if (hasGutterRenderer) managedOptions.renderGutterUtility = noopRender;
if (hasCodeViewHeader) managedOptions.renderCodeViewHeader = noopRender;
diff --git a/dist/utils/createFileHeaderElement.js b/dist/utils/createFileHeaderElement.js
index 39fe30e..600442e 100644
--- a/dist/utils/createFileHeaderElement.js
+++ b/dist/utils/createFileHeaderElement.js
@@ -73,12 +73,12 @@ function createMetadataElement(fileDiff) {
}
if (deletions > 0 || additions === 0) children.push(createHastElement({
tagName: "span",
- children: [createTextNodeElement(`-${deletions}`)],
+ children: [createTextNodeElement(`-${deletions.toLocaleString()}`)],
properties: { "data-deletions-count": "" }
}));
if (additions > 0 || deletions === 0) children.push(createHastElement({
tagName: "span",
- children: [createTextNodeElement(`+${additions}`)],
+ children: [createTextNodeElement(`+${additions.toLocaleString()}`)],
properties: { "data-additions-count": "" }
}));
}
diff --git a/package.json b/package.json
index d9dc7b5..3c37bae 100644
--- a/package.json
+5 -5
View File
@@ -151,7 +151,7 @@ patchedDependencies:
'@opencode/[email protected]': f725d6e6d9af0d56dc6ed71b863518fbfc751af1773cff2311209d2c404cf4cd
'@opencode/[email protected]': 17a82f6c2c98fd0371e786c211a4fbdaaba403577a25733e5e99a0c25a16a685
'@opencode/[email protected]': 650f1b8602789407c010861284272dcb6bd6de01ec6a75bf3c0904a0e7596d59
'@pierre/[email protected]': b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0
'@pierre/[email protected]': 298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7
'@react-native-ai/[email protected]': 2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d
'@react-native-menu/[email protected]': a4866ecfcd44f318043de839d20110c17e14909004900f002ffe12050376f2ba
'@react-navigation/[email protected]': d2d52f3776e30765519748fd5e177592dc3b9cc778c52fb00e02674dfa9042c5
@@ -331,7 +331,7 @@ importers:
version: 1.9.1
'@pierre/diffs':
specifier: 'catalog:'
version: 1.5.2(patch_hash=b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0)(@shikijs/[email protected])([email protected]([email protected]))([email protected])
version: 1.5.2(patch_hash=298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7)(@shikijs/[email protected])([email protected]([email protected]))([email protected])
'@react-native-ai/apple':
specifier: 0.12.0
version: 0.12.0(patch_hash=2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d)([email protected](@babel/[email protected])(@react-native/[email protected](@babel/[email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected]))
@@ -783,7 +783,7 @@ importers:
version: 1.8.0
'@pierre/diffs':
specifier: 'catalog:'
version: 1.5.2(patch_hash=b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0)(@shikijs/[email protected])([email protected]([email protected]))([email protected])
version: 1.5.2(patch_hash=298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7)(@shikijs/[email protected])([email protected]([email protected]))([email protected])
'@pierre/trees':
specifier: 1.0.0-beta.6
version: 1.0.0-beta.6(@pierre/[email protected])(@shikijs/[email protected])([email protected]([email protected]))([email protected])([email protected])
@@ -15726,7 +15726,7 @@ snapshots:
tslib: 2.8.1
webcrypto-core: 1.9.2
'@pierre/[email protected](patch_hash=b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0)(@shikijs/[email protected])([email protected]([email protected]))([email protected])':
'@pierre/[email protected](patch_hash=298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7)(@shikijs/[email protected])([email protected]([email protected]))([email protected])':
dependencies:
'@pierre/theme': 2.0.0
'@pierre/theming': 1.0.1(@pierre/[email protected])(@shikijs/[email protected])([email protected]([email protected]))([email protected])([email protected])
@@ -15741,7 +15741,7 @@ snapshots:
transitivePeerDependencies:
- '@shikijs/themes'
'@pierre/[email protected](patch_hash=b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0)(@shikijs/[email protected])([email protected]([email protected]))([email protected])':
'@pierre/[email protected](patch_hash=298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7)(@shikijs/[email protected])([email protected]([email protected]))([email protected])':
dependencies:
'@pierre/theme': 2.0.0
'@pierre/theming': 1.0.1(@pierre/[email protected])(@shikijs/[email protected])([email protected]([email protected]))([email protected])([email protected])