From: Alexander Ebert Date: Mon, 7 Dec 2020 16:27:54 +0000 (+0100) Subject: Force a whitespace before and after inserted smileys X-Git-Tag: 5.3.2~55 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9444045723fb21807b3ad05cd70058f7a9d58308;p=GitHub%2FWoltLab%2FWCF.git Force a whitespace before and after inserted smileys --- 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();