fix(web): honor whitespace settings in pull request diffs (#12438)
Co-authored-by: shivam <[email protected]>
This commit is contained in:
1 parent
7445aa733a
commit
4a560b4e4e
3 files changed
+230
-15
No files matched your search
@@ -20,6 +20,7 @@ import {
|
||||
InfoIcon,
|
||||
MessageSquareIcon,
|
||||
MessageSquareOffIcon,
|
||||
PilcrowIcon,
|
||||
Rows3Icon,
|
||||
TextWrapIcon,
|
||||
TriangleAlertIcon,
|
||||
@@ -233,6 +234,7 @@ function PullRequestCodeTab({
|
||||
const diffLayout = settings.diffLayout;
|
||||
const updateClientSettings = useUpdateClientSettings();
|
||||
const [wordWrap, setWordWrap] = useState(settings.wordWrap);
|
||||
const [ignoreWhitespace, setIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
|
||||
const [fileTreeOpen, setFileTreeOpen] = useLocalStorage(
|
||||
PULL_REQUEST_FILE_TREE_STORAGE_KEY,
|
||||
false,
|
||||
@@ -390,16 +392,17 @@ function PullRequestCodeTab({
|
||||
loadedSlices.map((slice) => {
|
||||
// The patch's own hash is part of the key: a refreshed page reuses its cursor, and a
|
||||
// key of position alone would keep handing back the parse of the patch it replaced.
|
||||
const cacheKey = `pull-request:${scopeKey}:${resolvedTheme}:${slice.cursor ?? "first"}:${fnv1a32(slice.patch)}`;
|
||||
const cacheKey = `pull-request:${scopeKey}:${resolvedTheme}:${ignoreWhitespace}:${slice.cursor ?? "first"}:${fnv1a32(slice.patch)}`;
|
||||
const cached = parseCache.current.get(cacheKey);
|
||||
if (cached) return cached;
|
||||
const parsed = getRenderablePatch(slice.patch, cacheKey, {
|
||||
compactPartialHunkOffsets: true,
|
||||
ignoreWhitespace,
|
||||
});
|
||||
if (parsed) parseCache.current.set(cacheKey, parsed);
|
||||
return parsed;
|
||||
}),
|
||||
[loadedSlices, resolvedTheme, scopeKey],
|
||||
[loadedSlices, resolvedTheme, scopeKey, ignoreWhitespace],
|
||||
);
|
||||
// Ordered within a slice rather than across them: ordering the accumulated set would let a late
|
||||
// slice push a file the reader is part way through further down the page.
|
||||
@@ -702,7 +705,13 @@ function PullRequestCodeTab({
|
||||
// that silently lost its first line on the other hosts would be worse than one line.
|
||||
const path = resolveFileDiffPath(file);
|
||||
const previousPath = resolveFileDiffPreviousPath(file);
|
||||
const position = resolveDiffReviewPosition(file, range.end, range.endSide ?? range.side);
|
||||
const sourceFile = parsedSlices
|
||||
.flatMap((slice) => (slice?.kind === "files" ? slice.sourceFiles : []))
|
||||
.find((candidate) => resolveFileDiffPath(candidate) === path);
|
||||
const side = range.endSide ?? range.side;
|
||||
const position =
|
||||
(sourceFile && resolveDiffReviewPosition(sourceFile, range.end, side)) ??
|
||||
resolveDiffReviewPosition(file, range.end, side);
|
||||
if (position === null) return;
|
||||
setDraft({
|
||||
fileKey: item.id,
|
||||
@@ -712,7 +721,7 @@ function PullRequestCodeTab({
|
||||
range,
|
||||
});
|
||||
},
|
||||
[canCommentOnLines, files],
|
||||
[canCommentOnLines, files, parsedSlices],
|
||||
);
|
||||
|
||||
// Built here because the parsed diff only lives here, and built by the same function the
|
||||
@@ -1123,11 +1132,6 @@ function PullRequestCodeTab({
|
||||
}
|
||||
}, [commit, onSelectedCommitChange, selectedCommit]);
|
||||
const scopeLabel = selectedCommit ? selectedCommit.messageHeadline : "All commits";
|
||||
/**
|
||||
* The same controls the thread diff panel carries, in the same order, minus the
|
||||
* ignore-whitespace toggle: that is `git diff -w` on the server, and no host's pull request
|
||||
* diff API offers it.
|
||||
*/
|
||||
const toolbar = (
|
||||
<div className="flex h-10 min-h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 bg-background px-4 text-xs text-muted-foreground">
|
||||
<div className="flex min-w-0 flex-1 items-center gap-3">
|
||||
@@ -1276,6 +1280,30 @@ function PullRequestCodeTab({
|
||||
</PullRequestMetaLine>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Toggle
|
||||
aria-label={
|
||||
ignoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"
|
||||
}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
pressed={ignoreWhitespace}
|
||||
onPressedChange={(pressed) => {
|
||||
setIgnoreWhitespace(Boolean(pressed));
|
||||
setDraft(null);
|
||||
setSelectedLines(null);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PilcrowIcon className="size-3.5" />
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">
|
||||
{ignoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
{fileKeys.length > 0 ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
|
||||
Reference in new issue
Block a user