Improved cursor position for inserted bbcode tags
authorAlexander Ebert <ebert@woltlab.com>
Fri, 11 May 2018 14:58:55 +0000 (16:58 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 11 May 2018 14:58:55 +0000 (16:58 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js

index a7d8a76f4fd6eb2a50c2bf36dcd257a36977c601..aa245a25489192da5d68fac5bf68bf4b0fa7f06d 100644 (file)
@@ -166,7 +166,9 @@ $.Redactor.prototype.WoltLabButton = function() {
                        if (data.cancel !== true) {
                                this.buffer.set();
                                
-                               var html = '[' + bbcode + ']' + this.selection.html() + (this.selection.is() ? '' : this.marker.html()) + '[/' + bbcode + ']';
+                               var marker = this.marker.get();
+                               marker.classList.add('woltlab-bbcode-marker');
+                               var html = '[' + bbcode + ']' + this.selection.html() + marker.outerHTML + '[/' + bbcode + ']';
                                this.insert.html(html);
                                this.selection.restore();
                        }
index 184a9fb282e5dfe34199d37da221da3149e83be3..74aeedfe314234494225d7851dd6bb2792880b02 100644 (file)
@@ -223,6 +223,8 @@ $.Redactor.prototype.WoltLabClean = function() {
                                }
                                
                                elBySelAll('span', div, function (span) {
+                                       if (span.classList.contains('redactor-selection-marker')) return;
+                                       
                                        if (!span.hasAttribute('style') || !span.style.length) {
                                                while (span.childNodes.length) {
                                                        span.parentNode.insertBefore(span.childNodes[0], span);
index 901e906e037c4821f22d8c76cc354375e674dd08..8882b76120797d042c8fb170b4b6d3742d26c0ab 100644 (file)
@@ -77,6 +77,24 @@ $.Redactor.prototype.WoltLabInsert = function() {
                                
                                this.selection.saveInstant();
                        }).bind(this);
+                       
+                       this.placeHtml = (function(html) {
+                               var hasBbcodeMarker = false;
+                               html.forEach(function(fragment) {
+                                       if (fragment instanceof Element && fragment.classList.contains('woltlab-bbcode-marker')) {
+                                               hasBbcodeMarker = true;
+                                       }
+                               });
+                               
+                               var marker = document.createElement('span');
+                               marker.id = 'redactor-insert-marker';
+                               marker = this.insert.node(marker);
+                               
+                               $(marker).before(html);
+                               this.selection.restore();
+                               if (!hasBbcodeMarker) this.caret.after(marker);
+                               $(marker).remove();
+                       }).bind(this);
                }
        };
 };