Improved caret click handler
authorAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2016 13:11:39 +0000 (15:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2016 13:26:49 +0000 (15:26 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js

index 829afbf3bd07ef766714166b0e6703da529b29c9..dbf48ccb2714f679b3fd6e980f2c8d28788f1f62 100644 (file)
@@ -14,7 +14,7 @@ $.Redactor.prototype.WoltLabCaret = function() {
                                mpAfter.call(this, node);
                        }).bind(this);
                        
-                       this.$editor[0].addEventListener('mouseup', this.WoltLabCaret._handleEditorClick.bind(this));
+                       this.$editor[0].addEventListener(WCF_CLICK_EVENT, this.WoltLabCaret._handleEditorClick.bind(this));
                        
                        this.WoltLabCaret._initInternalRange();
                },
@@ -132,9 +132,13 @@ $.Redactor.prototype.WoltLabCaret = function() {
                        
                        var mpHtml = this.insert.html;
                        this.insert.html = (function (html, data) {
+                               var hasMarker = elBySel('.redactor-selection-marker', this.$editor[0]);
+                               
                                mpHtml.call(this, html, data);
                                
-                               saveRange();
+                               if (hasMarker || elBySel('.redactor-selection-marker', this.$editor[0]) === null) {
+                                       saveRange();
+                               }
                        }).bind(this);
                        
                        require(['Environment'], (function (Environment) {
@@ -151,10 +155,6 @@ $.Redactor.prototype.WoltLabCaret = function() {
                },
                
                _handleEditorClick: function (event) {
-                       if (!this.selection.get().isCollapsed) {
-                               return;
-                       }
-                       
                        var block = this.selection.block();
                        if (block === false) {
                                // check if the caret is now in a <p> before a <table>