From 4a7be94cbe28a43ec3e6f0248cd6efd4651a1cdb Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 13 Feb 2018 14:10:45 +0100 Subject: [PATCH] Work-around for the caret position in nested lists in Firefox --- .../redactor2/plugins/WoltLabKeyup.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeyup.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeyup.js index 14e913fe4a..55e18f5e76 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeyup.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeyup.js @@ -14,8 +14,36 @@ $.Redactor.prototype.WoltLabKeyup = function() { var editor = this.$editor[0]; var selection = window.getSelection(); - var node = selection.anchorNode; var parent = null; + + if (this.detect.isFirefox()) { + var anchorNode = selection.anchorNode; + if (anchorNode.nodeType === Node.TEXT_NODE && selection.anchorOffset === 0) { + parent = anchorNode.parentNode; + if (parent.childNodes[0] === anchorNode) { + anchorNode = anchorNode.parentNode; + } + } + + if (anchorNode.nodeName === 'LI') { + // check if this is a nested list + var list = anchorNode.parentNode; + parent = list.parentNode; + + // Firefox does not handle nested lists well, yielding untargetable list items + // see https://bugzilla.mozilla.org/show_bug.cgi?id=1428073 + if (parent.nodeName === 'LI' && list.previousSibling === null) { + parent.insertBefore(this.marker.get(), list); + parent.insertBefore(elCreate('br'), list); + + this.selection.restore(); + + return; + } + } + } + + var node = selection.anchorNode; while (node.parentNode) { if (node.parentNode === editor) { parent = node; -- 2.20.1