Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apps/web/src/components/DiffPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,16 @@ export default function DiffPanel({
workingTreeFilter,
],
);
// The filtered views already say which way a file can go; the unfiltered view asks the
// index, and a partially staged file can go either way.
// A file can be staged while it has edits outside the index and unstaged while it has
// entries in it, so a partially staged file offers both in every view. The filtered views
// imply one direction even before the index state has arrived.
const stagingActionsFor = useCallback(
(filePath: string): ReadonlyArray<"stage" | "unstage"> => {
if (workingTreeFilter !== "all")
return workingTreeFilter === "staged" ? ["unstage"] : ["stage"];
const staging = fileStagingByPath.get(filePath);
if (!staging?.staged) return ["stage"];
return staging.unstaged ? ["stage", "unstage"] : ["unstage"];
const canStage =
workingTreeFilter === "unstaged" || staging === undefined || staging.unstaged;
const canUnstage = workingTreeFilter === "staged" || staging?.staged === true;
return [...(canStage ? ["stage" as const] : []), ...(canUnstage ? ["unstage" as const] : [])];
},
[fileStagingByPath, workingTreeFilter],
);
Expand Down
Loading