From aabbf2aa7505ca63a6ef0365d14c31fec01ed923 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 4 Sep 2017 14:47:38 +0200 Subject: [PATCH] Fixed caret management when inserting images --- .../3rdParty/redactor2/plugins/WoltLabInsert.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js index 1206b2eb1a..55a948cd61 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js @@ -9,17 +9,22 @@ $.Redactor.prototype.WoltLabInsert = function() { this.insert.html = (function (html, data) { if (callback) callback = callback(); + var selection = window.getSelection(); + if (selection.rangeCount && selection.anchorNode.nodeName === 'IMG') { + this.caret.after(selection.anchorNode); + } + this.placeholder.hide(); this.core.editor().focus(); // Firefox may have an incorrect selection if pasting into the editor using the contextual menu if (this.detect.isFirefox()) { - var selection = this.selection.get(); - if (selection.anchorNode.closest('.redactor-layer') === null) { + var anchorNode = (selection.anchorNode.nodeType === Node.TEXT_NODE) ? selection.anchorNode.parentNode : selection.anchorNode; + if (anchorNode.closest('.redactor-layer') === null) { this.selection.restore(); - selection = this.selection.get(); - if (selection.anchorNode.closest('.redactor-layer') === null) { + anchorNode = (selection.anchorNode.nodeType === Node.TEXT_NODE) ? selection.anchorNode.parentNode : selection.anchorNode; + if (anchorNode.closest('.redactor-layer') === null) { this.WoltLabCaret.endOfEditor(); this.selection.save(); } @@ -52,6 +57,10 @@ $.Redactor.prototype.WoltLabInsert = function() { elRemove(block); } } + + if (selection.rangeCount && selection.anchorNode.nodeName === 'IMG') { + this.caret.after(selection.anchorNode); + } }).bind(this); var mpText = this.insert.text; -- 2.20.1