From de95ff6d89eb533d2613ab59cb1eac01fe92c91f Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Wed, 21 Aug 2024 16:58:32 +1200 Subject: [PATCH] Fix TinyMCE edit link when link contains html --- client/src/legacy/TinyMCE_sslink.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/legacy/TinyMCE_sslink.js b/client/src/legacy/TinyMCE_sslink.js index 374311cb0..35e55da32 100644 --- a/client/src/legacy/TinyMCE_sslink.js +++ b/client/src/legacy/TinyMCE_sslink.js @@ -35,6 +35,9 @@ const plugin = { // Callback for opening the edit link dialog form function openLinkDialog() { + // Find "a" node (we might have clicked on a child element e.g. "span") + const linkNode = jQuery(tinymce.activeEditor.selection.getNode()).closest('a'); + tinymce.activeEditor.selection.select(linkNode[0]); const node = tinymce.activeEditor.selection.getNode(); const href = node.getAttribute('href'); @@ -192,7 +195,11 @@ jQuery.entwine('ss', ($) => { */ getRequireLinkText() { const editor = this.getElement().getEditor(); - const selection = editor.getInstance().selection; + let selection = editor.getInstance().selection; + const node = $(selection.getNode()).closest('a'); + editor.getInstance().selection.select(node[0]); + + selection = editor.getInstance().selection; const isValidSelection = this.linkCanWrapSelection(editor, selection); const tagName = selection.getNode().tagName; const requireLinkText = tagName !== 'A' && !isValidSelection;