Add option to copy PR URL to clipboard

This commit is contained in:
Caleb Owens 2024-02-19 23:05:40 +00:00 committed by Mattias Granlund
parent 8b35614188
commit a247f08802
3 changed files with 51 additions and 0 deletions

View File

@ -1,7 +1,9 @@
<script lang="ts">
import Tag from '$lib/components/Tag.svelte';
import ViewPrContextMenu from '$lib/components/ViewPrContextMenu.svelte';
import { normalizeBranchName } from '$lib/utils/branch';
import { open } from '@tauri-apps/api/shell';
import { onDestroy } from 'svelte';
import type { Persisted } from '$lib/persisted/persisted';
import type { BaseBranch, Branch } from '$lib/vbranches/types';
@ -11,6 +13,22 @@
export let isUnapplied = false;
export let hasIntegratedCommits = false;
export let isLaneCollapsed: Persisted<boolean>;
function updateContextMenu() {
if (popupMenu) popupMenu.$destroy();
return new ViewPrContextMenu({
target: document.body,
props: { prUrl: prUrl || '' }
});
}
$: popupMenu = updateContextMenu();
onDestroy(() => {
if (popupMenu) {
popupMenu.$destroy();
}
});
</script>
{#if !branch.upstream}
@ -86,6 +104,10 @@
e.preventDefault();
e.stopPropagation();
}}
on:contextmenu={(e) => {
e.preventDefault();
popupMenu.openByMouse(e, undefined);
}}
>
View PR
</Tag>

View File

@ -45,6 +45,7 @@
class:verticalOrientation
class:not-button={!clickable}
on:click
on:contextmenu
role={clickable ? 'button' : undefined}
class:clickable
use:tooltip={help}

View File

@ -0,0 +1,28 @@
<script lang="ts">
import PopupMenu from '$lib/components/PopupMenu.svelte';
import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte';
import ContextMenuItem from '$lib/components/contextmenu/ContextMenuItem.svelte';
import ContextMenuSection from '$lib/components/contextmenu/ContextMenuSection.svelte';
import { copyToClipboard } from '$lib/utils/clipboard';
export let prUrl: string;
let popupMenu: PopupMenu;
export function openByMouse(e: MouseEvent, item: any) {
popupMenu.openByMouse(e, item);
}
</script>
<PopupMenu bind:this={popupMenu} let:dismiss>
<ContextMenu>
<ContextMenuSection>
<ContextMenuItem
label="Copy to Clipbaord"
on:click={() => {
copyToClipboard(prUrl);
dismiss();
}}
/>
</ContextMenuSection>
</ContextMenu>
</PopupMenu>