diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 1426ee3c5..f96e2a3df 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -209,7 +209,7 @@ const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IMod focusBlock(nodeElement); scrollCenter(editor.editor.protyle, nodeElement, true); } else if (editor.editor.protyle.block.rootID === options.id) { - // 由于 https://github.com/siyuan-note/siyuan/issues/5420,移除定位 + // 由于 https://github.com/siyuan-note/siyuan/issues/5420,移除定位 } else if (editor.editor.protyle.toolbar.range) { nodeElement = hasClosestBlock(editor.editor.protyle.toolbar.range.startContainer) as Element; focusByRange(editor.editor.protyle.toolbar.range); @@ -326,6 +326,19 @@ export const updatePanelByEditor = (protyle?: IProtyle, focus = true, pushBackSt setTitle(title); }; +export const isCurrentEditor = (blockId: string) => { + const activeElement = document.querySelector('.layout__wnd--active > .layout-tab-bar > .item--focus') + if (activeElement) { + const tab = getInstanceById(activeElement.getAttribute("data-id")) + if (tab instanceof Tab && tab.model instanceof Editor) { + if (tab.model.editor.protyle.block.rootID !== blockId) { + return false; + } + } + } + return true +} + const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => { models.outline.find(item => { if (reload || (item.type === "pin" && (!protyle || item.blockId !== protyle.block?.rootID))) { @@ -339,6 +352,9 @@ const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => { fetchPost("/api/outline/getDocOutline", { id: blockId, }, response => { + if (!isCurrentEditor(blockId)) { + return; + } item.update(response, blockId); if (protyle) { item.updateDocTitle(protyle.background.ial); @@ -388,8 +404,7 @@ export const updateBacklinkGraph = (models: IModels, protyle: IProtyle) => { if (blockId === item.blockId) { return; } - item.blockId = blockId; - item.searchGraph(true); + item.searchGraph(true, blockId); } }); models.backlinks.forEach(item => { @@ -410,6 +425,9 @@ export const updateBacklinkGraph = (models: IModels, protyle: IProtyle) => { k: item.inputsElement[0].value, mk: item.inputsElement[1].value, }, response => { + if (!isCurrentEditor(blockId)) { + return; + } item.blockId = blockId; item.render(response.data); }); diff --git a/app/src/layout/dock/Graph.ts b/app/src/layout/dock/Graph.ts index 0df2c8b75..1c4efe3b8 100644 --- a/app/src/layout/dock/Graph.ts +++ b/app/src/layout/dock/Graph.ts @@ -7,7 +7,7 @@ import {addScript} from "../../protyle/util/addScript"; import {BlockPanel} from "../../block/Panel"; import {fullscreen} from "../../protyle/breadcrumb/action"; import {fetchPost} from "../../util/fetch"; -import {openFileById} from "../../editor/util"; +import {isCurrentEditor, openFileById} from "../../editor/util"; import {updateHotkeyTip} from "../../protyle/util/compatibility"; declare const vis: any; @@ -401,9 +401,9 @@ export class Graph extends Model { this.searchGraph(false); } - public searchGraph(focus: boolean) { + public searchGraph(focus: boolean, id?: string) { const element = this.element.querySelector('.block__icon[data-type="refresh"] svg'); - if (element.classList.contains("fn__rotate")) { + if (element.classList.contains("fn__rotate") && !id) { return; } element.classList.add("fn__rotate"); @@ -448,17 +448,23 @@ export class Graph extends Model { } else { fetchPost("/api/graph/getLocalGraph", { k: this.inputElement.value, - id: this.blockId, + id: id || this.blockId, conf: { type, d3, dailyNote: (this.panelElement.querySelector("[data-type='dailyNote']") as HTMLInputElement).checked, }, }, response => { + element.classList.remove("fn__rotate"); + if (id) { + this.blockId = id + } + if (!isCurrentEditor(this.blockId)) { + return; + } this.graphData = response.data; window.siyuan.config.graph.local = response.data.conf; this.onGraph(focus); - element.classList.remove("fn__rotate"); }); } }