From e7990b41ba43c1936bd60af8267118d0b3dc8efc Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Mon, 11 Dec 2023 00:50:54 +0100 Subject: [PATCH] Fix bug in hunk context menu - it wasn't always referring to the right file --- .../[projectId]/components/FileCard.svelte | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/routes/[projectId]/components/FileCard.svelte b/packages/ui/src/routes/[projectId]/components/FileCard.svelte index 1db16eca0..f8bf5b04b 100644 --- a/packages/ui/src/routes/[projectId]/components/FileCard.svelte +++ b/packages/ui/src/routes/[projectId]/components/FileCard.svelte @@ -39,10 +39,15 @@ const userSettings = getContext(SETTINGS_CONTEXT); - const popupMenu = new HunkContextMenu({ - target: document.body, - props: { projectPath, file, branchController } - }); + function updateContextMenu(file: File) { + if (popupMenu) popupMenu.$destroy(); + return new HunkContextMenu({ + target: document.body, + props: { projectPath, file, branchController } + }); + } + + $: popupMenu = updateContextMenu(file); let sections: (HunkSection | ContentSection)[] = []; @@ -78,7 +83,9 @@ } onDestroy(() => { - popupMenu.$destroy(); + if (popupMenu) { + popupMenu.$destroy(); + } }); function computedAddedRemoved(section: HunkSection | ContentSection): {