From: Alexander Ebert Date: Tue, 9 Jul 2019 11:47:07 +0000 (+0200) Subject: Workaround for enter in empty lists in Safari X-Git-Tag: 5.2.0_Alpha_2~32 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5b442b41c24c5cf4830337d5aff30cf6e41a2752;p=GitHub%2FWoltLab%2FWCF.git Workaround for enter in empty lists in Safari --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js index ebb02bdf8b..d300fbbd72 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js @@ -1,11 +1,16 @@ $.Redactor.prototype.WoltLabKeydown = function() { "use strict"; + var _isSafari = false; var _tags = []; return { init: function () { var selection = window.getSelection(); + + require(['Environment'], function (Environment) { + _isSafari = (Environment.browser() === 'safari'); + }); var mpInit = this.keydown.init; this.keydown.init = (function (e) { @@ -341,10 +346,25 @@ $.Redactor.prototype.WoltLabKeydown = function() { // they do not recognize this at all times, in particular certain white-spaces // and
may not always play well. if (this.utils.isRedactorParent(listItem) && this.utils.isEmpty(listItem.innerHTML)) { - // the current item is empty and there is no adjacent one, force clear the - // contents to enable browser recognition + // The current item is empty and there is no adjacent one, force clear the + // contents to enable browser recognition. + // + // Unless this is Safari, which absolutely loves empty lines containing only + // a `
` and freaks out when a block element is completely empty. if (listItem.nextElementSibling === null) { - listItem.innerHTML = ''; + listItem.innerHTML = (_isSafari) ? '
' : ''; + + // If this is Safari, we'll move the caret behind the `
`, otherwise + // nothing will happen. + if (_isSafari) { + var range = document.createRange(); + range.selectNodeContents(listItem); + range.collapse(false); + + var selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + } } } }