Skip to content
Open
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
19 changes: 18 additions & 1 deletion web/src/routes/FileHeader.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import DiffStats from "$lib/components/diff/DiffStats.svelte";
import LabeledCheckbox from "$lib/components/LabeledCheckbox.svelte";
import { type FileDetails, GlobalOptions, MultiFileDiffViewerState } from "$lib/diff-viewer-multi-file.svelte";
import { type FileDetails, type GithubDiffMetadata, GlobalOptions, MultiFileDiffViewerState } from "$lib/diff-viewer-multi-file.svelte";
import { Popover, Button } from "bits-ui";
import { tick } from "svelte";

Expand All @@ -15,6 +15,7 @@
let { index, value }: Props = $props();

let popoverOpen = $state(false);
let isGithubDiff = viewer.diffMetadata?.type === "github";

async function showInFileTree() {
const fileTreeElement = document.getElementById("file-tree-file-" + index);
Expand All @@ -29,6 +30,15 @@
}
}

async function openInGithub() {
if (isGithubDiff) {
popoverOpen = false;
const filePath = value.toFile;
const { owner, repo, head } = (viewer.diffMetadata as GithubDiffMetadata).details;
window.open(`https://github.com/${owner}/${repo}/blob/${head}/${filePath}`, "_blank");
}
}

let patchHeaderDiffOnly = $derived(value.type === "text" && value.patchHeaderDiffOnly);
</script>

Expand Down Expand Up @@ -84,6 +94,13 @@
}
}
/>
<Button.Root
onclick={openInGithub}
disabled={!isGithubDiff}
class="disabled:btn-disabled px-2 py-1 not-disabled:btn-ghost disabled:text-gray-500"
>
Open in GitHub
</Button.Root>
<Popover.Arrow class="text-edge" />
</Popover.Content>
</Popover.Portal>
Expand Down