From: Alexander Ebert Date: Wed, 11 Oct 2017 09:13:12 +0000 (+0200) Subject: Improved backspace/delete key handling for empty lines X-Git-Tag: 3.0.10~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=163ead009c7eb8beb9a6912979fc837d8b7b6aa9;p=GitHub%2FWoltLab%2FWCF.git Improved backspace/delete key handling for empty lines --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js index ebd24db79b..4375491f70 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js @@ -45,6 +45,47 @@ $.Redactor.prototype.WoltLabKeydown = function() { } } + // delete the current line on backspace and delete, if it is empty, and move + // the caret into the adjacent element, rather than pulling content out + if (e.which === this.keyCode.BACKSPACE || e.which === this.keyCode.DELETE) { + if (selection.isCollapsed) { + var range = selection.getRangeAt(0); + var container = range.startContainer; + if (container.nodeType === Node.TEXT_NODE) container = container.parentNode; + if (container.nodeName === 'P' && container.childNodes.length === 1 && container.childNodes[0].textContent === '\u200B') { + // simple comparison to check that at least one sibling is not null + if (container.previousElementSibling !== container.nextElementSibling) { + var caretEnd = null, caretStart = null; + + if (e.which === this.keyCode.BACKSPACE) { + if (container.previousElementSibling === null) { + caretStart = container.nextElementSibling; + } + else { + caretEnd = container.previousElementSibling; + } + } + else { + if (container.nextElementSibling === null) { + caretEnd = container.previousElementSibling; + } + else { + caretStart = container.nextElementSibling; + } + } + + elRemove(container); + + if (caretStart === null) this.caret.end(caretEnd); + else this.caret.start(caretStart); + + e.preventDefault(); + return; + } + } + } + } + var returnValue = mpInit.call(this, e); if (returnValue !== false && !e.originalEvent.defaultPrevented) {