From 3c3535dfa0c237372cc1182a410a1be9d2735a58 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 13 Feb 2018 14:35:33 +0100 Subject: [PATCH] Pressing delete at the end of a list item in Chrome could lead to stray items --- .../redactor2/plugins/WoltLabKeydown.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js index 24f2d0233a..5e30fe427b 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js @@ -83,6 +83,28 @@ $.Redactor.prototype.WoltLabKeydown = function() { return; } } + else if (this.detect.isWebkit() && container.nodeName === 'LI' && e.which === this.keyCode.DELETE) { + // check if caret is at the end of the list item, and if there is an adjacent list item + var anchorNode = selection.anchorNode; + if (anchorNode.nodeType === Node.TEXT_NODE && anchorNode.textContent.length === selection.anchorOffset && anchorNode.parentNode.lastChild === anchorNode) { + var nextItem = container.nextElementSibling; + if (nextItem && nextItem.nodeName === 'LI') { + this.buffer.set(); + + this.selection.save(); + + while (nextItem.childNodes.length) { + container.appendChild(nextItem.childNodes[0]); + } + elRemove(nextItem); + + this.selection.restore(); + + e.preventDefault(); + return; + } + } + } } } -- 2.20.1