Vanessa 2024-09-14 17:05:06 +08:00
parent 8ae79ed363
commit 8bb5c190b9
4 changed files with 29 additions and 33 deletions

View file

@ -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;
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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 {