This commit is contained in:
Vanessa 2022-07-19 11:35:23 +08:00
parent 883049e80e
commit d87f7b0715
2 changed files with 32 additions and 8 deletions

View file

@ -209,7 +209,7 @@ const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IMod
focusBlock(nodeElement); focusBlock(nodeElement);
scrollCenter(editor.editor.protyle, nodeElement, true); scrollCenter(editor.editor.protyle, nodeElement, true);
} else if (editor.editor.protyle.block.rootID === options.id) { } 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) { } else if (editor.editor.protyle.toolbar.range) {
nodeElement = hasClosestBlock(editor.editor.protyle.toolbar.range.startContainer) as Element; nodeElement = hasClosestBlock(editor.editor.protyle.toolbar.range.startContainer) as Element;
focusByRange(editor.editor.protyle.toolbar.range); focusByRange(editor.editor.protyle.toolbar.range);
@ -326,6 +326,19 @@ export const updatePanelByEditor = (protyle?: IProtyle, focus = true, pushBackSt
setTitle(title); 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) => { const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => {
models.outline.find(item => { models.outline.find(item => {
if (reload || (item.type === "pin" && (!protyle || item.blockId !== protyle.block?.rootID))) { 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", { fetchPost("/api/outline/getDocOutline", {
id: blockId, id: blockId,
}, response => { }, response => {
if (!isCurrentEditor(blockId)) {
return;
}
item.update(response, blockId); item.update(response, blockId);
if (protyle) { if (protyle) {
item.updateDocTitle(protyle.background.ial); item.updateDocTitle(protyle.background.ial);
@ -388,8 +404,7 @@ export const updateBacklinkGraph = (models: IModels, protyle: IProtyle) => {
if (blockId === item.blockId) { if (blockId === item.blockId) {
return; return;
} }
item.blockId = blockId; item.searchGraph(true, blockId);
item.searchGraph(true);
} }
}); });
models.backlinks.forEach(item => { models.backlinks.forEach(item => {
@ -410,6 +425,9 @@ export const updateBacklinkGraph = (models: IModels, protyle: IProtyle) => {
k: item.inputsElement[0].value, k: item.inputsElement[0].value,
mk: item.inputsElement[1].value, mk: item.inputsElement[1].value,
}, response => { }, response => {
if (!isCurrentEditor(blockId)) {
return;
}
item.blockId = blockId; item.blockId = blockId;
item.render(response.data); item.render(response.data);
}); });

View file

@ -7,7 +7,7 @@ import {addScript} from "../../protyle/util/addScript";
import {BlockPanel} from "../../block/Panel"; import {BlockPanel} from "../../block/Panel";
import {fullscreen} from "../../protyle/breadcrumb/action"; import {fullscreen} from "../../protyle/breadcrumb/action";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
import {openFileById} from "../../editor/util"; import {isCurrentEditor, openFileById} from "../../editor/util";
import {updateHotkeyTip} from "../../protyle/util/compatibility"; import {updateHotkeyTip} from "../../protyle/util/compatibility";
declare const vis: any; declare const vis: any;
@ -401,9 +401,9 @@ export class Graph extends Model {
this.searchGraph(false); this.searchGraph(false);
} }
public searchGraph(focus: boolean) { public searchGraph(focus: boolean, id?: string) {
const element = this.element.querySelector('.block__icon[data-type="refresh"] svg'); 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; return;
} }
element.classList.add("fn__rotate"); element.classList.add("fn__rotate");
@ -448,17 +448,23 @@ export class Graph extends Model {
} else { } else {
fetchPost("/api/graph/getLocalGraph", { fetchPost("/api/graph/getLocalGraph", {
k: this.inputElement.value, k: this.inputElement.value,
id: this.blockId, id: id || this.blockId,
conf: { conf: {
type, type,
d3, d3,
dailyNote: (this.panelElement.querySelector("[data-type='dailyNote']") as HTMLInputElement).checked, dailyNote: (this.panelElement.querySelector("[data-type='dailyNote']") as HTMLInputElement).checked,
}, },
}, response => { }, response => {
element.classList.remove("fn__rotate");
if (id) {
this.blockId = id
}
if (!isCurrentEditor(this.blockId)) {
return;
}
this.graphData = response.data; this.graphData = response.data;
window.siyuan.config.graph.local = response.data.conf; window.siyuan.config.graph.local = response.data.conf;
this.onGraph(focus); this.onGraph(focus);
element.classList.remove("fn__rotate");
}); });
} }
} }