From c038772ed2ea497e8b6f8849833724b0f57ce8f8 Mon Sep 17 00:00:00 2001 From: Sibiraj <20282546+sibiraj-s@users.noreply.github.com> Date: Sun, 12 May 2024 17:43:12 +0530 Subject: [PATCH] fix: unset link only when removed --- projects/ngx-editor/commands/removeLink.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/projects/ngx-editor/commands/removeLink.ts b/projects/ngx-editor/commands/removeLink.ts index cfbe46ac..bca295df 100644 --- a/projects/ngx-editor/commands/removeLink.ts +++ b/projects/ngx-editor/commands/removeLink.ts @@ -2,18 +2,20 @@ import { EditorState, Transaction, type Command } from 'prosemirror-state'; export const removeLink = (): Command => { return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => { - const { doc, selection, tr } = state; + const { doc, selection, tr, schema } = state; const { $head: { pos }, from, to } = selection; + const linkMark = schema.marks['link']; + // if the cursor is on the link without any selection if (from === to) { const $pos = doc.resolve(pos); const linkStart = pos - $pos.textOffset; const linkEnd = linkStart + $pos.parent.child($pos.index()).nodeSize; - tr.removeMark(linkStart, linkEnd); + tr.removeMark(linkStart, linkEnd, linkMark); } else { - tr.removeMark(from, to); + tr.removeMark(from, to, linkMark); } if (!tr.docChanged) {