Fix block formatting in Firefox w/o prior editor focus
authorAlexander Ebert <ebert@woltlab.com>
Wed, 16 Nov 2016 11:14:26 +0000 (12:14 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 16 Nov 2016 15:14:14 +0000 (16:14 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js

index 557e83866260bb5c869ee9610dd6b725bad3d07e..3a240230bba274853d3931cdf8688acf55819704 100644 (file)
@@ -31,6 +31,21 @@ $.Redactor.prototype.WoltLabBlock = function() {
                        
                        var mpFormatCollapsed = this.block.formatCollapsed;
                        this.block.formatCollapsed = (function(tag, attr, value, type) {
+                               if (this.detect.isFirefox()) {
+                                       var editor = this.core.editor()[0];
+                                       if (document.activeElement !== editor) {
+                                               this.selection.restore();
+                                               
+                                               if (document.activeElement !== editor) {
+                                                       editor.focus();
+                                               }
+                                       }
+                                       
+                                       if (this.selection.block() === false) {
+                                               this.focus.end();
+                                       }
+                               }
+                               
                                var replaced = mpFormatCollapsed.call(this, tag, attr, value, type);
                                
                                for (var i = 0, length = replaced.length; i < length; i++) {