Taking care of caret position on edit click
authorAlexander Ebert <ebert@woltlab.com>
Mon, 5 Sep 2016 10:37:39 +0000 (12:37 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 5 Sep 2016 13:15:19 +0000 (15:15 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Code.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Spoiler.js

index e3c209a9e2a27354452ad5ea466a8a5221ffc331..c509424b09d480f6093e80086ed2d865d04bc1af 100644 (file)
@@ -67,7 +67,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di
                 */
                _observeLoad: function() {
                        elBySelAll('pre', this._editor.$editor[0], (function(pre) {
-                               pre.addEventListener(WCF_CLICK_EVENT, this._callbackEdit);
+                               pre.addEventListener('mousedown', this._callbackEdit);
                                this._setTitle(pre);
                        }).bind(this));
                },
@@ -90,6 +90,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di
                        if (event.pageY > offset.top && event.pageY < (offset.top + _headerHeight)) {
                                event.preventDefault();
                                
+                               this._editor.selection.save();
                                this._pre = pre;
                                
                                UiDialog.open(this);
@@ -150,6 +151,10 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di
                        return {
                                id: id,
                                options: {
+                                       onClose: (function () {
+                                               this._editor.selection.restore();
+                                       }).bind(this),
+                                       
                                        onSetup: (function() {
                                                elById(idButtonSave).addEventListener(WCF_CLICK_EVENT, this._save.bind(this));
                                                
index 86b7e3aff2a04627aaf7a638352d1421a5f0f73b..9da1fd53fe07c82abd9a4135395f2fb47d0958c1 100644 (file)
@@ -118,7 +118,7 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util'
                        for (var i = 0, length = this._quotes.length; i < length; i++) {
                                quote = this._quotes[i];
                                
-                               quote.addEventListener(WCF_CLICK_EVENT, this._callbackEdit);
+                               quote.addEventListener('mousedown', this._callbackEdit);
                                this._setTitle(quote);
                        }
                },
@@ -141,6 +141,7 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util'
                        if (event.pageY > offset.top && event.pageY < (offset.top + _headerHeight)) {
                                event.preventDefault();
                                
+                               this._editor.selection.save();
                                this._quote = quote;
                                
                                UiDialog.open(this);
@@ -209,6 +210,10 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util'
                        return {
                                id: id,
                                options: {
+                                       onClose: (function () {
+                                               this._editor.selection.restore();
+                                       }).bind(this),
+                                       
                                        onSetup: (function() {
                                                elById(idButtonSave).addEventListener(WCF_CLICK_EVENT, this._save.bind(this));
                                        }).bind(this),
index 744f1d4c566261bd5098e8b652177b7796be8f05..4b6b6d5a1425c52b8ca7405bc45855a42de17270 100644 (file)
@@ -65,7 +65,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di
                 */
                _observeLoad: function() {
                        elBySelAll('woltlab-spoiler', this._editor.$editor[0], (function(spoiler) {
-                               spoiler.addEventListener(WCF_CLICK_EVENT, this._callbackEdit);
+                               spoiler.addEventListener('mousedown', this._callbackEdit);
                                this._setTitle(spoiler);
                        }).bind(this));
                },
@@ -88,6 +88,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di
                        if (event.pageY > offset.top && event.pageY < (offset.top + _headerHeight)) {
                                event.preventDefault();
                                
+                               this._editor.selection.save();
                                this._spoiler = spoiler;
                                
                                UiDialog.open(this);
@@ -133,6 +134,10 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di
                        return {
                                id: id,
                                options: {
+                                       onClose: (function () {
+                                               this._editor.selection.restore();
+                                       }).bind(this),
+                                       
                                        onSetup: (function() {
                                                elById(idButtonSave).addEventListener(WCF_CLICK_EVENT, this._save.bind(this));
                                        }).bind(this),