Skip to content

Commit

Permalink
fix(preview): hide tooltip for links in preview
Browse files Browse the repository at this point in the history
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Mar 6, 2024
1 parent 75f5479 commit 1ee3cbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/nodes/Preview.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/extensions/LinkBubblePluginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/nodes/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export default Node.create({
setPreview: () => ({ state, chain }) => {
return previewPossible(state)
&& chain()
.unsetLink()
.setNode(this.name, previewAttributesFromSelection(state))
.run()
},
Expand All @@ -102,7 +101,6 @@ export default Node.create({
return isPreview(this.name, this.attributes, state)
&& chain()
.setNode('paragraph')
.setLink(this.attributes)
.run()
},

Expand Down

0 comments on commit 1ee3cbd

Please sign in to comment.