Fixed selection handling in Chrome 58
authorAlexander Ebert <ebert@woltlab.com>
Tue, 2 May 2017 08:45:26 +0000 (10:45 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 2 May 2017 08:45:26 +0000 (10:45 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 2053268f3e9c875eeda59fbaff36b63ff0562bb5..b3a039ed08ea0e925e934714309223927a2dc019 100644 (file)
@@ -1350,6 +1350,31 @@ RedactorPlugins.wmonkeypatch = function() {
                                $(document).find('span.redactor-nodes-marker').each($removeEmptyTextNodes);
                                this.$editor.find('span.redactor-nodes-marker').each($removeEmptyTextNodes);
                        }).bind(this);
+                       
+                       this.selection.createMarkers = (function() {
+                               this.selection.get();
+                               
+                               var node1 = this.selection.getMarker(1);
+                               
+                               this.selection.setMarker(this.range, node1, true);
+                               if (this.range.collapsed === false)
+                               {
+                                       var node2 = this.selection.getMarker(2);
+                                       this.selection.setMarker(this.range, node2, false);
+                                       
+                                       // Chrome 58 fails if the selection contains the first marker
+                                       var range = document.createRange();
+                                       range.setStartAfter(node1);
+                                       range.setEndBefore(node2);
+                                       
+                                       var selection = window.getSelection();
+                                       selection.removeAllRanges();
+                                       selection.addRange(range);
+                                       
+                               }
+                               
+                               this.savedSel = this.$editor.html();
+                       }).bind(this);
                },
                
                /**