From b62eca1305f4cb826ec047d5f56d2d8c5144db9d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 29 Nov 2014 01:16:06 +0100 Subject: [PATCH] Fixing HTML insert issues --- .../3rdParty/redactor/plugins/wmonkeypatch.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index ea4cd16e1f..893c39f281 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -435,12 +435,23 @@ RedactorPlugins.wmonkeypatch = function() { insert: function() { var $isWebKit = ($.browser.webkit || document.documentElement.style.hasOwnProperty('WebkitAppearance') || window.hasOwnProperty('chrome')); - var $focusEditor = (function() { + var $focusEditor = (function(html) { var $html = this.$editor.html(); if (this.utils.isEmpty($html)) { + var $cleared = false; + if (html.match(/^<(blockquote|div|p)/)) { + // inserting a block-level element into a

yields inconsistent behaviors in different browsers + // but since the HTML to be inserted is already a block element, we can place it directly in the root + this.$editor.empty(); + + $cleared = true; + } + this.$editor.focus(); - this.caret.setEnd(this.$editor.children('p:eq(0)')); + if (!$cleared) { + this.caret.setEnd(this.$editor.children('p:eq(0)')); + } } else { if (document.activeElement !== this.$editor[0]) { @@ -485,7 +496,7 @@ RedactorPlugins.wmonkeypatch = function() { // insert.html var $mpHtml = this.insert.html; this.insert.html = (function(html, clean) { - $focusEditor(); + $focusEditor(html); $mpHtml.call(this, html, clean); -- 2.20.1