Skip to content

Build your personal knowledge base with Trilium Notes

fix(calendar): keep the hover preview out of the popover's way

Elian Doranb2279dcfa4fe
diff --git a/apps/client/src/services/note_tooltip.spec.ts b/apps/client/src/services/note_tooltip.spec.ts
index cadfe5e506..9eee07fbee 100644
--- a/apps/client/src/services/note_tooltip.spec.ts
+++ b/apps/client/src/services/note_tooltip.spec.ts
@@ -365,6 +365,25 @@ describe("mouseEnterHandler", () => {
expect($.fn.tooltip as unknown as ReturnType<typeof vi.fn>).not.toHaveBeenCalled();
});
+ it("shows nothing for a link that takes the opt-out while its preview is in flight", async () => {
+ vi.useFakeTimers();
+ const $link = makeLink('<a data-href="#root/abc">x</a>');
+ parseNavigationStateFromUrl.mockReturnValue({ notePath: "root/abc", noteId: "abc", viewScope: { viewMode: "default" } });
+ froca.getNote = vi.fn(async () => fakeNote({ noteId: "abc", bestPath: "root/abc" })) as unknown as typeof froca.getNote;
+ hoverActive = true;
+
+ // The pointer stays on the link throughout — a calendar chip keeps it after the click that
+ // opens the popover — so the hover test alone cannot hold the preview back. Only the
+ // opt-out, taken on while the preview was being fetched, says it is no longer wanted.
+ const promise = mouseEnterHandler.call($link[0], eventFor($link));
+ $link.addClass("no-tooltip-preview");
+ await vi.advanceTimersByTimeAsync(600);
+ await promise;
+
+ expect(parseNavigationStateFromUrl).toHaveBeenCalled();
+ expect($.fn.tooltip as unknown as ReturnType<typeof vi.fn>).not.toHaveBeenCalled();
+ });
+
it("short-circuits when a tooltip for this link is already visible", async () => {
const $link = makeLink('<a data-link-id="existing" href="#root/abc">x</a>');
parseNavigationStateFromUrl.mockReturnValue({ notePath: "root/abc", noteId: "abc", viewScope: { viewMode: "default" } });
diff --git a/apps/client/src/services/note_tooltip.ts b/apps/client/src/services/note_tooltip.ts
index 2c1bca0fc4..0ced0d770a 100644
--- a/apps/client/src/services/note_tooltip.ts
+++ b/apps/client/src/services/note_tooltip.ts
@@ -130,7 +130,13 @@ export async function mouseEnterHandler<T>(this: HTMLElement, e: JQuery.Triggere
// since the operation to get tooltip content was async, it is possible that
// we now create tooltip which won't close because it won't receive mouseleave event
// — or that a context menu was invoked in the meantime, which the preview must not cover.
- if ($link.filter(":hover").length > 0 && !isContextMenuShown()) {
+ //
+ // The opt-out is re-read for the same reason: an element may take it on while its preview is
+ // being fetched, which is how a surface that opens over the pointer says the preview is no
+ // longer wanted — a calendar chip clicked gains it as the popover opens (see the class in
+ // CalendarView's eventClassNames), and the pointer is still on the chip, so the hover test
+ // alone would let the preview land on top of what the click just opened.
+ if ($link.filter(":hover").length > 0 && !isContextMenuShown() && !$link.hasClass("no-tooltip-preview")) {
$link.tooltip({
container: "body",
// https://github.com/zadam/trilium/issues/2794 https://github.com/zadam/trilium/issues/2988
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 8db6c969bf..0a2cbec4c2 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -13,6 +13,7 @@ import date_notes from "../../../services/date_notes";
import dialog from "../../../services/dialog";
import froca from "../../../services/froca";
import { t } from "../../../services/i18n";
+import note_tooltip from "../../../services/note_tooltip";
import { escapeHtml, isMobile } from "../../../services/utils";
import CollectionProperties from "../../note_bars/CollectionProperties";
import ActionButton from "../../react/ActionButton";
@@ -192,6 +193,13 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
// FullCalendar makes of the click — so the click must not reach the document at all.
e.jsEvent.preventDefault();
e.jsEvent.stopPropagation();
+
+ // Which also keeps the click from the tooltip service, whose own document listener is what
+ // ordinarily puts a preview away when something is done (see note_tooltip.ts). Said here
+ // instead: a preview left standing would cover the very popover the click opens, at the
+ // chip both of them are drawn beside.
+ note_tooltip.dismissAllTooltips();
+
const noteId = e.event.extendedProps.noteId;
if (noteId) {
// The click names which of the event's chips to stand by (see eventAnchorRect).
@@ -247,7 +255,14 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
{...editingProps}
unselectAuto={false}
eventClick={onEventClick}
- eventClassNames={(arg) => selection && "noteId" in selection && arg.event.extendedProps.noteId === selection.noteId ? [ "calendar-event-selected" ] : []}
+ // The event the popover stands for is marked as such, and asks for no hover
+ // preview while it does: the popover beside it already says everything the
+ // preview would, at full length and editable, and the two are drawn beside the
+ // same chip. The geo map's marker previews keep clear of its detail pane the same
+ // way (see Tooltips there).
+ eventClassNames={(arg) => selection && "noteId" in selection && arg.event.extendedProps.noteId === selection.noteId
+ ? [ "calendar-event-selected", "no-tooltip-preview" ]
+ : []}
eventDidMount={eventDidMount}
viewDidMount={({ view }) => {
if (initialView.current !== view.type) {