Fixed keydown handling and range after removing selection markers
authorAlexander Ebert <ebert@woltlab.com>
Tue, 13 Jan 2015 11:50:20 +0000 (12:50 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 13 Jan 2015 11:50:20 +0000 (12:50 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 8c23c3b95b0ae233dd788b330517a5be02b6dc8a..c35169bac63b6be8ca8dc57dc5c57b38af162c9a 100644 (file)
@@ -1449,9 +1449,23 @@ RedactorPlugins.wbbcode = function() {
                                                                $preventAndSelectQuote = true;
                                                        }
                                                }
-                                               else if (current.previousElementSibling && current.previousElementSibling.tagName === 'BLOCKQUOTE') {
-                                                       $quote = current.previousElementSibling;
-                                                       $preventAndSelectQuote = true;
+                                               else {
+                                                       var $scope = current;
+                                                       if ($scope.nodeType === Node.TEXT_NODE) {
+                                                               if (this.range.startOffset === 0 || (this.range.startOffset === 1 && $scope.textContent === '\u200b')) {
+                                                                       if (!$scope.previousSibling) {
+                                                                               $scope = $scope.parentElement;
+                                                                       }
+                                                               }
+                                                       }
+                                                       
+                                                       if ($scope.nodeType === Node.ELEMENT_NODE) {
+                                                               var $previous = $scope.previousSibling;
+                                                               if ($previous && $previous.nodeType === Node.ELEMENT_NODE && $previous.tagName === 'BLOCKQUOTE') {
+                                                                       $quote = $previous;
+                                                                       $preventAndSelectQuote = true;
+                                                               }
+                                                       }
                                                }
                                                
                                                if ($preventAndSelectQuote) {
index 91a447ac5c573ac968a2a892941a5d3599d2c291..51007c899f4ac5bf42a7eefabbbd4011719cfef8 100644 (file)
@@ -868,14 +868,23 @@ RedactorPlugins.wmonkeypatch = function() {
                 *  - remove superflous empty text nodes caused by the selection markers (#2083)
                 */
                selection: function() {
-                       var $removeEmptyTextNodes = function(index, marker) {
+                       var $removeEmptyTextNodes = (function(index, marker) {
                                var $nextSibling = marker.nextSibling;
                                if ($nextSibling !== null && $nextSibling.nodeType === Node.TEXT_NODE && $nextSibling.length === 0) {
                                        $($nextSibling).remove();
                                }
                                
-                               $(marker).remove();     
-                       };
+                               var $node = null;
+                               if ((marker.id === 'selection-marker-1' && !this.$editor.find('#selection-marker-2').length) || marker.id === 'nodes-marker-1' && !this.$editor.find('#nodes-marker-2').length) {
+                                       $node = marker.previousSibling;
+                               }
+                               
+                               $(marker).remove();
+                               
+                               if ($node !== null) {
+                                       this.caret.set($node, $node.length, $node, $node.length);
+                               }
+                       }).bind(this);
                        
                        // selection.removeMarkers
                        this.selection.removeMarkers = (function() {