Fixed cmd+k link insertion on OSX Safari
authorAlexander Ebert <ebert@woltlab.com>
Sun, 25 Dec 2016 12:36:58 +0000 (13:36 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 25 Dec 2016 12:37:05 +0000 (13:37 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js

index 6c159b0517549e567f811e91fca5014b44761b5b..8ece922a18f00082244832a371e74071566e523f 100644 (file)
@@ -19,6 +19,10 @@ $.Redactor.prototype.WoltLabLink = function() {
                                e.preventDefault();
                        }
                        
+                       // used to determine if selection needs to be restored later as
+                       // Safari sometimes discards the selection when setting markers
+                       var hasSelectedText = this.selection.is();
+                       
                        this.selection.save();
                        
                        // close tooltip
@@ -49,8 +53,12 @@ $.Redactor.prototype.WoltLabLink = function() {
                        // WoltLab END
                        
                        // build link
+                       if (hasSelectedText) this.selection.restore();
+                       
                        var link = this.link.buildLinkFromElement($el);
                        
+                       if (hasSelectedText) this.selection.save();
+                       
                        // if link cut & paste inside editor browser added self host to a link
                        link.url = this.link.removeSelfHostFromUrl(link.url);