Skip to content

Commit

Permalink
Improve popup hiding to fix dangling open popups in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hlxid committed Mar 2, 2024
1 parent 20f8794 commit 7e151fd
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/features/dfdElements/nodeAnnotationUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,23 @@ export class DfdNodeAnnotationUI extends AbstractUIExtension {
containerElement.classList.add("ui-float");
containerElement.appendChild(this.annotationParagraph);

containerElement.addEventListener("mouseleave", () => {
this.hide();
document.addEventListener("mousemove", (event) => {
if (containerElement.style.visibility === "hidden") {
// Not visible anyway, no need to do the check
return;
}

// If mouse not in popup => hide
const rect = containerElement.getBoundingClientRect();
console.log(rect);
if (
event.clientX < rect.left ||
event.clientX > rect.right ||
event.clientY < rect.top ||
event.clientY > rect.bottom
) {
this.hide();
}
});
}

Expand All @@ -140,14 +155,17 @@ export class DfdNodeAnnotationUI extends AbstractUIExtension {
// Clear previous content
this.annotationParagraph.innerHTML = "";

// Set position
// 2 offset to ensure the mouse is inside the popup when showing it.
// Otherwise it would be on the node instead of the popup because of the rounded corners.
// The cursor should be inside the popup when opening it for the closing
// using the mouseleave event to work correctly.
// When moving the cursor from the node to the popup, the popup would move a bit
// because the cursor is going a bit over the model and then the popup would re-show
// with the new position after the timeout.
const mousePosition = this.mouseListener.getMousePosition();
containerElement.style.left = `${mousePosition.x - 2}px`;
containerElement.style.top = `${mousePosition.y - 2}px`;

// Set content
if (!node.annotation) {
this.annotationParagraph.innerText = "No errors";
return;
Expand Down

0 comments on commit 7e151fd

Please sign in to comment.