Fixed inconsistent editor behavior when inserting links
authorAlexander Ebert <ebert@woltlab.com>
Tue, 28 Oct 2014 00:23:58 +0000 (01:23 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 28 Oct 2014 00:23:58 +0000 (01:23 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 1819633a4cbe2775052e39b49a28edde5526198c..30c47f948f3af0c4aa983b271949a3c44a31eddd 100644 (file)
@@ -29,6 +29,7 @@ RedactorPlugins.wmonkeypatch = function() {
                        this.wmonkeypatch.image();
                        this.wmonkeypatch.insert();
                        this.wmonkeypatch.keydown();
+                       this.wmonkeypatch.link();
                        this.wmonkeypatch.modal();
                        this.wmonkeypatch.paste();
                        this.wmonkeypatch.observe();
@@ -325,6 +326,25 @@ RedactorPlugins.wmonkeypatch = function() {
                        }).bind(this);
                },
                
+               /**
+                * Partially overwrites the 'link' module.
+                * 
+                * - force consistent caret position upon link insert
+                */
+               link: function() {
+                       // link.insert
+                       var $mpInsert = this.link.insert;
+                       this.link.insert = (function() {
+                               $mpInsert.call(this);
+                               
+                               this.selection.get();
+                               var $current = this.selection.getCurrent();
+                               if ($current.tagName === 'A') {
+                                       this.caret.setAfter($current);
+                               }
+                       }).bind(this);
+               },
+               
                /**
                 * Partially overwrites the 'modal' module.
                 *