From 4f5b5992b0d291bb3698429bf22fbe98927ea18c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 6 Jan 2017 11:44:51 +0100 Subject: [PATCH] Fixed backspacing of inserted images --- .../redactor2/plugins/WoltLabAttachment.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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); } -- 2.20.1