From: Alexander Ebert Date: Mon, 25 Jul 2016 11:28:00 +0000 (+0200) Subject: Work-around for Firefox... again X-Git-Tag: 3.0.0_Beta_1~117^2~20 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=263e497c6d3b4d62cdd42df6df32bb9f146650b2;p=GitHub%2FWoltLab%2FWCF.git Work-around for Firefox... again --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index d40e76138a..67d2b87bfa 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -1985,6 +1985,8 @@ RedactorPlugins.wbbcode = function() { * @param object data */ _keyupCallback: function(data) { + this.keydown.woltlabIsEnter = false; + switch (data.event.which) { case $.ui.keyCode.BACKSPACE: case $.ui.keyCode.DELETE: diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index c34a659aa2..334a71d30f 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -873,6 +873,7 @@ RedactorPlugins.wmonkeypatch = function() { */ keydown: function() { this.keydown.enterWithinBlockquote = false; + this.keydown.woltlabIsEnter = false; // keydown.onTab var $mpOnTab = this.keydown.onTab; @@ -901,6 +902,8 @@ RedactorPlugins.wmonkeypatch = function() { // keydown.setupBuffer var $mpSetupBuffer = this.keydown.setupBuffer; this.keydown.setupBuffer = (function(e, key) { + this.keydown.woltlabIsEnter = (key == this.keyCode.ENTER && !e.shiftKey && !e.ctrlKey && !e.metaKey); + // undo if (this.keydown.ctrl && key === 89 && !e.shiftKey && !e.altKey && this.opts.rebuffer.length !== 0) { e.preventDefault(); @@ -1309,6 +1312,24 @@ RedactorPlugins.wmonkeypatch = function() { fixApple = true; } else { + // Removing the marker without moving the selection first causes Firefox + // to move the selection somewhere else. Unfortunately the predicted new + // location is sometimes completely off, messing up everything. + if (this.keydown.woltlabIsEnter && this.utils.browser('mozilla')) { + $node = null; + + var text = document.createTextNode("\u200B"); + if (marker.nextSibling) marker.parentNode.insertBefore(text, marker.nextSibling); + else marker.parentNode.appendChild(text); + + this.selection.implicitRange = document.createRange(); + this.selection.implicitRange.setStartAfter(text); + this.selection.implicitRange.setEndAfter(text); + + getSelection().removeAllRanges(); + getSelection().addRange(this.selection.implicitRange); + } + marker.parentNode.removeChild(marker); } @@ -1320,7 +1341,7 @@ RedactorPlugins.wmonkeypatch = function() { getSelection().removeAllRanges(); getSelection().addRange(this.selection.implicitRange); } - else { + else if (!this.utils.browser('mozilla')) { this.selection.implicitRange = null; } @@ -1338,7 +1359,18 @@ RedactorPlugins.wmonkeypatch = function() { // selection.removeMarkers this.selection.removeMarkers = (function() { - this.$editor.find('span.redactor-selection-marker').each($removeEmptyTextNodes); + var func = (function() { + this.$editor.find('span.redactor-selection-marker').each($removeEmptyTextNodes); + }).bind(this); + + if (this.keydown.woltlabIsEnter && this.utils.browser('mozilla')) { + // slightly delay removal to give Firefox some time to accept + // the new caret position + setTimeout(func, 1); + } + else { + func(); + } }).bind(this); // selection.removeNodesMarkers