diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index d7843c7b8..4424d5c38 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -2326,6 +2326,7 @@ export class Gutter { const undoOperations: IOperation[] = []; const operations: IOperation[] = []; nodeElements.forEach((e) => { + e.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); undoOperations.push({ action: "update", id: e.getAttribute("data-node-id"), @@ -2334,6 +2335,7 @@ export class Gutter { }); inputElement.addEventListener(inputElement.type === "number" ? "blur" : "change", () => { nodeElements.forEach((e: HTMLElement) => { + e.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); operations.push({ action: "update", id: e.getAttribute("data-node-id"), diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts index 0772ca740..df5e17205 100644 --- a/app/src/protyle/hint/extend.ts +++ b/app/src/protyle/hint/extend.ts @@ -622,6 +622,7 @@ export const hintMoveBlock = (pathString: string, sourceElements: Element[], pro if (item.classList.contains("protyle-attr")) { return; } + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ action: "update", id: item.getAttribute("data-node-id"), diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index ec75841ce..40cdb261d 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -837,6 +837,7 @@ ${genHintItemHTML(item)} } nodeElement.insertAdjacentHTML("afterend", newHTML); const newId = newHTML.substr(newHTML.indexOf('data-node-id="') + 14, 22); + nodeElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); nodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${newId}"]`); // https://github.com/siyuan-note/siyuan/issues/6864 if (nodeElement.getAttribute("data-type") === "NodeTable") { diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 11ff857d4..332d0afec 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -1899,6 +1899,7 @@ export class Toolbar { highlightRender(nodeElement); } nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); + nodeElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ id, data: nodeElement.outerHTML, diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts index 8d612a5cf..c313d12f5 100644 --- a/app/src/protyle/util/insertHTML.ts +++ b/app/src/protyle/util/insertHTML.ts @@ -362,6 +362,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false, range.deleteContents(); } range.insertNode(document.createElement("wbr")); + blockElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); undoOperation.push({ action: "update", id, @@ -463,6 +464,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false, let addId = item.getAttribute("data-node-id"); const hasParentHeading = item.getAttribute("parent-heading"); if (addId === id) { + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperation.push({ action: "update", data: item.outerHTML, diff --git a/app/src/protyle/wysiwyg/callout.ts b/app/src/protyle/wysiwyg/callout.ts index faddd798e..f1f1a5ac2 100644 --- a/app/src/protyle/wysiwyg/callout.ts +++ b/app/src/protyle/wysiwyg/callout.ts @@ -75,6 +75,7 @@ export const updateCalloutType = (blockElements: HTMLElement[], protyle: IProtyl item.querySelector(".callout-title").innerHTML = title || (textElements[0].value.trim().substring(0, 1).toUpperCase() + textElements[0].value.trim().substring(1).toLowerCase()); item.querySelector(".callout-icon").innerHTML = dialogCalloutIconElement.innerHTML; + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ id, data: item.outerHTML, diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts index 549317b80..21ef7f7dd 100644 --- a/app/src/protyle/wysiwyg/commonHotkey.ts +++ b/app/src/protyle/wysiwyg/commonHotkey.ts @@ -388,6 +388,7 @@ export const duplicateBlock = async (nodeElements: Element[], protyle: IProtyle) }); nextElement.setAttribute("data-marker", starIndex + "."); nextElement.querySelector(".protyle-action--order").textContent = starIndex + "."; + nextElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ action: "update", data: nextElement.outerHTML, diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts index c43bf18df..61360e0f1 100644 --- a/app/src/protyle/wysiwyg/enter.ts +++ b/app/src/protyle/wysiwyg/enter.ts @@ -284,6 +284,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle if (item.dataset.nodeId === id) { blockElement.before(item); blockElement.remove(); + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperation.push({ action: "update", data: item.outerHTML, @@ -485,6 +486,7 @@ const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) = updateListOrder(listItemElement.parentElement); } if (listItemElement.parentElement.classList.contains("protyle-wysiwyg")) { + listItemElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); transaction(protyle, [{ action: "update", data: listItemElement.outerHTML, @@ -573,6 +575,7 @@ const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) = updateListOrder(listItemElement.parentElement); } if (listItemElement.parentElement.classList.contains("protyle-wysiwyg")) { + listItemElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); transaction(protyle, [{ action: "update", id: listItemElement.getAttribute("data-node-id"), diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts index 236dd3434..23cbd74eb 100644 --- a/app/src/protyle/wysiwyg/list.ts +++ b/app/src/protyle/wysiwyg/list.ts @@ -288,6 +288,7 @@ export const listIndent = (protyle: IProtyle, liItemElements: Element[], range: const count = index + 1 + "."; item.setAttribute("data-marker", count); item.querySelector(".protyle-action--order").textContent = count; + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ action: "update", id: itemId, @@ -682,6 +683,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: item.setAttribute("data-marker", "*"); item.removeAttribute("data-task"); item.classList.remove("protyle-task--done"); + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ action: "update", id: itemId, @@ -698,6 +700,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: item.setAttribute("data-subtype", "o"); item.setAttribute("data-marker", "1."); item.removeAttribute("data-task"); + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ action: "update", id: itemId, @@ -714,6 +717,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: item.setAttribute("data-subtype", "t"); item.setAttribute("data-marker", "*"); item.setAttribute("data-task", " "); + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ action: "update", id: itemId, diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts index 67f44281c..f6244c75b 100644 --- a/app/src/protyle/wysiwyg/remove.ts +++ b/app/src/protyle/wysiwyg/remove.ts @@ -578,6 +578,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang // extractContents 内容过多时需要进行滚动条重置,否则位置会错位 protyle.contentElement.scrollTop = scroll; protyle.scroll.lastScrollTop = scroll - 1; + previousLastElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); doOperations.push({ action: "update", data: previousLastElement.outerHTML, @@ -650,6 +651,8 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDele if (listElement.getAttribute("data-subtype") === "o") { updateListOrder(listElement); } + listElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); + previousLastElement.parentElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); transaction(protyle, [{ action: "update", id: listElement.getAttribute("data-node-id"), diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index b655acb38..99f82c3ff 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -1178,6 +1178,7 @@ export const turnsIntoTransaction = (options: { if (foldData && foldData.doOperations?.length > 0) { doOperations.push(...foldData.doOperations); } + item.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); undoOperations.push({ action: "update", id, @@ -1545,6 +1546,7 @@ export const updateBatchTransaction = (nodeElements: Element[], protyle: IProtyl data: element.outerHTML }); cb(element as HTMLElement); + element.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); operations.push({ action: "update", id, diff --git a/app/src/protyle/wysiwyg/turnIntoList.ts b/app/src/protyle/wysiwyg/turnIntoList.ts index 16b3235ff..bdc61d756 100644 --- a/app/src/protyle/wysiwyg/turnIntoList.ts +++ b/app/src/protyle/wysiwyg/turnIntoList.ts @@ -2,6 +2,7 @@ import {transaction, updateTransaction} from "./transaction"; import {focusByWbr} from "../util/selection"; import * as dayjs from "dayjs"; import {decodeHTML, escapeAttr} from "../../util/escape"; +import {Constants} from "../../constants"; export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: HTMLElement, editElement: HTMLElement, range: Range) => { const html = decodeHTML(editElement.innerHTML); @@ -52,6 +53,7 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: const liItemId = Lute.NewNodeID(); const oldHTML = blockElement.outerHTML; editElement.innerHTML = html.substring(contextStartIndex); + blockElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); transaction(protyle, [{ action: "update", id, @@ -98,6 +100,7 @@ export const headingTurnIntoList = (protyle: IProtyle, type: string, blockElemen const oldHTML = blockElement.outerHTML; const marker = editElement.innerHTML.substring(0, 1); editElement.innerHTML = editElement.innerHTML.substring(2); + blockElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); transaction(protyle, [{ action: "update", id,