From: Alexander Ebert Date: Thu, 2 Jun 2022 16:26:11 +0000 (+0200) Subject: Incorrect editor access from within a dialog X-Git-Tag: 5.5.0_RC_1~12 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=69b974205540e768750d36aed2e050a0483ac54f;p=GitHub%2FWoltLab%2FWCF.git Incorrect editor access from within a dialog See https://www.woltlab.com/community/thread/295821-fehler-beim-einf%C3%BCgen-von-zitaten/ --- diff --git a/ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts b/ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts index 5afd1f9ef6..747b1aaab6 100644 --- a/ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts +++ b/ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts @@ -60,59 +60,61 @@ class UiRedactorQuote { return; } - EventHandler.fire("com.woltlab.wcf.redactor2", "showEditor"); + Core.interactWithRedactor(() => { + EventHandler.fire("com.woltlab.wcf.redactor2", "showEditor"); - const editor = this._editor.core.editor()[0]; - this._editor.selection.restore(); + const editor = this._editor.core.editor()[0]; + this._editor.selection.restore(); - this._editor.buffer.set(); + this._editor.buffer.set(); - // caret must be within a `

`, if it is not: move it - let block = this._editor.selection.block(); - if (block === false) { - this._editor.focus.end(); - block = this._editor.selection.block() as HTMLElement; - } - - while (block && block.parentElement !== editor) { - block = block.parentElement!; - } + // caret must be within a `

`, if it is not: move it + let block = this._editor.selection.block(); + if (block === false) { + this._editor.focus.end(); + block = this._editor.selection.block() as HTMLElement; + } - const quote = document.createElement("woltlab-quote"); - quote.dataset.author = data.author; - quote.dataset.link = data.link; + while (block && block.parentElement !== editor) { + block = block.parentElement!; + } - let content = data.content; - if (data.isText) { - content = StringUtil.escapeHTML(content); - content = `

${content}

`; - content = content.replace(/\n\n/g, "

"); - content = content.replace(/\n/g, "
"); - } else { - content = UiRedactorMetacode.convertFromHtml(this._editor.$element[0].id, content); - } + const quote = document.createElement("woltlab-quote"); + quote.dataset.author = data.author; + quote.dataset.link = data.link; + + let content = data.content; + if (data.isText) { + content = StringUtil.escapeHTML(content); + content = `

${content}

`; + content = content.replace(/\n\n/g, "

"); + content = content.replace(/\n/g, "
"); + } else { + content = UiRedactorMetacode.convertFromHtml(this._editor.$element[0].id, content); + } - // bypass the editor as `insert.html()` doesn't like us - quote.innerHTML = content; + // bypass the editor as `insert.html()` doesn't like us + quote.innerHTML = content; - const blockParent = block.parentElement!; - blockParent.insertBefore(quote, block.nextSibling); + const blockParent = block.parentElement!; + blockParent.insertBefore(quote, block.nextSibling); - if (block.nodeName === "P" && (block.innerHTML === "
" || block.innerHTML.replace(/\u200B/g, "") === "")) { - blockParent.removeChild(block); - } + if (block.nodeName === "P" && (block.innerHTML === "
" || block.innerHTML.replace(/\u200B/g, "") === "")) { + blockParent.removeChild(block); + } - // avoid adjacent blocks that are not paragraphs - let sibling = quote.previousElementSibling; - if (sibling && sibling.nodeName !== "P") { - sibling = document.createElement("p"); - sibling.textContent = "\u200B"; - quote.insertAdjacentElement("beforebegin", sibling); - } + // avoid adjacent blocks that are not paragraphs + let sibling = quote.previousElementSibling; + if (sibling && sibling.nodeName !== "P") { + sibling = document.createElement("p"); + sibling.textContent = "\u200B"; + quote.insertAdjacentElement("beforebegin", sibling); + } - this._editor.WoltLabCaret.paragraphAfterBlock(quote); + this._editor.WoltLabCaret.paragraphAfterBlock(quote); - this._editor.buffer.set(); + this._editor.buffer.set(); + }); } /** 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 02d8bc2dd9..682621eb6f 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js @@ -41,48 +41,50 @@ define(["require", "exports", "tslib", "../../Core", "../../Dom/Util", "../../Ev if (this._editor.WoltLabSource.isActive()) { return; } - EventHandler.fire("com.woltlab.wcf.redactor2", "showEditor"); - const editor = this._editor.core.editor()[0]; - this._editor.selection.restore(); - this._editor.buffer.set(); - // caret must be within a `

`, if it is not: move it - let block = this._editor.selection.block(); - if (block === false) { - this._editor.focus.end(); - block = this._editor.selection.block(); - } - while (block && block.parentElement !== editor) { - block = block.parentElement; - } - const quote = document.createElement("woltlab-quote"); - quote.dataset.author = data.author; - quote.dataset.link = data.link; - let content = data.content; - if (data.isText) { - content = StringUtil.escapeHTML(content); - content = `

${content}

`; - content = content.replace(/\n\n/g, "

"); - content = content.replace(/\n/g, "
"); - } - else { - content = UiRedactorMetacode.convertFromHtml(this._editor.$element[0].id, content); - } - // bypass the editor as `insert.html()` doesn't like us - quote.innerHTML = content; - const blockParent = block.parentElement; - blockParent.insertBefore(quote, block.nextSibling); - if (block.nodeName === "P" && (block.innerHTML === "
" || block.innerHTML.replace(/\u200B/g, "") === "")) { - blockParent.removeChild(block); - } - // avoid adjacent blocks that are not paragraphs - let sibling = quote.previousElementSibling; - if (sibling && sibling.nodeName !== "P") { - sibling = document.createElement("p"); - sibling.textContent = "\u200B"; - quote.insertAdjacentElement("beforebegin", sibling); - } - this._editor.WoltLabCaret.paragraphAfterBlock(quote); - this._editor.buffer.set(); + Core.interactWithRedactor(() => { + EventHandler.fire("com.woltlab.wcf.redactor2", "showEditor"); + const editor = this._editor.core.editor()[0]; + this._editor.selection.restore(); + this._editor.buffer.set(); + // caret must be within a `

`, if it is not: move it + let block = this._editor.selection.block(); + if (block === false) { + this._editor.focus.end(); + block = this._editor.selection.block(); + } + while (block && block.parentElement !== editor) { + block = block.parentElement; + } + const quote = document.createElement("woltlab-quote"); + quote.dataset.author = data.author; + quote.dataset.link = data.link; + let content = data.content; + if (data.isText) { + content = StringUtil.escapeHTML(content); + content = `

${content}

`; + content = content.replace(/\n\n/g, "

"); + content = content.replace(/\n/g, "
"); + } + else { + content = UiRedactorMetacode.convertFromHtml(this._editor.$element[0].id, content); + } + // bypass the editor as `insert.html()` doesn't like us + quote.innerHTML = content; + const blockParent = block.parentElement; + blockParent.insertBefore(quote, block.nextSibling); + if (block.nodeName === "P" && (block.innerHTML === "
" || block.innerHTML.replace(/\u200B/g, "") === "")) { + blockParent.removeChild(block); + } + // avoid adjacent blocks that are not paragraphs + let sibling = quote.previousElementSibling; + if (sibling && sibling.nodeName !== "P") { + sibling = document.createElement("p"); + sibling.textContent = "\u200B"; + quote.insertAdjacentElement("beforebegin", sibling); + } + this._editor.WoltLabCaret.paragraphAfterBlock(quote); + this._editor.buffer.set(); + }); } /** * Toggles the quote block on button click.