fix(fe): new comment button doesn't disappear on external selection

This commit is contained in:
andrewwallacespeckle
2025-08-12 13:52:33 +01:00
parent 7a06e8ece4
commit bfa1238a1c
@@ -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 }
}