diff --git a/app/src/block/popover.ts b/app/src/block/popover.ts index c44121540..6d477d03f 100644 --- a/app/src/block/popover.ts +++ b/app/src/block/popover.ts @@ -8,7 +8,7 @@ export const initBlockPopover = () => { let timeoutHide: number; // 编辑器内容块引用/backlinks/tag/bookmark/套娃中使用 document.addEventListener("mouseover", (event: MouseEvent & { target: HTMLElement }) => { - const aElement = hasClosestByAttribute(event.target, "data-type", "a", true)|| + const aElement = hasClosestByAttribute(event.target, "data-type", "a", true) || hasClosestByAttribute(event.target, "data-type", "tab-header") || hasClosestByClassName(event.target, "emojis__item") || hasClosestByClassName(event.target, "emojis__type"); @@ -98,6 +98,9 @@ export const initBlockPopover = () => { } }, 200); timeout = window.setTimeout(async () => { + if (hasClosestByClassName(event.target, "history__repo", true)) { + return; + } let popoverTargetElement = hasClosestByAttribute(event.target, "data-type", "block-ref") as HTMLElement || hasClosestByAttribute(event.target, "data-type", "virtual-block-ref") as HTMLElement; if (!popoverTargetElement) { diff --git a/app/src/constants.ts b/app/src/constants.ts index 179a5033a..e4e4b458c 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -53,6 +53,7 @@ export abstract class Constants { public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置 public static readonly CB_GET_CONTEXT = "cb-get-context"; // 包含上下文 public static readonly CB_GET_HTML = "cb-get-html"; // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位 + public static readonly CB_GET_HISTORY = "cb-get-history"; // 历史渲染 // localstorage public static readonly LOCAL_SEARCHEDATA = "local-searchedata"; diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 73172316b..bcff95167 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -375,7 +375,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { }; export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushBack = true, callback?: () => void) => { - const breadcrumbHLElement = protyle.breadcrumb.element.querySelector(".protyle-breadcrumb__item--active"); + const breadcrumbHLElement = protyle.breadcrumb?.element.querySelector(".protyle-breadcrumb__item--active"); if (breadcrumbHLElement && breadcrumbHLElement.getAttribute("data-node-id") === id) { if (id === protyle.block.rootID) { return; diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts index 2b7e4d8d6..a8e9352e2 100644 --- a/app/src/mobile/editor.ts +++ b/app/src/mobile/editor.ts @@ -51,7 +51,7 @@ export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) = mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0, }, getResponse => { onGet(getResponse, window.siyuan.mobileEditor.protyle, action); - window.siyuan.mobileEditor.protyle.breadcrumb.render(window.siyuan.mobileEditor.protyle); + window.siyuan.mobileEditor.protyle.breadcrumb?.render(window.siyuan.mobileEditor.protyle); }); window.siyuan.mobileEditor.protyle.undo.clear(); } else { diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts index 5dafcdfca..3b18947c6 100644 --- a/app/src/mobile/util/MobileBackFoward.ts +++ b/app/src/mobile/util/MobileBackFoward.ts @@ -67,7 +67,7 @@ const focusStack = (backStack: IBackStack) => { enableProtyle(protyle); } protyle.contentElement.scrollTop = backStack.scrollTop; - window.siyuan.mobileEditor.protyle.breadcrumb.render(protyle); + window.siyuan.mobileEditor.protyle.breadcrumb?.render(protyle); }); }; diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts index 2d3127e80..e371f51da 100644 --- a/app/src/mobile/util/touch.ts +++ b/app/src/mobile/util/touch.ts @@ -7,7 +7,7 @@ let yDiff: number; export const handleTouchEnd = () => { if (window.siyuan.mobileEditor) { - window.siyuan.mobileEditor.protyle.breadcrumb.show(); + window.siyuan.mobileEditor.protyle.breadcrumb?.show(); } if (!clientX || !clientY || navigator.userAgent.indexOf("iPhone") === -1) { diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 358e47714..6a13a91bd 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -584,7 +584,7 @@ export class Gutter { html += removeEmbed(item); }); writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd()); - protyle.breadcrumb.hide(); + protyle.breadcrumb?.hide(); removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0])); } else { focusByRange(getEditorRange(selectsElement[0])); @@ -605,7 +605,7 @@ export class Gutter { icon: "iconTrashcan", accelerator: "⌫", click: () => { - protyle.breadcrumb.hide(); + protyle.breadcrumb?.hide(); removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0])); } }).element); @@ -965,7 +965,7 @@ export class Gutter { if (isNotEditBlock(nodeElement)) { writeText(protyle.lute.BlockDOM2StdMd(removeEmbed(nodeElement)).trimEnd()); removeBlock(protyle, nodeElement, getEditorRange(nodeElement)); - protyle.breadcrumb.hide(); + protyle.breadcrumb?.hide(); } else { focusByRange(getEditorRange(nodeElement)); document.execCommand("cut"); @@ -985,7 +985,7 @@ export class Gutter { icon: "iconTrashcan", accelerator: "⌫", click: () => { - protyle.breadcrumb.hide(); + protyle.breadcrumb?.hide(); removeBlock(protyle, nodeElement, getEditorRange(nodeElement)); } }).element); diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index 6ca93f429..20d556065 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -50,7 +50,9 @@ class Protyle { }; this.protyle.hint = new Hint(this.protyle); - this.protyle.breadcrumb = new Breadcrumb(this.protyle); + if (mergedOptions.render.breadcrumb) { + this.protyle.breadcrumb = new Breadcrumb(this.protyle); + } /// #if !MOBILE if (mergedOptions.render.title) { this.protyle.title = new Title(this.protyle); @@ -62,8 +64,9 @@ class Protyle { this.protyle.element.innerHTML = ""; this.protyle.element.classList.add("protyle"); - this.protyle.element.appendChild(this.protyle.breadcrumb.element.parentElement); - + if (mergedOptions.render.breadcrumb) { + this.protyle.element.appendChild(this.protyle.breadcrumb.element.parentElement); + } this.protyle.undo = new Undo(); this.protyle.wysiwyg = new WYSIWYG(this.protyle); this.protyle.toolbar = new Toolbar(this.protyle); @@ -76,130 +79,131 @@ class Protyle { } this.init(); - this.protyle.ws = new Model({ - id: this.protyle.id, - type: "protyle", - msgCallback: (data) => { - switch (data.cmd) { - case "transactions": - data.data[0].doOperations.forEach((item: IOperation) => { - onTransaction(this.protyle, item, false); - }); - break; - case "heading2doc": - case "li2doc": - if (this.protyle.block.rootID === data.data.srcRootBlockID) { - const scrollTop = this.protyle.contentElement.scrollTop; - fetchPost("/api/filetree/getDoc", { - id: this.protyle.block.id, - size: Constants.SIZE_GET, - }, getResponse => { - onGet(getResponse, this.protyle); - /// #if !MOBILE - if (data.cmd === "heading2doc") { - // 文档标题互转后,需更新大纲 - updatePanelByEditor(this.protyle, false, false, true); - } - /// #endif - // 文档标题互转后,编辑区会跳转到开头 https://github.com/siyuan-note/siyuan/issues/2939 - setTimeout(() => { - this.protyle.contentElement.scrollTop = scrollTop; - this.protyle.scroll.lastScrollTop = scrollTop - 1; - }, Constants.TIMEOUT_BLOCKLOAD); + if (!options.action.includes(Constants.CB_GET_HISTORY)) { + this.protyle.ws = new Model({ + id: this.protyle.id, + type: "protyle", + msgCallback: (data) => { + switch (data.cmd) { + case "transactions": + data.data[0].doOperations.forEach((item: IOperation) => { + onTransaction(this.protyle, item, false); }); - } - break; - case "rename": - if (this.protyle.path === data.data.path) { - if (this.protyle.model) { - this.protyle.model.parent.updateTitle(data.data.title); + break; + case "heading2doc": + case "li2doc": + if (this.protyle.block.rootID === data.data.srcRootBlockID) { + const scrollTop = this.protyle.contentElement.scrollTop; + fetchPost("/api/filetree/getDoc", { + id: this.protyle.block.id, + size: Constants.SIZE_GET, + }, getResponse => { + onGet(getResponse, this.protyle); + /// #if !MOBILE + if (data.cmd === "heading2doc") { + // 文档标题互转后,需更新大纲 + updatePanelByEditor(this.protyle, false, false, true); + } + /// #endif + // 文档标题互转后,编辑区会跳转到开头 https://github.com/siyuan-note/siyuan/issues/2939 + setTimeout(() => { + this.protyle.contentElement.scrollTop = scrollTop; + this.protyle.scroll.lastScrollTop = scrollTop - 1; + }, Constants.TIMEOUT_BLOCKLOAD); + }); } - if (this.protyle.background) { - this.protyle.background.ial.title = data.data.title; + break; + case "rename": + if (this.protyle.path === data.data.path) { + if (this.protyle.model) { + this.protyle.model.parent.updateTitle(data.data.title); + } + if (this.protyle.background) { + this.protyle.background.ial.title = data.data.title; + } } - } - if (this.protyle.options.render.title && this.protyle.block.parentID === data.data.id) { - if (getSelection().rangeCount > 0 && this.protyle.element.contains(getSelection().getRangeAt(0).startContainer)) { - // 编辑中的不用更新 - } else { - this.protyle.title.setTitle(data.data.title); + if (this.protyle.options.render.title && this.protyle.block.parentID === data.data.id) { + if (getSelection().rangeCount > 0 && this.protyle.element.contains(getSelection().getRangeAt(0).startContainer)) { + // 编辑中的不用更新 + } else { + this.protyle.title.setTitle(data.data.title); + } } - } - // update ref - this.protyle.wysiwyg.element.querySelectorAll(`[data-type="block-ref"][data-id="${data.data.id}"]`).forEach(item => { - if (item.getAttribute("data-subtype") === "d") { - item.textContent = data.data.title; + // update ref + this.protyle.wysiwyg.element.querySelectorAll(`[data-type="block-ref"][data-id="${data.data.id}"]`).forEach(item => { + if (item.getAttribute("data-subtype") === "d") { + item.textContent = data.data.title; + } + }); + break; + case "moveDoc": + if (data.data.fromNotebook === this.protyle.notebookId && this.protyle.path === data.data.fromPath) { + this.protyle.path = data.data.newPath; + this.protyle.notebookId = data.data.toNotebook; } - }); - break; - case "moveDoc": - if (data.data.fromNotebook === this.protyle.notebookId && this.protyle.path === data.data.fromPath) { - this.protyle.path = data.data.newPath; - this.protyle.notebookId = data.data.toNotebook; - } - break; - case "unmount": - if (this.protyle.model && this.protyle.notebookId === data.data.box) { - this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false); - } - break; - case "remove": - if (this.protyle.model && (this.protyle.notebookId === data.data.box && - (!data.data.path || this.protyle.path.indexOf(getDisplayName(data.data.path, false, true)) === 0))) { - this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false); - } - break; - } - } - }); - - setPadding(this.protyle); - fetchPost("/api/filetree/getDoc", { - id: options.blockId, - k: options.key || "", - mode: (options.action && options.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0, // 0: 仅当前 ID(默认值),1:向上 2:向下,3:上下都加载,4:加载最后 - size: options.action?.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : Constants.SIZE_GET, - }, getResponse => { - onGet(getResponse, this.protyle, options.action, options.scrollAttr); - if (this.protyle.model) { - /// #if !MOBILE - if (options.action?.includes(Constants.CB_GET_FOCUS)) { - setPanelFocus(this.protyle.model.element.parentElement.parentElement); - } - updatePanelByEditor(this.protyle, false); - /// #endif - } - - // 需等待 getDoc 完成后再执行,否则在无页签的时候 updatePanelByEditor 会执行2次 - // 只能用 focusin,否则点击表格无法执行 - /// #if !MOBILE - this.protyle.wysiwyg.element.addEventListener("focusin", () => { - if (this.protyle && this.protyle.model) { - let needUpdate = true; - if (this.protyle.model.element.parentElement.parentElement.classList.contains("layout__wnd--active") && this.protyle.model.headElement.classList.contains("item--focus")) { - needUpdate = false; + break; + case "unmount": + if (this.protyle.model && this.protyle.notebookId === data.data.box) { + this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false); + } + break; + case "remove": + if (this.protyle.model && (this.protyle.notebookId === data.data.box && + (!data.data.path || this.protyle.path.indexOf(getDisplayName(data.data.path, false, true)) === 0))) { + this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false); + } + break; } - if (!needUpdate) { - return; - } - setPanelFocus(this.protyle.model.element.parentElement.parentElement); - updatePanelByEditor(this.protyle, false); - } else { - // 悬浮层应移除其余面板高亮,否则按键会被面板监听到 - document.querySelectorAll(".block__icons--active").forEach(item => { - item.classList.remove("block__icons--active"); - }); - document.querySelectorAll(".layout__wnd--active").forEach(item => { - item.classList.remove("layout__wnd--active"); - }); } }); - /// #endif - // 需等渲染完后再回调,用于定位搜索字段 https://github.com/siyuan-note/siyuan/issues/3171 - if (mergedOptions.after) { - mergedOptions.after(this); - } - }); + fetchPost("/api/filetree/getDoc", { + id: options.blockId, + k: options.key || "", + mode: (options.action && options.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0, // 0: 仅当前 ID(默认值),1:向上 2:向下,3:上下都加载,4:加载最后 + size: options.action?.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : Constants.SIZE_GET, + }, getResponse => { + onGet(getResponse, this.protyle, options.action, options.scrollAttr); + if (this.protyle.model) { + /// #if !MOBILE + if (options.action?.includes(Constants.CB_GET_FOCUS)) { + setPanelFocus(this.protyle.model.element.parentElement.parentElement); + } + updatePanelByEditor(this.protyle, false); + /// #endif + } + + // 需等待 getDoc 完成后再执行,否则在无页签的时候 updatePanelByEditor 会执行2次 + // 只能用 focusin,否则点击表格无法执行 + /// #if !MOBILE + this.protyle.wysiwyg.element.addEventListener("focusin", () => { + if (this.protyle && this.protyle.model) { + let needUpdate = true; + if (this.protyle.model.element.parentElement.parentElement.classList.contains("layout__wnd--active") && this.protyle.model.headElement.classList.contains("item--focus")) { + needUpdate = false; + } + if (!needUpdate) { + return; + } + setPanelFocus(this.protyle.model.element.parentElement.parentElement); + updatePanelByEditor(this.protyle, false); + } else { + // 悬浮层应移除其余面板高亮,否则按键会被面板监听到 + document.querySelectorAll(".block__icons--active").forEach(item => { + item.classList.remove("block__icons--active"); + }); + document.querySelectorAll(".layout__wnd--active").forEach(item => { + item.classList.remove("layout__wnd--active"); + }); + } + }); + /// #endif + // 需等渲染完后再回调,用于定位搜索字段 https://github.com/siyuan-note/siyuan/issues/3171 + if (mergedOptions.after) { + mergedOptions.after(this); + } + }); + setPadding(this.protyle); + } } public reload() { diff --git a/app/src/protyle/scroll/event.ts b/app/src/protyle/scroll/event.ts index 054670715..35820ffb2 100644 --- a/app/src/protyle/scroll/event.ts +++ b/app/src/protyle/scroll/event.ts @@ -35,7 +35,7 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => { showMessage(window.siyuan.languages.crossPageUse.replace("${}", updateHotkeyTip("⇧Click")), 9000); } - const panelContextElement = protyle.breadcrumb.element.parentElement.querySelector('[data-type="context"]'); + const panelContextElement = protyle.breadcrumb?.element.parentElement.querySelector('[data-type="context"]'); if (panelContextElement && !panelContextElement.classList.contains("ft__primary")) { // 悬浮窗需展开上下文后才能进行滚动 https://github.com/siyuan-note/siyuan/issues/2311 return; diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts index 27c6ec6fe..b4efe047b 100644 --- a/app/src/protyle/ui/initUI.ts +++ b/app/src/protyle/ui/initUI.ts @@ -19,7 +19,9 @@ export const initUI = (protyle: IProtyle) => { protyle.contentElement.appendChild(protyle.title.element); } protyle.contentElement.appendChild(protyle.wysiwyg.element); - scrollEvent(protyle, protyle.contentElement); + if (!protyle.options.action.includes(Constants.CB_GET_HISTORY)) { + scrollEvent(protyle, protyle.contentElement); + } protyle.element.append(protyle.contentElement); protyle.element.appendChild(protyle.preview.element); if (protyle.upload) { @@ -59,6 +61,9 @@ export const removeLoading = (protyle: IProtyle) => { }; export const setPadding = (protyle: IProtyle) => { + if (protyle.options.action.includes(Constants.CB_GET_HISTORY)) { + return; + } let min16 = 16; let min24 = 24; if (!isMobile()) { diff --git a/app/src/protyle/util/Options.ts b/app/src/protyle/util/Options.ts index 0695bc9cd..9ab6c0ae0 100644 --- a/app/src/protyle/util/Options.ts +++ b/app/src/protyle/util/Options.ts @@ -13,6 +13,7 @@ export class Options { title: false, gutter: true, scroll: false, + breadcrumb: true, breadcrumbDocName: false, breadcrumbContext: false }, diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index fb5cf9de9..7df5dc7cb 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -172,6 +172,10 @@ const setHTML = (options: { content: string, action?: string[], unScroll?: boole processRender(protyle.wysiwyg.element); highlightRender(protyle.wysiwyg.element); blockRender(protyle, protyle.wysiwyg.element); + if (options.action.includes(Constants.CB_GET_HISTORY)) { + disabledProtyle(protyle); + return; + } if (protyle.options.render.scroll) { protyle.scroll.update(protyle.block.blockCount, protyle); } @@ -265,7 +269,9 @@ const setHTML = (options: { content: string, action?: string[], unScroll?: boole if (options.action.includes(Constants.CB_GET_APPEND) || options.action.includes(Constants.CB_GET_BEFORE)) { return; } - protyle.breadcrumb.render(protyle); + if (protyle.options.render.breadcrumb) { + protyle.breadcrumb.render(protyle); + } }; /** 禁用编辑器 */ diff --git a/app/src/protyle/util/setEditMode.ts b/app/src/protyle/util/setEditMode.ts index 99971e7d1..4b89db52a 100644 --- a/app/src/protyle/util/setEditMode.ts +++ b/app/src/protyle/util/setEditMode.ts @@ -9,7 +9,9 @@ export const setEditMode = (protyle: IProtyle, type: TEditorMode) => { protyle.preview.element.classList.remove("fn__none"); protyle.contentElement.classList.add("fn__none"); protyle.scroll?.element.classList.add("fn__none"); - protyle.breadcrumb.element.classList.add("fn__none"); + if (protyle.options.render.breadcrumb) { + protyle.breadcrumb?.element.classList.add("fn__none"); + } protyle.preview.render(protyle); } else if (type === "wysiwyg") { setPadding(protyle); @@ -22,7 +24,9 @@ export const setEditMode = (protyle: IProtyle, type: TEditorMode) => { if (protyle.options.render.scroll) { protyle.scroll?.element.classList.remove("fn__none"); } - protyle.breadcrumb.element.classList.remove("fn__none"); + if (protyle.options.render.breadcrumb) { + protyle.breadcrumb?.element.classList.remove("fn__none"); + } } hideElements( ["gutter", "toolbar", "select", "hint", "util"], protyle); }; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index ec7b638b0..ac3b5a337 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -78,6 +78,9 @@ export class WYSIWYG { if (window.siyuan.config.editor.displayBookmarkIcon) { this.element.classList.add("protyle-wysiwyg--attr"); } + if (protyle.options.action.includes(Constants.CB_GET_HISTORY)) { + return; + } this.bindEvent(protyle); keydown(protyle, this.element); dropEvent(protyle, this.element); @@ -273,7 +276,9 @@ export class WYSIWYG { event.stopPropagation(); event.preventDefault(); - protyle.breadcrumb.hide(); + if (protyle.options.render.breadcrumb) { + protyle.breadcrumb.hide(); + } const range = getEditorRange(protyle.wysiwyg.element); let nodeElement = hasClosestBlock(range.startContainer); if (!nodeElement) { @@ -727,7 +732,7 @@ export class WYSIWYG { } else if (event.clientX < mostLeft) { x = mostLeft; } - const mostTop = rect.top + protyle.breadcrumb.element.parentElement.clientHeight; + const mostTop = rect.top + (protyle.options.render.breadcrumb?protyle.breadcrumb.element.parentElement.clientHeight:0); let mouseElement: Element; let moveCellElement: HTMLElement; @@ -1873,7 +1878,9 @@ export class WYSIWYG { } // 面包屑定位 - protyle.breadcrumb.render(protyle); + if (protyle.options.render.breadcrumb) { + protyle.breadcrumb.render(protyle); + } }); } } diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts index afdbf7250..799c60719 100644 --- a/app/src/types/protyle.d.ts +++ b/app/src/types/protyle.d.ts @@ -355,6 +355,7 @@ interface IOptions { title?: boolean gutter?: boolean scroll?: boolean + breadcrumb?: boolean breadcrumbDocName?: boolean breadcrumbContext?: boolean } diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts index 243205ab3..1074c3c86 100644 --- a/app/src/util/globalShortcut.ts +++ b/app/src/util/globalShortcut.ts @@ -91,7 +91,7 @@ export const globalShortcut = () => { } const eventPath0 = event.composedPath()[0] as HTMLElement; - if (eventPath0 && eventPath0.nodeType !== 3 && eventPath0.classList.contains("protyle-wysiwyg")) { + if (eventPath0 && eventPath0.nodeType !== 3 && eventPath0.classList.contains("protyle-wysiwyg") && eventPath0.style.paddingLeft) { // 光标在编辑器右边也需要进行显示 const mouseElement = document.elementFromPoint(eventPath0.getBoundingClientRect().left + parseInt(eventPath0.style.paddingLeft) + 13, event.clientY); const blockElement = hasClosestBlock(mouseElement); diff --git a/app/src/util/history.ts b/app/src/util/history.ts index 349b87be1..561680ba3 100644 --- a/app/src/util/history.ts +++ b/app/src/util/history.ts @@ -6,7 +6,10 @@ import {escapeHtml} from "./escape"; import {isMobile} from "./functions"; import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {renderAssetsPreview} from "../asset/renderAssets"; +import Protyle from "../protyle"; +import {onGet} from "../protyle/util/onGet"; +let historyEditor: Protyle const renderDoc = (element: HTMLElement, currentPage: number) => { const previousElement = element.querySelector('[data-type="docprevious"]'); const nextElement = element.querySelector('[data-type="docnext"]'); @@ -24,9 +27,13 @@ const renderDoc = (element: HTMLElement, currentPage: number) => { if (typeElement.value === "0") { opElement.removeAttribute("disabled") notebookElement.removeAttribute("disabled") + element.lastElementChild.lastElementChild.previousElementSibling.classList.add("fn__none"); + element.lastElementChild.lastElementChild.classList.remove("fn__none"); } else { opElement.setAttribute("disabled", "disabled") notebookElement.setAttribute("disabled", "disabled") + element.lastElementChild.lastElementChild.previousElementSibling.classList.remove("fn__none"); + element.lastElementChild.lastElementChild.classList.add("fn__none"); } fetchPost("/api/history/searchHistory", { notebook: notebookElement.value, @@ -41,7 +48,8 @@ const renderDoc = (element: HTMLElement, currentPage: number) => { nextElement.setAttribute("disabled", "disabled"); } if (response.data.histories.length === 0) { - element.lastElementChild.lastElementChild.innerHTML = ""; + element.lastElementChild.lastElementChild.previousElementSibling.classList.add("fn__none"); + element.lastElementChild.lastElementChild.classList.add("fn__none"); element.lastElementChild.firstElementChild.innerHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; return; } @@ -65,12 +73,12 @@ const renderDoc = (element: HTMLElement, currentPage: number) => { logsHTML += ""; if (index === 0) { if (typeElement.value === "1") { - element.lastElementChild.lastElementChild.innerHTML = renderAssetsPreview(item.items[0].path); + element.lastElementChild.lastElementChild.previousElementSibling.innerHTML = renderAssetsPreview(item.items[0].path); } else { fetchPost("/api/history/getDocHistoryContent", { historyPath: item.items[0].path }, (contentResponse) => { - element.lastElementChild.lastElementChild.innerHTML = contentResponse.data.content; + onGet(contentResponse, historyEditor.protyle, [Constants.CB_GET_HISTORY]); }); } } @@ -262,7 +270,8 @@ export const openHistory = () => { -
    +
    +