Fixed block-level changes w/o editor focus
authorAlexander Ebert <ebert@woltlab.com>
Thu, 30 Mar 2017 14:07:07 +0000 (16:07 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 30 Mar 2017 14:07:12 +0000 (16:07 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js

index e8afa1779fc574f68c8c873a4ef8cfa29adb1ebb..7b89d3dc1a7069afb8812caae89217ad743a9b87 100644 (file)
@@ -29,6 +29,10 @@ $.Redactor.prototype.WoltLabBlock = function() {
                                return (this.utils.isCollapsed()) ? this.block.formatCollapsed(tag, attr, value, type) : this.block.formatUncollapsed(tag, attr, value, type);
                        }).bind(this);
                        
+                       var isCaretInsideRedactor = (function (editor, block) {
+                               return !(document.activeElement !== editor || block === false || !this.utils.isRedactorParent(block));
+                       }).bind(this);
+                       
                        var mpFormatCollapsed = this.block.formatCollapsed;
                        this.block.formatCollapsed = (function(tag, attr, value, type) {
                                var block = this.selection.block();
@@ -37,21 +41,20 @@ $.Redactor.prototype.WoltLabBlock = function() {
                                        return;
                                }
                                
-                               if (this.detect.isFirefox()) {
-                                       var editor = this.core.editor()[0];
-                                       if (document.activeElement !== editor) {
-                                               this.selection.restore();
-                                               
-                                               if (document.activeElement !== editor) {
-                                                       editor.focus();
-                                               }
-                                       }
+                               var editor = this.core.editor()[0];
+                               if (!isCaretInsideRedactor(editor, block)) {
+                                       this.selection.restore();
                                        
-                                       if (this.selection.block() === false) {
-                                               this.focus.end();
+                                       if (document.activeElement !== editor) {
+                                               editor.focus();
                                        }
                                }
                                
+                               if (!isCaretInsideRedactor(editor, block)) {
+                                       this.focus.end();
+                                       this.selection.save();
+                               }
+                               
                                var replaced = mpFormatCollapsed.call(this, tag, attr, value, type);
                                
                                for (var i = 0, length = replaced.length; i < length; i++) {