Improved selection handling
authorAlexander Ebert <ebert@woltlab.com>
Mon, 15 Dec 2014 14:44:01 +0000 (15:44 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 15 Dec 2014 14:44:01 +0000 (15:44 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js

index 6a4913fca9534b34471293b0d0b364de73efbaf1..3694b5e4b189eafc50a9ec76ffdc9b36a6232cc3 100644 (file)
@@ -89,6 +89,14 @@ RedactorPlugins.wbutton = function() {
                        this.button.addCallback(this.button.get('image'), $.proxy(this.wbutton.insertImage, this));
                },
                
+               /**
+                * Modifies an existing button belonging to Redactor.
+                * 
+                * @param       string          buttonName
+                * @param       string          buttonTitle
+                * @param       string          faIcon
+                * @param       string          insertAfter
+                */
                _addCoreButton: function(buttonName, buttonTitle, faIcon, insertAfter) {
                        var $buttonObj = { title: (buttonTitle === null ? buttonName : buttonTitle) };
                        if (buttonName === 'subscript' || buttonName === 'superscript') {
@@ -153,6 +161,7 @@ RedactorPlugins.wbutton = function() {
                                        }
                                }
                                else {
+                                       this.buffer.set();
                                        this.insert.html('[' + $bbcode + ']' + $selectedHtml + this.selection.getMarkerAsHtml() + '[/' + $bbcode + ']', false);
                                        this.selection.restore();
                                }
index 4f37093637d2990ef76e15ff0a39f6c57fe490bf..0fbea06d487f71248504f7c3d0e011c6e690d3ad 100644 (file)
@@ -88,8 +88,17 @@ RedactorPlugins.wmonkeypatch = function() {
                                this.$editor.on('keyup.redactor', $.proxy(this.keyup.init, this));
                        }
                        
-                       this.$editor.on('mousedown.wmonkeypatch mouseup.wmonkeypatch', (function() {
-                               this.wutil.saveSelection();
+                       var $saveSelection = false;
+                       this.$editor.on('mousedown.wmonkeypatch', (function() {
+                               $saveSelection = true;
+                       }).bind(this));
+                       
+                       $(document).on('mouseup.wmonkeypatch', (function() {
+                               if ($saveSelection) {
+                                       $saveSelection = false;
+                                       
+                                       this.wutil.saveSelection();
+                               }
                        }).bind(this));
                },
                
index 78ac18bdcb12c6c97fa11c27e4361c1a1e78aad4..9386feb203998979b366667b5af652364bf7ccb4 100644 (file)
@@ -84,6 +84,13 @@ RedactorPlugins.wutil = function() {
                        }
                },
                
+               /**
+                * Clears the current selection.
+                */
+               clearSelection: function() {
+                       this._wutil.range = null;
+               },
+               
                /**
                 * Allows inserting of text contents in Redactor's source area.
                 *