"+o+"")).setAttribute("href",t),e=r.insertContentAtFocusPoint(i.get("outerHTML")),r.setSelection(r.getSelectionFromNode(e));if(e)return t=this._findSelectedAnchors(u.one(e)),u.Array.each(t,function(t){this._content.one(h).get("checked")?t.setAttribute("target","_blank"):t.removeAttribute("target"),n&&o&&(this._hasPlainTextSelected?t.set("innerText",o):t.setAttribute("title",o))},this),e},_findSelectedAnchors:function(t){var e,n,i=t.get("tagName");return i&&"a"===i.toLowerCase()?[t]:(n=[],t.all("a").each(function(t){!e&&this.get("host").selectionContainsNode(t)&&n.push(t)},this),0{{#if showFilepicker}}
{{else}}{{/if}}
');return this._content=u.Node.create(e({showFilepicker:t,component:n,CSS:i})),this._content.one(o).on("keyup",this._updateTextToDisplay,this),this._content.one(o).on("change",this._updateTextToDisplay,this),this._content.one(d).on("keyup",this._setTextToDisplayState,this),this._content.one(l).on("click",this._setLink,this),t&&this._content.one(s).on("click",function(t){t.preventDefault(),this.get("host").showFilepicker("link",this._filepickerCallback,this)},this),this._content},_unlink:function(){var e=this.get("host"),t=e.getSelection();t&&t.length&&(t[0].startOffset===t[0].endOffset?(t=e.getSelectedNodes())&&(t.each(function(t){t=t.ancestor("a",!0);t&&(e.setSelection(e.getSelectionFromNode(t)),document.execCommand("unlink",!1,null))},this),this.markUpdated()):(document.execCommand("unlink",!1,null),this.markUpdated()))},_setTextToDisplayState:function(){var t=this._content.one(d).get("value");this._hasTextToDisplay=""!==t},_updateTextToDisplay:function(){
+var t=this._content.one(o),e=this._content.one(d),t=t.get("value");this._hasTextToDisplay||e.set("value",t)},_getTextSelection:function(){var t,e,n="",i=window.getSelection(),o=i.rangeCount;if(o){for(t=[],e=0;e 0) {
+ // For Firefox / Gecko we need to wrap the selection in a span so we can surround it with an anchor.
+ // This relates to https://bugzilla.mozilla.org/show_bug.cgi?id=1906559.
+ var originalSelection = document.getSelection();
+ var wrapper = document.createElement('span');
+ wrapper.setAttribute('data-wrapper', '');
+ wrapper.style.display = 'inline';
+
+ var i;
+ for (i = 0; i < originalSelection.rangeCount; i++) {
+ originalSelection.getRangeAt(i).surroundContents(wrapper);
+ }
+ host.setSelection(host.getSelectionFromNode(Y.one(wrapper)));
+
+ document.execCommand('unlink', false, null);
+ document.execCommand('createLink', false, url);
+
+ var anchorNode = wrapper.parentNode;
+ wrapper.children.forEach(function(child) {
+ anchorNode.appendChild(child);
+ });
+ wrapper.remove();
+
+ } else {
+ document.execCommand('unlink', false, null);
+ document.execCommand('createLink', false, url);
+ }
// Now set the target.
selectednode = host.getSelectionParentNode();
diff --git a/lib/editor/atto/plugins/link/yui/src/button/js/button.js b/lib/editor/atto/plugins/link/yui/src/button/js/button.js
index db182c031b7..5ad77e94758 100644
--- a/lib/editor/atto/plugins/link/yui/src/button/js/button.js
+++ b/lib/editor/atto/plugins/link/yui/src/button/js/button.js
@@ -315,8 +315,33 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
selectednode = host.insertContentAtFocusPoint(link.get('outerHTML'));
host.setSelection(host.getSelectionFromNode(selectednode));
} else {
- document.execCommand('unlink', false, null);
- document.execCommand('createLink', false, url);
+ if (Y.UA.gecko > 0) {
+ // For Firefox / Gecko we need to wrap the selection in a span so we can surround it with an anchor.
+ // This relates to https://bugzilla.mozilla.org/show_bug.cgi?id=1906559.
+ var originalSelection = document.getSelection();
+ var wrapper = document.createElement('span');
+ wrapper.setAttribute('data-wrapper', '');
+ wrapper.style.display = 'inline';
+
+ var i;
+ for (i = 0; i < originalSelection.rangeCount; i++) {
+ originalSelection.getRangeAt(i).surroundContents(wrapper);
+ }
+ host.setSelection(host.getSelectionFromNode(Y.one(wrapper)));
+
+ document.execCommand('unlink', false, null);
+ document.execCommand('createLink', false, url);
+
+ var anchorNode = wrapper.parentNode;
+ wrapper.children.forEach(function(child) {
+ anchorNode.appendChild(child);
+ });
+ wrapper.remove();
+
+ } else {
+ document.execCommand('unlink', false, null);
+ document.execCommand('createLink', false, url);
+ }
// Now set the target.
selectednode = host.getSelectionParentNode();