From dde4901561cb1420a30805adb739d1952c196c35 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 6 Mar 2024 17:57:56 +0100 Subject: [PATCH] fix(preview): hide tooltip for links in preview Signed-off-by: Max --- cypress/e2e/nodes/Preview.spec.js | 4 ++-- src/extensions/LinkBubblePluginView.js | 6 ++++++ src/nodes/Preview.js | 2 -- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cypress/e2e/nodes/Preview.spec.js b/cypress/e2e/nodes/Preview.spec.js index 4ca3101ae78..c701f635c42 100644 --- a/cypress/e2e/nodes/Preview.spec.js +++ b/cypress/e2e/nodes/Preview.spec.js @@ -75,12 +75,12 @@ describe.only('Preview extension', { retries: 0 }, () => { expect(editor.can().setPreview()).to.be.true }) - it('results in a preview node with the href and plain text', () => { + it('results in a preview node with the href and text with link mark', () => { prepareEditor('[link text](https://nextcloud.com)\n') editor.commands.setPreview() expect(getParentNode().type.name).to.equal('preview') expect(getParentNode().attrs.href).to.equal('https://nextcloud.com') - expect(getMark()).to.be.undefined + expect(getMark().attrs.href).to.equal('https://nextcloud.com') }) it('cannot run twice', () => { diff --git a/src/extensions/LinkBubblePluginView.js b/src/extensions/LinkBubblePluginView.js index 6e968713253..3f5d09f53dd 100644 --- a/src/extensions/LinkBubblePluginView.js +++ b/src/extensions/LinkBubblePluginView.js @@ -195,6 +195,12 @@ class LinkBubblePluginView { const to = Math.max(...ranges.map(range => range.$to.pos)) const resolved = view.state.doc.resolve(from) + + // ignore links in previews + if (resolved.parent.type.name === 'preview') { + return false + } + const node = resolved.parent.maybeChild(resolved.index()) const nodeStart = resolved.pos - resolved.textOffset const nodeEnd = nodeStart + node?.nodeSize diff --git a/src/nodes/Preview.js b/src/nodes/Preview.js index e330f7d1922..a11e69dea38 100644 --- a/src/nodes/Preview.js +++ b/src/nodes/Preview.js @@ -87,7 +87,6 @@ export default Node.create({ setPreview: () => ({ state, chain }) => { return previewPossible(state) && chain() - .unsetLink() .setNode(this.name, previewAttributesFromSelection(state)) .run() }, @@ -102,7 +101,6 @@ export default Node.create({ return isPreview(this.name, this.attributes, state) && chain() .setNode('paragraph') - .setLink(this.attributes) .run() },