Fixed caret position on text insert
authorAlexander Ebert <ebert@woltlab.com>
Tue, 12 Dec 2017 10:25:28 +0000 (11:25 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 12 Dec 2017 10:25:28 +0000 (11:25 +0100)
Fixes WoltLab/com.woltlab.gallery#55

wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js

index 55a948cd61c63b4e06c1891abbfe510671f84e3b..a3f181599e9196583c67e120c90d013185677a4a 100644 (file)
@@ -67,7 +67,16 @@ $.Redactor.prototype.WoltLabInsert = function() {
                        this.insert.text = (function (text) {
                                if (callback) callback = callback();
                                
+                               this.core.editor().focus();
+                               this.selection.restore();
+                               if (elClosest(window.getSelection().anchorNode, '.redactor-layer') !== this.core.editor()[0]) {
+                                       this.WoltLabCaret.endOfEditor();
+                                       console.log("fixed selection");
+                               }
+                               
                                mpText.call(this, text);
+                               
+                               this.selection.saveInstant();
                        }).bind(this);
                }
        };