From 965bdab52311503182148d8f99013d35492e41e1 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 17 Apr 2024 18:08:08 +0200 Subject: [PATCH] refactor(link): use isMarkActive in insertOrSetLink This way we do not hand in the active state and avoid inconsistencies. Signed-off-by: Max --- cypress/e2e/marks/Link.spec.js | 2 +- src/components/Menu/ActionInsertLink.vue | 2 +- src/marks/Link.js | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cypress/e2e/marks/Link.spec.js b/cypress/e2e/marks/Link.spec.js index 98aa1ec66c3..f2ccb7dd2d7 100644 --- a/cypress/e2e/marks/Link.spec.js +++ b/cypress/e2e/marks/Link.spec.js @@ -50,7 +50,7 @@ describe('Link marks', { retries: 0 }, () => { it('will insert a link in a normal paragraph', () => { prepareEditor('hello\n', 3) - editor.commands.insertOrSetLink(false, 'https://nextcloud.com', { href: 'https://nextcloud.com' }) + editor.commands.insertOrSetLink('https://nextcloud.com', { href: 'https://nextcloud.com' }) expectMarkdown(editor, 'he\n\n\n\nllo') }) diff --git a/src/components/Menu/ActionInsertLink.vue b/src/components/Menu/ActionInsertLink.vue index f69008e455d..8c50d815076 100644 --- a/src/components/Menu/ActionInsertLink.vue +++ b/src/components/Menu/ActionInsertLink.vue @@ -189,7 +189,7 @@ export default { // Avoid issues when parsing urls later on in markdown that might be entered in an invalid format (e.g. "mailto: example@example.com") const href = url.replaceAll(' ', '%20') const chain = this.$editor.chain() - chain.insertOrSetLink(this.state.active, text, { href }) + chain.insertOrSetLink(text, { href }) chain.focus().run() }, /** diff --git a/src/marks/Link.js b/src/marks/Link.js index 824b5ac7cc7..c1d25c4876f 100644 --- a/src/marks/Link.js +++ b/src/marks/Link.js @@ -7,6 +7,7 @@ import { markInputRule } from '@tiptap/core' import TipTapLink from '@tiptap/extension-link' import { domHref, parseHref } from './../helpers/links.js' import { linkClicking } from '../plugins/links.js' +import { isMarkActive } from '@tiptap/core' const PROTOCOLS_TO_LINK_TO = ['http:', 'https:', 'mailto:', 'tel:'] @@ -93,11 +94,11 @@ const Link = TipTapLink.extend({ * Insert a link if there currently is none. * */ - insertOrSetLink: (active, text, attrs) => ({ state, chain, commands }) => { + insertOrSetLink: (text, attrs) => ({ state, chain, commands }) => { // Check if any text is selected, // if not insert the link using the given text property if (state.selection.empty) { - if (active) { + if (isMarkActive(state, this.name)) { commands.deleteNode('paragraph') } return chain().insertContent({