Skip to content

Commit

Permalink
fix: removing delete jump to link
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvente committed Apr 2, 2024
1 parent a8c88b5 commit b11bf08
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/editors/sharedComponents/InsertLinkModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const InsertLinkModal = ({
const editor = editorRef.current;
const urlPath = blockSelected?.lmsWebUrl || inputUrlValue;
const blockId = blockSelected?.blockId;
const linkRegex = /<a\b[^>]*><\/a>/gi;
if (editor && urlPath) {
const validateUrl = isValidURL(urlPath);

Expand All @@ -78,12 +79,20 @@ const InsertLinkModal = ({
selectedRange.insertNode(newLinkNode);
// Remove empty "a" tags after replacing URLs
const editorContent = editor.getContent();
const modifiedContent = editorContent.replace(/<a\b[^>]*><\/a>/gi, '');
const modifiedContent = editorContent.replace(linkRegex, '');
editor.setContent(modifiedContent);

dispatch(actions.addBlock({ [blockId]: blockSelected }));
}

if (editor && !blockId) {
// eslint-disable-next-line react/prop-types
editor.execCommand('unlink');
const editorContent = editor.getContent();
const modifiedContent = editorContent.replace(linkRegex, '');
editor.setContent(modifiedContent);
}

onClose();
};

Expand Down

0 comments on commit b11bf08

Please sign in to comment.