diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 37011ae5e..a9134386f 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -34,6 +34,7 @@ import {App} from "../index"; import {newCardModel} from "../card/newCardTab"; import {preventScroll} from "../protyle/scroll/preventScroll"; import {clearOBG} from "../layout/dock/util"; +import {Model} from "../layout/Model"; export const openFileById = async (options: { app: App, @@ -44,7 +45,7 @@ export const openFileById = async (options: { keepCursor?: boolean zoomIn?: boolean removeCurrentTab?: boolean - afterOpen?: () => void + afterOpen?: (model:Model) => void }) => { const response = await fetchSyncPost("/api/block/getBlockInfo", {id: options.id}); if (response.code === -1) { @@ -112,7 +113,7 @@ export const openFile = async (options: IOpenFileOptions) => { }); if (asset) { if (options.afterOpen) { - options.afterOpen(); + options.afterOpen(asset); } return asset.parent; } @@ -129,14 +130,14 @@ export const openFile = async (options: IOpenFileOptions) => { }); if (custom) { if (options.afterOpen) { - options.afterOpen(); + options.afterOpen(custom); } return custom.parent; } const hasModel = getUnInitTab(options); if (hasModel) { if (options.afterOpen) { - options.afterOpen(); + options.afterOpen(hasModel.model); } return hasModel; } @@ -176,7 +177,7 @@ export const openFile = async (options: IOpenFileOptions) => { switchEditor(editor, options, allModels); } if (options.afterOpen) { - options.afterOpen(); + options.afterOpen(editor); } return editor.parent; } @@ -184,7 +185,7 @@ export const openFile = async (options: IOpenFileOptions) => { const hasEditor = getUnInitTab(options); if (hasEditor) { if (options.afterOpen) { - options.afterOpen(); + options.afterOpen(hasEditor.model); } return hasEditor; } @@ -268,7 +269,7 @@ export const openFile = async (options: IOpenFileOptions) => { } wnd.showHeading(); if (options.afterOpen) { - options.afterOpen(); + options.afterOpen(createdTab.model); } return createdTab; } @@ -305,7 +306,7 @@ export const openFile = async (options: IOpenFileOptions) => { } wnd.showHeading(); if (options.afterOpen) { - options.afterOpen(); + options.afterOpen(createdTab.model); } return createdTab; } diff --git a/app/src/layout/dock/Outline.ts b/app/src/layout/dock/Outline.ts index 91be8565e..d6198c087 100644 --- a/app/src/layout/dock/Outline.ts +++ b/app/src/layout/dock/Outline.ts @@ -11,11 +11,12 @@ import {openFileById} from "../../editor/util"; import {Constants} from "../../constants"; import {escapeHtml} from "../../util/escape"; import {unicode2Emoji} from "../../emoji"; -import {onGet} from "../../protyle/util/onGet"; import {getPreviousBlock} from "../../protyle/wysiwyg/getBlock"; import {App} from "../../index"; import {checkFold} from "../../util/noRelyPCFunction"; import {transaction} from "../../protyle/wysiwyg/transaction"; +import {goHome} from "../../protyle/wysiwyg/commonHotkey"; +import {Editor} from "../../editor"; export class Outline extends Model { public tree: Tree; @@ -166,12 +167,8 @@ export class Outline extends Model { setStorageVal(Constants.LOCAL_OUTLINE, window.siyuan.storage[Constants.LOCAL_OUTLINE]); }); options.tab.panelElement.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => { - if (this.type === "local") { - setPanelFocus(options.tab.panelElement.parentElement.parentElement); - } else { - setPanelFocus(options.tab.panelElement); - } let target = event.target as HTMLElement; + let isFocus = true; while (target && !target.isEqualNode(options.tab.panelElement)) { if (target.classList.contains("block__icon")) { const type = target.getAttribute("data-type"); @@ -182,30 +179,27 @@ export class Outline extends Model { } break; } else if (target.isSameNode(this.headerElement.nextElementSibling) || target.classList.contains("block__icons")) { - getAllModels().editor.find(item => { - if (this.blockId === item.editor.protyle.block.rootID) { - if (item.editor.protyle.scroll.element.classList.contains("fn__none")) { - item.editor.protyle.contentElement.scrollTop = 0; - } else { - fetchPost("/api/filetree/getDoc", { - id: item.editor.protyle.block.rootID, - mode: 0, - size: window.siyuan.config.editor.dynamicLoadBlocks, - }, getResponse => { - onGet({ - data: getResponse, - protyle: item.editor.protyle, - action: [Constants.CB_GET_FOCUS], - }); - }); + openFileById({ + app: options.app, + id: this.blockId, + afterOpen(model: Editor) { + if (model) { + goHome(model.editor.protyle); } - return true; } }); + isFocus = false; break; } target = target.parentElement; } + if (isFocus) { + if (this.type === "local") { + setPanelFocus(options.tab.panelElement.parentElement.parentElement); + } else { + setPanelFocus(options.tab.panelElement); + } + } }); this.bindSort(); if (this.isPreview) { diff --git a/app/src/plugin/API.ts b/app/src/plugin/API.ts index 20e25803a..2ce77f753 100644 --- a/app/src/plugin/API.ts +++ b/app/src/plugin/API.ts @@ -17,6 +17,7 @@ import {Menu} from "./Menu"; import {Protyle} from "../protyle"; import {openMobileFileById} from "../mobile/editor"; import {lockScreen} from "../dialog/processSystem"; +import {Model} from "../layout/Model"; let openTab; let openWindow; @@ -77,7 +78,7 @@ openTab = (options: { position?: "right" | "bottom", keepCursor?: boolean // 是否跳转到新 tab 上 removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签 - afterOpen?: () => void // 打开后回调 + afterOpen?: (model?: Model) => void // 打开后回调 }) => { if (options.doc) { if (options.doc.zoomIn) { diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index bfdc645b3..e19105269 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -552,7 +552,7 @@ interface IOpenFileOptions { keepCursor?: boolean // file,是否跳转到新 tab 上 zoomIn?: boolean // 是否缩放 removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签 - afterOpen?: () => void // 打开后回调 + afterOpen?: (model?: import("../layout/Model").Model) => void // 打开后回调 } interface ILayoutOptions {