diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index b6552ab72..aa11682fe 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -626,6 +626,14 @@ export class Gutter { selectsElement, type: "Blocks2Blockquote" })); + turnIntoSubmenu.push(this.turnsIntoOne({ + menuId: "callout", + icon: "iconCallout", + label: window.siyuan.languages.callout, + protyle, + selectsElement, + type: "Blocks2Callout" + })); } turnIntoSubmenu.push(this.turnsInto({ menuId: "paragraph", @@ -1007,6 +1015,14 @@ export class Gutter { selectsElement: [nodeElement], type: "Blocks2Blockquote" })); + turnIntoSubmenu.push(this.turnsIntoOne({ + menuId: "callout", + icon: "iconCallout", + label: window.siyuan.languages.callout, + protyle, + selectsElement: [nodeElement], + type: "Blocks2Callout" + })); turnIntoSubmenu.push(this.turnsInto({ menuId: "heading1", icon: "iconH1", @@ -1086,6 +1102,14 @@ export class Gutter { selectsElement: [nodeElement], type: "Blocks2Blockquote" })); + turnIntoSubmenu.push(this.turnsIntoOne({ + menuId: "callout", + icon: "iconCallout", + label: window.siyuan.languages.callout, + protyle, + selectsElement: [nodeElement], + type: "Blocks2Callout" + })); if (subType !== "h1") { turnIntoSubmenu.push(this.turnsInto({ menuId: "heading1", @@ -1178,6 +1202,14 @@ export class Gutter { selectsElement: [nodeElement], type: "Blocks2Blockquote" })); + turnIntoSubmenu.push(this.turnsIntoOne({ + menuId: "callout", + icon: "iconCallout", + label: window.siyuan.languages.callout, + protyle, + selectsElement: [nodeElement], + type: "Blocks2Callout" + })); if (nodeElement.getAttribute("data-subtype") === "o") { turnIntoSubmenu.push(this.turnsOneInto({ menuId: "list", diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 9b749c093..e8742debf 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -162,11 +162,14 @@ const promiseTransaction = () => { } else if (updateElements.length > 0) { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.parentID}"]`)).forEach(item => { if (!isInEmbedBlock(item) && !getFirstBlock(item).contains(range.startContainer)) { + const cloneElement = processClonePHElement(updateElements[0].cloneNode(true) as Element); // 列表特殊处理 if (item.firstElementChild?.classList.contains("protyle-action")) { - item.firstElementChild.after(processClonePHElement(updateElements[0].cloneNode(true) as Element)); + item.firstElementChild.after(cloneElement); + } else if (item.classList.contains("callout")) { + item.querySelector(".callout-content").prepend(cloneElement); } else { - item.prepend(processClonePHElement(updateElements[0].cloneNode(true) as Element)); + item.prepend(cloneElement); } hasFind = true; } @@ -208,10 +211,14 @@ const promiseTransaction = () => { if (!isInEmbedBlock(item) && !item.contains(range.startContainer)) { // 列表特殊处理 if (item.firstElementChild && item.firstElementChild.classList.contains("protyle-action") && - item.firstElementChild.nextElementSibling.getAttribute("data-node-id") !== operation.id) { + item.firstElementChild.nextElementSibling?.getAttribute("data-node-id") !== operation.id) { item.firstElementChild.insertAdjacentHTML("afterend", operation.data); cursorElements.push(item.firstElementChild.nextElementSibling); - } else if (item.firstElementChild && item.firstElementChild.getAttribute("data-node-id") !== operation.id) { + } else if (item.classList.contains("callout") && + item.querySelector('[data-node-id]')?.getAttribute("data-node-id") !== operation.id) { + item.querySelector(".callout-content").insertAdjacentHTML("afterbegin", operation.data); + cursorElements.push(item.querySelector('[data-node-id]')); + } else if (item.firstElementChild.getAttribute("data-node-id") !== operation.id) { item.insertAdjacentHTML("afterbegin", operation.data); cursorElements.push(item.firstElementChild); } @@ -719,11 +726,14 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: } else { parentElement.forEach(item => { if (!isInEmbedBlock(item)) { + const cloneElement = processClonePHElement(updateElements[0].cloneNode(true) as Element); // 列表特殊处理 if (item.firstElementChild?.classList.contains("protyle-action")) { - item.firstElementChild.after(processClonePHElement(updateElements[0].cloneNode(true) as Element)); + item.firstElementChild.after(cloneElement); + } else if (item.classList.contains("callout")) { + item.querySelector(".callout-content").prepend(cloneElement); } else { - item.prepend(processClonePHElement(updateElements[0].cloneNode(true) as Element)); + item.prepend(cloneElement); } hasFind = true; } @@ -825,6 +835,9 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: if (item.firstElementChild?.classList.contains("protyle-action")) { item.firstElementChild.insertAdjacentHTML("afterend", operation.data); cursorElements.push(item.firstElementChild.nextElementSibling); + } else if (item.classList.contains("callout")) { + item.querySelector(".callout-content").insertAdjacentHTML("afterbegin", operation.data); + cursorElements.push(item.querySelector('[data-node-id]')); } else { item.insertAdjacentHTML("afterbegin", operation.data); cursorElements.push(item.firstElementChild); @@ -923,14 +936,15 @@ export const turnsIntoOneTransaction = (options: { parentElement.classList.add("bq"); parentElement.setAttribute("data-node-id", id); parentElement.setAttribute("data-type", "NodeBlockquote"); - parentElement.innerHTML = '
'; + parentElement.innerHTML = `