From d9813b016f92c22e89623ade98fef5083256d80e Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 25 Apr 2023 19:36:42 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/8098 --- app/src/boot/globalShortcut.ts | 2 +- app/src/dialog/processSystem.ts | 27 +++++++++++++++++++++++---- app/src/layout/dock/util.ts | 6 +++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/src/boot/globalShortcut.ts b/app/src/boot/globalShortcut.ts index 73f6666a9..a05df1099 100644 --- a/app/src/boot/globalShortcut.ts +++ b/app/src/boot/globalShortcut.ts @@ -1094,7 +1094,7 @@ const editKeydown = (event: KeyboardEvent) => { } if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event)) { fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => { - openCardByData(response.data, "doc", protyle.block.rootID, protyle.title.editElement.textContent); + openCardByData(response.data, "doc", protyle.block.rootID, protyle.title.editElement.textContent || "Untitled"); }); event.preventDefault(); return true; diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index b0ab1ec10..6c188c574 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -17,12 +17,22 @@ import {needSubscribe} from "../util/needSubscribe"; import {redirectToCheckAuth} from "../util/pathName"; import {getAllModels} from "../layout/getAll"; import {reloadProtyle} from "../protyle/util/reload"; +import {Tab} from "../layout/Tab"; -export const reloadSync = (data:{upsertRootIDs: string[], removeRootIDs: string[]}) => { + +const updateTitle = (rootID: string, tab: Tab) => { + fetchPost("/api/block/getDocInfo", { + id: rootID + }, (response) => { + tab.updateTitle(response.data.name) + }) +} +export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: string[] }) => { const allModels = getAllModels() allModels.editor.forEach(item => { if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) { - reloadProtyle(item.editor.protyle) + reloadProtyle(item.editor.protyle); + updateTitle(item.editor.protyle.block.rootID, item.parent); } else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) { item.parent.parent.removeTab(item.parent.id, false, false, false); } @@ -30,19 +40,25 @@ export const reloadSync = (data:{upsertRootIDs: string[], removeRootIDs: string[ allModels.graph.forEach(item => { if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) { item.parent.parent.removeTab(item.parent.id, false, false, false); - } else if (item.type !== "local" || data.upsertRootIDs.includes(item.rootId)){ + } else if (item.type !== "local" || data.upsertRootIDs.includes(item.rootId)) { item.searchGraph(false); + if (item.type === "local") { + updateTitle(item.rootId, item.parent); + } } }) allModels.outline.forEach(item => { if (item.type === "local" && data.removeRootIDs.includes(item.blockId)) { item.parent.parent.removeTab(item.parent.id, false, false, false); - } else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)){ + } else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) { fetchPost("/api/outline/getDocOutline", { id: item.blockId, }, response => { item.update(response); }); + if (item.type === "local") { + updateTitle(item.blockId, item.parent); + } } }) allModels.backlink.forEach(item => { @@ -50,6 +66,9 @@ export const reloadSync = (data:{upsertRootIDs: string[], removeRootIDs: string[ item.parent.parent.removeTab(item.parent.id, false, false, false); } else { item.refresh(); + if (item.type === "local") { + updateTitle(item.rootId, item.parent); + } } }) allModels.files.forEach(item => { diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.ts index 1a23b132f..bf75911b0 100644 --- a/app/src/layout/dock/util.ts +++ b/app/src/layout/dock/util.ts @@ -18,7 +18,7 @@ export const openBacklink = (protyle: IProtyle) => { const newWnd = protyle.model.parent.parent.split("lr"); const tab = new Tab({ icon: "iconLink", - title: protyle.title.editElement.textContent, + title: protyle.title.editElement.textContent || "Untitled", callback(tab: Tab) { tab.addModel(new Backlink({ type: "local", @@ -45,7 +45,7 @@ export const openGraph = (protyle: IProtyle) => { const wnd = protyle.model.parent.parent.split("lr"); const tab = new Tab({ icon: "iconGraph", - title: protyle.title.editElement.textContent, + title: protyle.title.editElement.textContent || "Untitled", callback(tab: Tab) { tab.addModel(new Graph({ type: "local", @@ -71,7 +71,7 @@ export const openOutline = (protyle: IProtyle) => { const newWnd = protyle.model.parent.parent.split("lr"); const tab = new Tab({ icon: "iconAlignCenter", - title: protyle.title.editElement.textContent, + title: protyle.title.editElement.textContent || "Untitled", callback(tab: Tab) { tab.addModel(new Outline({ type: "local",