Fixed pasting of contents into empty quotes
authorAlexander Ebert <ebert@woltlab.com>
Fri, 24 Apr 2015 18:46:10 +0000 (20:46 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 24 Apr 2015 18:46:10 +0000 (20:46 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index b94530da4146a0a1d95c9ac8c18aca146d727ac7..6719d5a471555c88e2ec8d12265cdc4b5dea7ab9 100644 (file)
@@ -2071,7 +2071,7 @@ RedactorPlugins.wbbcode = function() {
                                }
                                else {
                                        $html = this.wbbcode.convertToHtml($openTag + $id + $closingTag);
-                                       $html = $html.replace($id, $innerHTML.replace(/^<p>/, '').replace(/<\/p>$/, ''));
+                                       $html = $html.replace($id, html.replace(/^<p>/, '').replace(/<\/p>$/, ''));
                                }
                                
                                $html = $html.replace(/^<p>/, '').replace(/<\/p>$/, '');
@@ -2088,6 +2088,8 @@ RedactorPlugins.wbbcode = function() {
                                                if (!window.getSelection().rangeCount) {
                                                        this.wutil.selectionEndOfEditor();
                                                }
+                                               
+                                               this.wutil.saveSelection();
                                        }
                                }
                                
index 7512287cafaadd0c5636e68467b403bc0b9cb288..70ccdf695a97de972a7a9627f7beaf32f5042835 100644 (file)
@@ -1085,9 +1085,39 @@ RedactorPlugins.wmonkeypatch = function() {
                                }
                        }).bind(this);
                        
+                       var $fixSelection = function() {
+                               var $selection = window.getSelection();
+                               if (!$selection.rangeCount) {
+                                       return;
+                               }
+                               
+                               var $range = $selection.getRangeAt(0);
+                               if (!$range.collapsed) {
+                                       return;
+                               }
+                               
+                               var $element = $range.startContainer;
+                               if ($element.nodeType === Node.ELEMENT_NODE && $element.tagName === 'DIV') {
+                                       var $parentNode = $element.parentNode;
+                                       if ($parentNode !== null && $parentNode.tagName === 'BLOCKQUOTE' && $parentNode.classList.contains('quoteBox')) {
+                                               var $endContainer = $range.startContainer.childNodes[$range.startContainer.childNodes.length - 1];
+                                               var $newRange = document.createRange();
+                                               $newRange.setStart($range.startContainer.childNodes[0], 0);
+                                               
+                                               $newRange.setEnd($endContainer, $endContainer.length);
+                                               $newRange.collapse(false);
+                                               
+                                               $selection.removeAllRanges();
+                                               $selection.addRange($newRange);
+                                       }
+                               }
+                       };
+                       
                        // paste.insert
                        var $mpInsert = this.paste.insert;
                        this.paste.insert = (function(html) {
+                               $fixSelection();
+                               
                                $mpInsert.call(this, html);
                                
                                setTimeout((function() {