From c09b1e485b074e7f14e1ef186c439e77a7374bb4 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Fri, 4 Jul 2025 11:28:51 +0200 Subject: [PATCH] fix: Fix an issue where the link context menu wasn't opened anymore. --- src/extensions/link.js | 2 +- src/tiptap.test.js | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/extensions/link.js b/src/extensions/link.js index 68fd443..daef7ce 100644 --- a/src/extensions/link.js +++ b/src/extensions/link.js @@ -254,7 +254,7 @@ export function init({ app, button }) { app.editor.isActive("link") ? button.classList.add("active") : button.classList.remove("active"); - app.editor.can().setLink() + app.editor.can().setLink({}) ? button.classList.remove("disabled") : button.classList.add("disabled"); diff --git a/src/tiptap.test.js b/src/tiptap.test.js index 84ad0a8..654606e 100644 --- a/src/tiptap.test.js +++ b/src/tiptap.test.js @@ -396,6 +396,7 @@ describe("pat-tiptap", () => { data-pat-tiptap=" toolbar-external: #tiptap-external-toolbar; link-panel: #link-panel; + link-menu: #context-menu-link; link-extra-protocols: fantasy; "> @@ -409,6 +410,20 @@ describe("pat-tiptap", () => { class="close-panel">submit + `; const pattern = new Pattern(document.querySelector(".pat-tiptap")); await events.await_pattern_init(pattern); @@ -506,6 +521,52 @@ describe("pat-tiptap", () => { expect(anchor.href).toBe("fantasy://patternslib.com"); expect(anchor.textContent).toBe("Link text"); }); + + it("5.8 - Opens a link context menu", async () => { + // Add a link to test the context menu on. + document.querySelector("#link-panel [name=tiptap-href]").value = "https://patternslib.com"; // prettier-ignore + document.querySelector("#link-panel [name=tiptap-text]").value = "Link text"; // prettier-ignore + document.querySelector("#link-panel [name=tiptap-confirm]").dispatchEvent(new Event("click")); // prettier-ignore + await utils.timeout(1); + + const editable = document.querySelector( + ".tiptap-container [contenteditable]", + ); + const range = document.createRange(); + const sel = window.getSelection(); + + // Add the triggering character into the content editable + editable.innerHTML = "

@

"; + + // Set the cursor right after the @-sign. + range.setStart(editable.childNodes[0].childNodes[0], 1); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + // Wait some ticks. + await utils.timeout(1); + await utils.timeout(1); + + // Context menu not yet opened. + expect(document.querySelector(".tiptap-link-context-menu")).toBeFalsy(); + + // Context menu opens with a 50ms delay. + await utils.timeout(50); + + // Context menu should be opened now. + expect(document.querySelector(".tiptap-link-context-menu")).toBeTruthy(); + + // Wait two more ticks for the context menu to be fully initialized. + await utils.timeout(1); + await utils.timeout(1); + + // UI elements should be initialized now. + expect( + document.querySelector(".tiptap-link-context-menu .tiptap-open-new-link") + .href, + ).toBe("https://patternslib.com/"); + }); }); it("6.1 - Adds an image within
tags including a
", async () => {