From 1a37316d4fff1557bd4f52e432f6c8eb980f48d0 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 20 Jan 2015 19:26:37 +0100 Subject: [PATCH] Caret could not be set into empty but formatted list item --- .../3rdParty/redactor/plugins/wmonkeypatch.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 6d0fcdfa4a..9a24ff5ed4 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -171,6 +171,34 @@ RedactorPlugins.wmonkeypatch = function() { return false; } + else if (event.target.tagName === 'LI') { + // work-around for #1942 + var $range = (window.getSelection().rangeCount) ? window.getSelection().getRangeAt(0) : null; + var $caretInsideList = false; + if ($range !== null) { + if (!$range.collapsed) { + return; + } + + var $current = $range.startContainer; + while ($current !== null && $current !== this.$editor[0]) { + if ($current.tagName === 'LI') { + $caretInsideList = true; + break; + } + + $current = $current.parentElement; + } + } + + if (!$caretInsideList || $range === null) { + var $node = document.createTextNode('\u200b'); + var $firstChild = event.target.children[0]; + $firstChild.appendChild($node); + + this.caret.setEnd($firstChild); + } + } }).bind(this)); }, -- 2.20.1