From: Alexander Ebert Date: Sun, 28 Dec 2014 23:31:44 +0000 (+0100) Subject: Fixed inserting block-level elements into empty

in Safari X-Git-Tag: 2.1.0_Beta_3~65 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=262c339657fde6316851eab8d83e5490d5dedd28;p=GitHub%2FWoltLab%2FWCF.git Fixed inserting block-level elements into empty

in Safari --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index d5b757fc80..4e95f3e53e 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -504,7 +504,7 @@ RedactorPlugins.wmonkeypatch = function() { var $html = this.$editor.html(); if (this.utils.isEmpty($html)) { var $cleared = false; - if (html.match(/^<(blockquote|div|p)/)) { + if (html.match(/^<(blockquote|div|p)/i)) { // 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(); @@ -522,6 +522,14 @@ RedactorPlugins.wmonkeypatch = function() { if (document.activeElement !== this.$editor[0]) { this.wutil.restoreSelection(); } + + if (html.match(/^<(blockquote|div|p)/i) && getSelection().getRangeAt(0).collapsed) { + var $startContainer = getSelection().getRangeAt(0).startContainer; + if ($startContainer.nodeType === Node.TEXT_NODE && $startContainer.textContent === '\u200b') { + // Safari breaks if inserting block-level elements into a

w/ only a zero-width space + this.caret.setEnd($($startContainer.parentElement).html('
')); + } + } } }).bind(this);