Repository: go-gitea/gitea
File: web_src/js/modules/tippy.ts (TypeScript)

Code before:
  if (popupTippyId) {
    // for example, the "Copy Permalink" button in the "File View" page for the selected lines
    target = document.body;
    refClientRect = document.querySelector(`[aria-controls="${CSS.escape(popupTippyId)}"]`)?.getBoundingClientRect();
    refClientRect = refClientRect ?? new DOMRect(0, 0, 0, 0); // fallback to empty rect if not found, tippy doesn't accept null
  } else {
    // for example, the "Copy Link" button in the issue header dropdown menu
    target = target.closest('.ui.dropdown') ?? target;
    refClientRect = target.getBoundingClientRect();
    useHideTimeout = true;
  }
  const tooltipTippy = target._tippy ?? attachTooltip(target, content);
  tooltipTippy.setContent(content);
  tooltipTippy.setProps({getReferenceClientRect: () => refClientRect});
  if (!tooltipTippy.state.isShown) tooltipTippy.show();

  tooltipTippy.setProps({
    onHidden: (tippy) => {
      // reset the default tooltip content, if no default, then this temporary tooltip could be destroyed
      if (!attachTooltip(target)) {
        tippy.destroy();
      }
    },
  });

  // on elements where the tooltip is re-loacted like "Copy Link" inside fomantic dropdowns, tippy.js gets
  // no mouseOut event so we have to hide the tooltip manually.
  if (useHideTimeout) {
    setTimeout(() => {
      if (tooltipTippy.state.isVisible) tooltipTippy.hide();
    }, 1500);
  }
}

export function getAttachedTippyInstance(el: Element): Instance | null {
  return el._tippy ?? null;
}


Review comment (suggestion):
```suggestion
  // on elements where the tooltip is re-locacted like "Copy Link" inside fomantic dropdowns, tippy.js gets
```

Code after:
    // for example, the "Copy Permalink" button in the "File View" page for the selected lines
    target = document.body;
    refClientRect = document.querySelector(`[aria-controls="${CSS.escape(popupTippyId)}"]`)?.getBoundingClientRect();
    refClientRect = refClientRect ?? new DOMRect(0, 0, 0, 0); // fallback to empty rect if not found, tippy doesn't accept null
  } else {
    // for example, the "Copy Link" button in the issue header dropdown menu
    target = target.closest('.ui.dropdown') ?? target;
    refClientRect = target.getBoundingClientRect();
  }
  const tooltipTippy = target._tippy ?? attachTooltip(target, content);
  tooltipTippy.setContent(content);
  tooltipTippy.setProps({getReferenceClientRect: () => refClientRect});
  if (!tooltipTippy.state.isShown) tooltipTippy.show();

  tooltipTippy.setProps({
    onHidden: (tippy) => {
      // reset the default tooltip content, if no default, then this temporary tooltip could be destroyed
      if (!attachTooltip(target)) {
        tippy.destroy();
      }
    },
  });

  // on elements where the tooltip is re-located like "Copy Link" inside fomantic dropdowns, tippy.js gets
  // no `mouseout` event and the tooltip stays visible, hide it with timeout.
  if (!popupTippyId) {
    setTimeout(() => {
      if (tooltipTippy.state.isVisible) tooltipTippy.hide();
    }, 1500);
  }
}

export function getAttachedTippyInstance(el: Element): Instance | null {
  return el._tippy ?? null;
}