From 262c339657fde6316851eab8d83e5490d5dedd28 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 29 Dec 2014 00:31:44 +0100 Subject: [PATCH] Fixed inserting block-level elements into empty

in Safari --- .../files/js/3rdParty/redactor/plugins/wmonkeypatch.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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); -- 2.20.1