Fixed backspacing of inserted images
authorAlexander Ebert <ebert@woltlab.com>
Fri, 6 Jan 2017 10:44:51 +0000 (11:44 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 6 Jan 2017 10:44:57 +0000 (11:44 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabAttachment.js

index 42717057e36c81a29eee55ea71b0c763a4324924..c6581a5340c5c62b9b38377e2532c4b91366ca8a 100644 (file)
@@ -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);
                        }