From: Alexander Ebert `, 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/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.