From: Alexander Ebert Date: Fri, 6 Jan 2017 10:44:51 +0000 (+0100) Subject: Fixed backspacing of inserted images X-Git-Tag: 3.0.0~35 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4f5b5992b0d291bb3698429bf22fbe98927ea18c;p=GitHub%2FWoltLab%2FWCF.git Fixed backspacing of inserted images --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabAttachment.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabAttachment.js index 42717057e3..c6581a5340 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabAttachment.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabAttachment.js @@ -35,7 +35,21 @@ $.Redactor.prototype.WoltLabAttachment = function() { var img = elById(id); if (img) { img.removeAttribute('id'); - this.caret.after(img); + + // manually set the caret after the img by using a simple text-node containing just `\u200B` + var text = img.nextSibling; + if (!text || text.nodeType !== Node.TEXT_NODE || text.textContent !== '\u200B') { + text = document.createTextNode('\u200B'); + img.parentNode.insertBefore(text, img.nextSibling); + } + + var range = document.createRange(); + range.selectNode(text); + range.collapse(false); + + var selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); } }).bind(this), 10); }