Using alternative range handling
authorAlexander Ebert <ebert@woltlab.com>
Thu, 25 Aug 2016 16:29:22 +0000 (18:29 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 25 Aug 2016 16:30:01 +0000 (18:30 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js

index 92f93e499ca86dc8871051a621f71278ecd71328..7d364fdae97df58387b271ad7c279e89672dc45d 100644 (file)
@@ -15,6 +15,35 @@ $.Redactor.prototype.WoltLabCaret = function() {
                        }).bind(this);
                        
                        this.$editor[0].addEventListener('mouseup', this.WoltLabCaret._handleEditorClick.bind(this));
+                       
+                       var internalRange = null;
+                       var selection = window.getSelection();
+                       this.$editor[0].addEventListener('keyup', function () {
+                               internalRange = selection.getRangeAt(0).cloneRange();
+                       });
+                       
+                       var mpSave = this.selection.save;
+                       this.selection.save = (function () {
+                               internalRange = null;
+                               
+                               mpSave.call(this);
+                       }).bind(this);
+                       
+                       var mpRestore = this.selection.restore;
+                       this.selection.restore = (function () {
+                               if (internalRange) {
+                                       selection.removeAllRanges();
+                                       selection.addRange(internalRange);
+                                       
+                                       internalRange = null;
+                                       
+                                       if (selection.rangeCount && this.utils.isRedactorParent(selection.getRangeAt(0).commonAncestorContainer)) {
+                                               return;
+                                       }
+                               }
+                               
+                               mpRestore.call(this);
+                       }).bind(this);
                },
                
                _handleEditorClick: function (event) {
index 6e3ed0e9a6986252fd0f899c16d9fdafb0c437af..b40ac961ba343eaf8da64e64c02e9737df50cd92 100644 (file)
@@ -51,17 +51,13 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util'
                 * @protected
                 */
                _insertQuote: function (data) {
+                       this._editor.selection.restore();
+                       
                        this._editor.buffer.set();
                        
                        // caret must be within a `<p>`, if it is not move it
                        /** @type Node */
                        var block = this._editor.selection.block();
-                       if (block === false) {
-                               this._editor.selection.restore();
-                               
-                               block = this._editor.selection.block();
-                       }
-                       
                        var redactor = this._editor.core.editor()[0];
                        while (block.parentNode && block.parentNode !== redactor) {
                                block = block.parentNode;