From 7018481ed20632a89d44c3b7e46f3c1fa7e7270c Mon Sep 17 00:00:00 2001 From: christian-byrne Date: Tue, 24 Dec 2024 19:50:26 -0700 Subject: [PATCH 1/2] Early return link tooltip when links hidden --- src/LGraphCanvas.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index d1aec74..12577bc 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -5055,6 +5055,7 @@ export class LGraphCanvas { * @todo Split tooltip from hover, so it can be drawn / eased separately */ drawLinkTooltip(ctx: CanvasRenderingContext2D, link: LinkSegment): void { + if (this.links_render_mode === LinkRenderType.HIDDEN_LINK) return const pos = link._pos ctx.fillStyle = "black" ctx.beginPath() From 6a6837ffe0827a8396a3895bb41b6977e8e6548d Mon Sep 17 00:00:00 2001 From: christian-byrne Date: Tue, 24 Dec 2024 21:09:34 -0700 Subject: [PATCH 2/2] Add test --- test/LGraphCanvas.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/LGraphCanvas.test.ts diff --git a/test/LGraphCanvas.test.ts b/test/LGraphCanvas.test.ts new file mode 100644 index 0000000..69da807 --- /dev/null +++ b/test/LGraphCanvas.test.ts @@ -0,0 +1,26 @@ +import { lgTest } from "./lgTest" +import { expect, describe, vi } from "vitest" +import { LGraphCanvas } from "@/LGraphCanvas" +import { LinkRenderType } from "@/types/globalEnums" + +describe("Link rendering", () => { + lgTest("should not draw link mouseover effect when links are hidden", () => { + const mockCtx = { + fillText: vi.fn(), + measureText: vi.fn(() => ({ width: 100 })), + } as unknown as CanvasRenderingContext2D + + const mockLink = {} as any + + const mockCanvas: Partial = { + links_render_mode: LinkRenderType.HIDDEN_LINK, + } as LGraphCanvas + + // Directly call the method that draws link mouseover effects and tooltips + const drawLinkTooltip = LGraphCanvas.prototype.drawLinkTooltip + drawLinkTooltip.call(mockCanvas, mockCtx, mockLink) + + // Verify that no text rendering was attempted + expect(mockCtx.fillText).not.toHaveBeenCalled() + }) +})