From: Alexander Ebert Date: Sat, 29 Nov 2014 00:16:06 +0000 (+0100) Subject: Fixing HTML insert issues X-Git-Tag: 2.1.0_Beta_1~123 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b62eca1305f4cb826ec047d5f56d2d8c5144db9d;p=GitHub%2FWoltLab%2FWCF.git Fixing HTML insert issues --- 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);