diff --git a/app/src/asset/index.ts b/app/src/asset/index.ts index acdbfffba..bd71cd786 100644 --- a/app/src/asset/index.ts +++ b/app/src/asset/index.ts @@ -14,6 +14,7 @@ import {webViewerPageNumberChanged} from "./pdf/app"; import {fetchPost} from "../util/fetch"; import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility"; import {App} from "../index"; +import {clearOBG} from "../layout/dock/util"; export class Asset extends Model { public path: string; @@ -31,6 +32,7 @@ export class Asset extends Model { this.path = options.path; this.pdfId = options.page; this.element.addEventListener("click", (event) => { + clearOBG(); setPanelFocus(this.element.parentElement.parentElement); this.app.plugins.forEach(item => { item.eventBus.emit("click-pdf", {event}); diff --git a/app/src/card/newCardTab.ts b/app/src/card/newCardTab.ts index d5d0adcb0..49a9c0e22 100644 --- a/app/src/card/newCardTab.ts +++ b/app/src/card/newCardTab.ts @@ -5,6 +5,7 @@ import {fetchPost} from "../util/fetch"; import {Protyle} from "../protyle"; import {setPanelFocus} from "../layout/util"; import {App} from "../index"; +import {clearOBG} from "../layout/dock/util"; export const newCardModel = (options: { app: App, @@ -108,6 +109,7 @@ export const newCardModel = (options: { } }); customObj.element.addEventListener("click", () => { + clearOBG(); setPanelFocus(customObj.element.parentElement.parentElement); }); return customObj; diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index cf990aff7..2c0f8d16e 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -28,6 +28,7 @@ import {Search} from "../search"; import {App} from "../index"; import {newCardModel} from "../card/newCardTab"; import {preventScroll} from "../protyle/scroll/preventScroll"; +import {clearOBG} from "../layout/dock/util"; export const openFileById = async (options: { app: App, @@ -86,9 +87,14 @@ export const openFile = async (options: IOpenFileOptions) => { document.querySelectorAll(".av__panel, .av__mask").forEach(item => { item.remove(); }); + // 打开 PDF 时移除文档光标 + if (document.activeElement instanceof HTMLElement) { + document.activeElement.blur(); + } const allModels = getAllModels(); // 文档已打开 if (options.assetPath) { + clearOBG(); const asset = allModels.asset.find((item) => { if (item.path == options.assetPath) { if (!pdfIsLoading(item.parent.parent.element)) { @@ -106,6 +112,7 @@ export const openFile = async (options: IOpenFileOptions) => { return asset.parent; } } else if (options.custom) { + clearOBG(); const custom = allModels.custom.find((item) => { if (objEquals(item.data, options.custom.data) && (!options.custom.id || options.custom.id === item.type)) { if (!pdfIsLoading(item.parent.parent.element)) { @@ -129,6 +136,7 @@ export const openFile = async (options: IOpenFileOptions) => { return hasModel; } } else if (options.searchData) { + clearOBG(); const search = allModels.search.find((item) => { if (objEquals(item.config, options.searchData)) { if (!pdfIsLoading(item.parent.parent.element)) { @@ -547,14 +555,14 @@ export const isCurrentEditor = (blockId: string) => { 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 && - tab.model.editor.protyle.block.parentID !== blockId && // updateBacklinkGraph 时会传入 parentID - tab.model.editor.protyle.block.id !== blockId) { - return false; + if (tab.model.editor.protyle.block.rootID === blockId || + tab.model.editor.protyle.block.parentID === blockId || // updateBacklinkGraph 时会传入 parentID + tab.model.editor.protyle.block.id === blockId) { + return true; } } } - return true; + return false; }; export const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => { diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index 3d8641dc8..05ad3e1ba 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -40,6 +40,7 @@ import {newCenterEmptyTab, resizeTabs} from "./tabUtil"; import {fullscreen} from "../protyle/breadcrumb/action"; import {setPadding} from "../protyle/ui/initUI"; import {setPosition} from "../util/setPosition"; +import {clearOBG} from "./dock/util"; export class Wnd { private app: App; @@ -497,13 +498,7 @@ export class Wnd { setPadding(currentTab.model.editor.protyle); } } else { - updatePanelByEditor({ - protyle: undefined, - focus: false, - pushBackStack: false, - reload: false, - resize, - }); + clearOBG(); } if (isSaveLayout) { saveLayout(); @@ -721,13 +716,7 @@ export class Wnd { // 关闭分屏页签后光标消失 const editors = getAllModels().editor; if (editors.length === 0) { - updatePanelByEditor({ - protyle: undefined, - focus: true, - pushBackStack: false, - reload: false, - resize: true, - }); + clearOBG() } else { editors.forEach(item => { if (!item.element.classList.contains("fn__none")) { diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.ts index 91669de4f..d0e15b30c 100644 --- a/app/src/layout/dock/util.ts +++ b/app/src/layout/dock/util.ts @@ -196,3 +196,41 @@ export const toggleDockBar = (useElement: Element) => { resizeTabs(); resetFloatDockSize(); }; + +export const clearOBG = () => { + const models = getAllModels(); + models.outline.find(item => { + if (item.type === "pin") { + if ("" === item.blockId) { + return; + } + item.isPreview = false; + item.update({data: [], msg: "", code: 0}, ""); + item.updateDocTitle(); + } + }); + models.graph.forEach(item => { + if (item.type !== "global") { + if (item.type === "local") { + return; + } + if ("" === item.blockId) { + return; + } + item.blockId = ""; + item.graphData = undefined; + item.onGraph(false); + } + }); + models.backlink.forEach(item => { + if (item.type === "local") { + return; + } + if ("" === item.blockId) { + return; + } + item.saveStatus(); + item.blockId = ""; + item.render(undefined); + }); +} diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts index 301df2877..6a65cd60e 100644 --- a/app/src/plugin/index.ts +++ b/app/src/plugin/index.ts @@ -14,6 +14,7 @@ import {MobileCustom} from "../mobile/dock/MobileCustom"; import {hasClosestByAttribute} from "../protyle/util/hasClosest"; import {BlockPanel} from "../block/Panel"; import {Setting} from "./Setting"; +import {clearOBG} from "../layout/dock/util"; export class Plugin { private app: App; @@ -268,6 +269,7 @@ export class Plugin { update: options.update, }); customObj.element.addEventListener("click", () => { + clearOBG(); setPanelFocus(customObj.element.parentElement.parentElement); }); return customObj; diff --git a/app/src/search/index.ts b/app/src/search/index.ts index 34651f103..3c1f0dca2 100644 --- a/app/src/search/index.ts +++ b/app/src/search/index.ts @@ -4,6 +4,7 @@ import {Protyle} from "../protyle"; import {genSearch} from "./util"; import {setPanelFocus} from "../layout/util"; import {App} from "../index"; +import {clearOBG} from "../layout/dock/util"; export class Search extends Model { public element: HTMLElement; @@ -22,6 +23,7 @@ export class Search extends Model { this.config = options.config; this.editors = genSearch(options.app, this.config, this.element); this.element.addEventListener("click", () => { + clearOBG(); setPanelFocus(this.element.parentElement.parentElement); }); }