Workaround for the misaligned caret in Safari caused by 0x200B
authorAlexander Ebert <ebert@woltlab.com>
Mon, 7 Dec 2020 19:02:58 +0000 (20:02 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 7 Dec 2020 19:02:58 +0000 (20:02 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js

index 08d505c26563491af1b8aa37d60a800a7fcf36f9..dd14d4e514fd29e829e2b4ec6df7e41b83897988 100644 (file)
@@ -29,6 +29,13 @@ $.Redactor.prototype.WoltLabSmiley = function() {
                        smiley = elById(id);
                        smiley.removeAttribute('id');
                        
+                       // Check if there is a zero-width whitespace after the smiley, Safari does
+                       // not like them that much (caret will be placed inside a character).
+                       const nextSibling = smiley.nextSibling;
+                       if (nextSibling && nextSibling.nodeType === Node.TEXT_NODE && nextSibling.textContent === "\u200B") {
+                               nextSibling.remove();
+                       }
+                       
                        smiley.parentNode.insertBefore(document.createTextNode(" "), smiley);
                        
                        const whitespace = document.createTextNode(" ");