From 9444045723fb21807b3ad05cd70058f7a9d58308 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 7 Dec 2020 17:27:54 +0100 Subject: [PATCH] Force a whitespace before and after inserted smileys --- .../3rdParty/redactor2/plugins/WoltLabSmiley.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js index 62a6815fb7..08d505c265 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js @@ -29,11 +29,22 @@ $.Redactor.prototype.WoltLabSmiley = function() { smiley = elById(id); smiley.removeAttribute('id'); - // Safari does not properly update the caret position on insert - this.caret.after(smiley); + smiley.parentNode.insertBefore(document.createTextNode(" "), smiley); + const whitespace = document.createTextNode(" "); + smiley.parentNode.insertBefore(whitespace, smiley.nextSibling); + + // Replace the image with itself to forcefully invalidate any references. //noinspection SillyAssignmentJS smiley.outerHTML = smiley.outerHTML; + + const selection = window.getSelection(); + const range = document.createRange(); + range.selectNode(whitespace); + range.collapse(false); + + selection.removeAllRanges(); + selection.addRange(range); // force-save the caret position this.WoltLabCaret.forceSelectionSave(); -- 2.20.1