diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts index 322540858..d70619e7a 100644 --- a/app/src/protyle/hint/extend.ts +++ b/app/src/protyle/hint/extend.ts @@ -16,6 +16,7 @@ import {genEmptyElement} from "../../block/util"; import {updateListOrder} from "../wysiwyg/list"; import {escapeHtml} from "../../util/escape"; import {zoomOut} from "../../menus/protyle"; +import {hideElements} from "../ui/hideElements"; export const hintSlash = (key: string, protyle: IProtyle) => { const allList: IHintData[] = [{ @@ -413,14 +414,14 @@ export const hintRenderTemplate = (value: string, protyle: IProtyle, nodeElement blockRender(protyle, protyle.wysiwyg.element); processRender(protyle.wysiwyg.element); highlightRender(protyle.wysiwyg.element); - protyle.toolbar.subElement.classList.add("fn__none"); + hideElements(["util"], protyle); }); }; export const hintRenderWidget = (value: string, protyle: IProtyle) => { focusByRange(protyle.toolbar.range); insertHTML(protyle.lute.SpinBlockDOM(``), protyle, true); - protyle.toolbar.subElement.classList.add("fn__none"); + hideElements(["util"], protyle); }; export const hintRenderAssets = (value: string, protyle: IProtyle) => { @@ -438,7 +439,7 @@ export const hintRenderAssets = (value: string, protyle: IProtyle) => { fileMD += `[${value.startsWith("assets/") ? filename + type : value}](${value})`; } insertHTML(protyle.lute.SpinBlockDOM(fileMD), protyle); - protyle.toolbar.subElement.classList.add("fn__none"); + hideElements(["util"], protyle); }; export const hintMoveBlock = (pathString: string, sourceElements: Element[], protyle: IProtyle) => { @@ -505,5 +506,5 @@ export const hintMoveBlock = (pathString: string, sourceElements: Element[], pro // 跨文档不支持撤销 transaction(protyle, doOperations); - protyle.toolbar.subElement.classList.add("fn__none"); + hideElements(["util"], protyle); }; diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts index 542fa1d98..e4e5e98da 100644 --- a/app/src/protyle/toolbar/Font.ts +++ b/app/src/protyle/toolbar/Font.ts @@ -16,6 +16,7 @@ export class Font extends ToolbarItem { protyle.toolbar.subElement.style.padding = ""; protyle.toolbar.subElement.append(fontMenu(protyle)); protyle.toolbar.subElement.classList.remove("fn__none"); + protyle.toolbar.subElementCloseCB = undefined; const position = getSelectionPosition(protyle.wysiwyg.element, protyle.toolbar.range); setPosition(protyle.toolbar.subElement, position.left, position.top + 18, 26); }); diff --git a/app/src/protyle/toolbar/InlineMemo.ts b/app/src/protyle/toolbar/InlineMemo.ts index 7c2b92911..ae551beca 100644 --- a/app/src/protyle/toolbar/InlineMemo.ts +++ b/app/src/protyle/toolbar/InlineMemo.ts @@ -38,10 +38,7 @@ export class InlineMemo extends ToolbarItem { if (!["DIV", "TD", "TH", "TR"].includes(range.endContainer.parentElement.tagName) && range.endOffset === range.endContainer.textContent.length && !hasNextSibling(range.endContainer)) { range.setEndAfter(range.endContainer.parentElement); } - const wbrElement = document.createElement("wbr"); - range.insertNode(wbrElement); - const html = nodeElement.outerHTML; - + const oldHTML = nodeElement.outerHTML; const newNodes: Element[] = []; const contents = range.extractContents(); contents.childNodes.forEach((item: HTMLElement) => { @@ -82,10 +79,7 @@ export class InlineMemo extends ToolbarItem { } } range.setStart(newNodes[0].firstChild, 0); - protyle.toolbar.showRender(protyle, newNodes[0], newNodes); - nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); - updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html); - wbrElement.remove(); + protyle.toolbar.showRender(protyle, newNodes[0], newNodes, oldHTML); }); } } diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 930303887..506b5364a 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -46,6 +46,7 @@ import {InlineMemo} from "./InlineMemo"; export class Toolbar { public element: HTMLElement; public subElement: HTMLElement; + public subElementCloseCB: () => void; public range: Range; private toolbarHeight: number; @@ -593,23 +594,24 @@ export class Toolbar { } }); this.subElement.classList.remove("fn__none"); + this.subElementCloseCB = undefined; const nodeRect = refElement.getBoundingClientRect(); setPosition(this.subElement, nodeRect.left, nodeRect.bottom, nodeRect.height + 4); this.element.classList.add("fn__none"); anchorElement.select(); } - public showRender(protyle: IProtyle, renderElement: Element, updateElements?: Element[]) { + public showRender(protyle: IProtyle, renderElement: Element, updateElements?: Element[], oldHTML?: string) { const nodeElement = hasClosestBlock(renderElement); if (!nodeElement) { return; } const id = nodeElement.getAttribute("data-node-id"); - const type = renderElement.getAttribute("data-type"); - let html = protyle.lute.SpinBlockDOM(nodeElement.outerHTML); + const types = (renderElement.getAttribute("data-type") || "").split(" "); + const html = oldHTML || protyle.lute.SpinBlockDOM(nodeElement.outerHTML); let title = "HTML"; let placeholder = ""; - const isInlineMemo = type && type.split(" ").includes("inline-memo"); + const isInlineMemo = types.includes("inline-memo"); switch (renderElement.getAttribute("data-subtype")) { case "abc": title = window.siyuan.languages.staff; @@ -636,14 +638,14 @@ export class Toolbar { title = "UML"; break; case "math": - if (type === "NodeMathBlock") { + if (types.includes("NodeMathBlock")) { title = window.siyuan.languages.math; } else { title = window.siyuan.languages["inline-math"]; } break; } - if (type === "NodeBlockQueryEmbed") { + if (types.includes("NodeBlockQueryEmbed")) { title = window.siyuan.languages.blockEmbed; } else if (isInlineMemo) { title = window.siyuan.languages.memo; @@ -661,11 +663,11 @@ export class Toolbar { this.subElement.innerHTML = `