diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index de0c0f4ad..9af4c9f0c 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -61,7 +61,7 @@ import {popSearch} from "../mobile/menu/search"; import {showMessage} from "../dialog/message"; import {img3115} from "../boot/compatibleVersion"; import {hideTooltip} from "../dialog/tooltip"; -import {clearSelect} from "../protyle/util/clearSelect"; +import {clearSelect} from "../protyle/util/clear"; import {scrollCenter} from "../util/highlightById"; const renderAssetList = (element: Element, k: string, position: IPosition, exts: string[] = []) => { diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 6dd37ecd8..d0a79a37e 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -62,7 +62,7 @@ import {openFileById} from "../../editor/util"; import * as path from "path"; /// #endif import {checkFold} from "../../util/noRelyPCFunction"; -import {clearSelect} from "../util/clearSelect"; +import {clearSelect} from "../util/clear"; export class Gutter { public element: HTMLElement; diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index 16c4d895e..0e87428cc 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -36,7 +36,7 @@ import {fetchPost, fetchSyncPost} from "../../../util/fetch"; import {scrollCenter} from "../../../util/highlightById"; import {escapeHtml} from "../../../util/escape"; import {editGalleryItem, openGalleryItemMenu} from "./gallery/util"; -import {clearSelect} from "../../util/clearSelect"; +import {clearSelect} from "../../util/clear"; import {removeCompressURL} from "../../../util/image"; let foldTimeout: number; diff --git a/app/src/protyle/render/av/gallery/item.ts b/app/src/protyle/render/av/gallery/item.ts index d3b962f34..1c1a099b6 100644 --- a/app/src/protyle/render/av/gallery/item.ts +++ b/app/src/protyle/render/av/gallery/item.ts @@ -2,7 +2,7 @@ import {genCellValue, getTypeByCellElement, renderCell, renderCellAttr} from ".. import {fetchPost} from "../../../../util/fetch"; import {setPage} from "../row"; import {Constants} from "../../../../constants"; -import {clearSelect} from "../../../util/clearSelect"; +import {clearSelect} from "../../../util/clear"; export const insertGalleryItemAnimation = (options: { blockElement: HTMLElement; diff --git a/app/src/protyle/render/av/keydown.ts b/app/src/protyle/render/av/keydown.ts index a2d1a0f8d..35fd364ca 100644 --- a/app/src/protyle/render/av/keydown.ts +++ b/app/src/protyle/render/av/keydown.ts @@ -5,7 +5,7 @@ import {avContextmenu} from "./action"; import {hasClosestByClassName} from "../../util/hasClosest"; import {Constants} from "../../../constants"; import {upDownHint} from "../../../util/upDownHint"; -import {clearSelect} from "../../util/clearSelect"; +import {clearSelect} from "../../util/clear"; export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyle: IProtyle) => { if (!nodeElement.classList.contains("av") || !window.siyuan.menus.menu.element.classList.contains("fn__none")) { diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index c795de9cd..5702fdd4f 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -17,7 +17,7 @@ import {renderGallery} from "./gallery/render"; import {getFieldsByData, getViewIcon} from "./view"; import {openMenuPanel} from "./openMenuPanel"; import {getPageSize} from "./groups"; -import {clearSelect} from "../../util/clearSelect"; +import {clearSelect} from "../../util/clear"; import {showMessage} from "../../../dialog/message"; import {renderKanban} from "./kanban/render"; diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.ts index 86291db25..c64141cb7 100644 --- a/app/src/protyle/render/av/row.ts +++ b/app/src/protyle/render/av/row.ts @@ -7,7 +7,7 @@ import {fetchPost} from "../../../util/fetch"; import * as dayjs from "dayjs"; import {Constants} from "../../../constants"; import {insertGalleryItemAnimation} from "./gallery/item"; -import {clearSelect} from "../../util/clearSelect"; +import {clearSelect} from "../../util/clear"; import {isCustomAttr} from "./blockAttr"; export const getFieldIdByCellElement = (cellElement: Element, viewType: TAVView): string => { diff --git a/app/src/protyle/util/clearSelect.ts b/app/src/protyle/util/clear.ts similarity index 73% rename from app/src/protyle/util/clearSelect.ts rename to app/src/protyle/util/clear.ts index f010919cb..a805981ac 100644 --- a/app/src/protyle/util/clearSelect.ts +++ b/app/src/protyle/util/clear.ts @@ -1,4 +1,21 @@ import {updateHeader} from "../render/av/row"; +import {Constants} from "../../constants"; + +export const clearBlockElement = (element: Element) => { + element.classList.remove("protyle-wysiwyg--select", "protyle-wysiwyg--hl"); + element.removeAttribute(Constants.CUSTOM_RIFF_DECKS); + element.removeAttribute("refcount"); + element.querySelector(".protyle-attr--av")?.remove(); + element.querySelector(".protyle-attr--refcount")?.remove(); + element.removeAttribute("custom-avs"); + element.removeAttribute("av-names"); + debugger + element.getAttributeNames().forEach(attr => { + if (attr.startsWith("custom-sy-av-s-text-")) { + element.removeAttribute(attr); + } + }) +}; export const clearSelect = (types: ("av" | "img" | "cell" | "row" | "galleryItem")[], element: Element) => { if (types.includes("cell")) { diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts index a60afc39f..30eb9fec6 100644 --- a/app/src/protyle/util/editorCommonEvent.ts +++ b/app/src/protyle/util/editorCommonEvent.ts @@ -34,7 +34,7 @@ import {webUtils} from "electron"; import {addDragFill, getTypeByCellElement} from "../render/av/cell"; import {processClonePHElement} from "../render/util"; import {insertGalleryItemAnimation} from "../render/av/gallery/item"; -import {clearSelect} from "./clearSelect"; +import {clearSelect} from "./clear"; import {dragoverTab} from "../render/av/view"; // position: afterbegin 为拖拽成超级块; "afterend", "beforebegin" 一般拖拽 diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 1b605b494..f39a3c98a 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -14,6 +14,7 @@ import {hideElements} from "../ui/hideElements"; import {avRender} from "../render/av/render"; import {cellScrollIntoView, getCellText} from "../render/av/cell"; import {getContenteditableElement} from "../wysiwyg/getBlock"; +import {clearBlockElement} from "./clear"; export const getTextStar = (blockElement: HTMLElement) => { const dataType = blockElement.dataset.type; @@ -407,13 +408,8 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven tempElement.querySelectorAll("[data-node-id]").forEach((e) => { const newId = Lute.NewNodeID(); e.setAttribute("data-node-id", newId); - e.removeAttribute(Constants.CUSTOM_RIFF_DECKS); e.classList.remove("protyle-wysiwyg--select", "protyle-wysiwyg--hl"); - e.setAttribute("updated", newId.split("-")[0]); - e.removeAttribute("refcount"); - e.querySelector(".protyle-attr--av")?.remove(); - e.removeAttribute("custom-avs"); - e.removeAttribute("av-names"); + clearBlockElement(e); isBlock = true; }); if (nodeElement.classList.contains("table")) { diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts index 11c4d733b..05438fd73 100644 --- a/app/src/protyle/wysiwyg/commonHotkey.ts +++ b/app/src/protyle/wysiwyg/commonHotkey.ts @@ -15,6 +15,7 @@ import {processClonePHElement} from "../render/util"; import {copyTextByType} from "../toolbar/util"; import {hasClosestByTag, hasTopClosestByClassName} from "../util/hasClosest"; import {removeEmbed} from "./removeEmbed"; +import {clearBlockElement} from "../util/clear"; export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement?: HTMLElement) => { if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) { @@ -313,25 +314,13 @@ export const duplicateBlock = async (nodeElements: Element[], protyle: IProtyle) focusElement = tempElement; } tempElement.setAttribute("data-node-id", newId); - tempElement.removeAttribute(Constants.CUSTOM_RIFF_DECKS); - tempElement.classList.remove("protyle-wysiwyg--hl"); tempElement.setAttribute("updated", newId.split("-")[0]); - tempElement.removeAttribute("refcount"); - tempElement.lastElementChild.querySelector(".protyle-attr--refcount")?.remove(); - tempElement.lastElementChild.querySelector(".protyle-attr--av")?.remove(); - tempElement.removeAttribute("custom-avs"); - tempElement.removeAttribute("av-names"); + clearBlockElement(tempElement); tempElement.querySelectorAll("[data-node-id]").forEach(childItem => { const subNewId = Lute.NewNodeID(); childItem.setAttribute("data-node-id", subNewId); - childItem.removeAttribute(Constants.CUSTOM_RIFF_DECKS); - childItem.classList.remove("protyle-wysiwyg--hl"); childItem.setAttribute("updated", subNewId.split("-")[0]); - childItem.removeAttribute("refcount"); - childItem.lastElementChild.querySelector(".protyle-attr--refcount")?.remove(); - childItem.lastElementChild.querySelector(".protyle-attr--av")?.remove(); - childItem.removeAttribute("custom-avs"); - childItem.removeAttribute("av-names"); + clearBlockElement(childItem); }); if (typeof starIndex === "number") { const orderIndex = starIndex + index + 1; @@ -360,19 +349,11 @@ export const duplicateBlock = async (nodeElements: Element[], protyle: IProtyle) } childItem.querySelectorAll("[data-node-id]").forEach(subItem => { subItem.setAttribute("data-node-id", Lute.NewNodeID()); - subItem.removeAttribute(Constants.CUSTOM_RIFF_DECKS); - subItem.removeAttribute("refcount"); - subItem.lastElementChild.querySelector(".protyle-attr--av")?.remove(); - subItem.removeAttribute("custom-avs"); - subItem.removeAttribute("av-names"); + clearBlockElement(subItem); }); const newChildId = Lute.NewNodeID(); childItem.setAttribute("data-node-id", newChildId); - childItem.removeAttribute(Constants.CUSTOM_RIFF_DECKS); - childItem.removeAttribute("refcount"); - childItem.lastElementChild.querySelector(".protyle-attr--av")?.remove(); - childItem.removeAttribute("custom-avs"); - childItem.removeAttribute("av-names"); + clearBlockElement(childItem); doOperations.push({ context: { ignoreProcess: "true" diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index c9ca0ca17..08699beb7 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -99,7 +99,7 @@ import {img3115} from "../../boot/compatibleVersion"; import {globalClickHideMenu} from "../../boot/globalEvent/click"; import {hideTooltip} from "../../dialog/tooltip"; import {openGalleryItemMenu} from "../render/av/gallery/util"; -import {clearSelect} from "../util/clearSelect"; +import {clearSelect} from "../util/clear"; import {chartRender} from "../render/chartRender"; export class WYSIWYG {