From bfa1238a1cdc169dd38bb31ab4f5d879779cfdeb Mon Sep 17 00:00:00 2001 From: andrewwallacespeckle Date: Tue, 12 Aug 2025 13:52:33 +0100 Subject: [PATCH] fix(fe): new comment button doesn't disappear on external selection --- .../lib/viewer/composables/commentBubbles.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/frontend-2/lib/viewer/composables/commentBubbles.ts b/packages/frontend-2/lib/viewer/composables/commentBubbles.ts index ed61008d7..2d131d722 100644 --- a/packages/frontend-2/lib/viewer/composables/commentBubbles.ts +++ b/packages/frontend-2/lib/viewer/composables/commentBubbles.ts @@ -61,7 +61,8 @@ export function useViewerNewThreadBubble(params: { openThread: { newThreadEditor } }, camera: { target }, - selection + selection, + filters: { selectedObjects } } = useInjectedViewerInterfaceState() const getCamCenterObjId = useGetScreenCenterObjectId() const { setSelectionFromObjectIds } = useSelectionUtilities() @@ -95,6 +96,9 @@ export function useViewerNewThreadBubble(params: { buttonState.value.clickLocation = null } + // Flag to skip the next selection change (from viewer click) + const skipNextSelectionWatch = ref(false) + useSelectionEvents({ singleClickCallback: (_event, { firstVisibleSelectionHit }) => { if (block?.value) return @@ -105,6 +109,7 @@ export function useViewerNewThreadBubble(params: { return } + skipNextSelectionWatch.value = true buttonState.value.clickLocation = firstVisibleSelectionHit.point.clone() buttonState.value.isVisible = true updatePositions() @@ -155,6 +160,18 @@ export function useViewerNewThreadBubble(params: { } }) + // Clear button when selection changes (external sources like models panel) + watch(selectedObjects, () => { + if (skipNextSelectionWatch.value) { + skipNextSelectionWatch.value = false + return + } + + if (buttonState.value.isVisible) { + closeNewThread() + } + }) + return { buttonState, closeNewThread } }