feat(diff): enable line-level patch selection and actions

Introduces granular control over diff operations by enabling users to select individual lines within a hunk. This refactors the core logic across multiple components, allowing for precise staging, unstaging, or discarding of specific changes rather than operating on entire hunks. The UI now features dedicated controls and visual feedback for line-level selection.

- Refactored patch parsing to track selected line IDs and calculate range information.
- Updated the diff view CSS and component structure to display interactive line selection bars.
- Extended action dialogs to support confirming operations on selected lines.
This commit is contained in:
Christoph Brandau
2026-07-26 22:10:33 +02:00
parent 38b7f1a536
commit 24201c1302
5 changed files with 350 additions and 70 deletions
@@ -5,7 +5,7 @@
interface Props {
files: GitFileStatus[];
staged: boolean | null;
scope: "file" | "hunk";
scope: "file" | "hunk" | "lines";
isBusy: boolean;
onConfirm: () => void | Promise<void>;
onClose: () => void;
@@ -26,9 +26,9 @@
let count = $derived(files.length);
let title = $derived(
scope === "hunk" ? "Discard hunk?" : count > 1 ? `Discard changes in ${count} files?` : "Discard file changes?"
scope === "hunk" ? "Discard hunk?" : scope === "lines" ? "Discard selected lines?" : count > 1 ? `Discard changes in ${count} files?` : "Discard file changes?"
);
let scopeLabel = $derived(scope === "hunk" ? "selected hunk" : count > 1 ? `${count} files` : "file");
let scopeLabel = $derived(scope === "hunk" ? "selected hunk" : scope === "lines" ? "selected lines" : count > 1 ? `${count} files` : "file");
let sourceLabel = $derived(staged === null ? "staged and unstaged changes" : staged ? "staged changes" : "unstaged changes");
</script>