From 3eeb67d024950eb180b9ae07f63a8925ecaa18ad Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 25 Aug 2016 18:29:22 +0200 Subject: [PATCH] Using alternative range handling --- .../redactor2/plugins/WoltLabCaret.js | 29 +++++++++++++++++++ .../js/WoltLabSuite/Core/Ui/Redactor/Quote.js | 8 ++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js index 92f93e499c..7d364fdae9 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js @@ -15,6 +15,35 @@ $.Redactor.prototype.WoltLabCaret = function() { }).bind(this); this.$editor[0].addEventListener('mouseup', this.WoltLabCaret._handleEditorClick.bind(this)); + + var internalRange = null; + var selection = window.getSelection(); + this.$editor[0].addEventListener('keyup', function () { + internalRange = selection.getRangeAt(0).cloneRange(); + }); + + var mpSave = this.selection.save; + this.selection.save = (function () { + internalRange = null; + + mpSave.call(this); + }).bind(this); + + var mpRestore = this.selection.restore; + this.selection.restore = (function () { + if (internalRange) { + selection.removeAllRanges(); + selection.addRange(internalRange); + + internalRange = null; + + if (selection.rangeCount && this.utils.isRedactorParent(selection.getRangeAt(0).commonAncestorContainer)) { + return; + } + } + + mpRestore.call(this); + }).bind(this); }, _handleEditorClick: function (event) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js index 6e3ed0e9a6..b40ac961ba 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js @@ -51,17 +51,13 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util' * @protected */ _insertQuote: function (data) { + this._editor.selection.restore(); + this._editor.buffer.set(); // caret must be within a `

`, if it is not move it /** @type Node */ var block = this._editor.selection.block(); - if (block === false) { - this._editor.selection.restore(); - - block = this._editor.selection.block(); - } - var redactor = this._editor.core.editor()[0]; while (block.parentNode && block.parentNode !== redactor) { block = block.parentNode; -- 2.20.1