This commit is contained in:
Vanessa 2022-08-28 23:16:02 +08:00
parent f338c4016a
commit 87f681cce2
3 changed files with 26 additions and 2 deletions

View file

@ -2,7 +2,7 @@ import {Tab} from "../layout/Tab";
import {Editor} from "./index";
import {Wnd} from "../layout/Wnd";
import {getDockByType, getInstanceById, getWndByLayout} from "../layout/util";
import {getAllModels} from "../layout/getAll";
import {getAllModels, getAllTabs} from "../layout/getAll";
import {highlightById, scrollCenter} from "../util/highlightById";
import {getDisplayName, pathPosix} from "../util/pathName";
import {Constants} from "../constants";
@ -96,6 +96,29 @@ const openFile = (options: IOpenFileOptions) => {
switchEditor(editor, options, allModels);
return true;
}
// 没有初始化的页签无法检测到
const hasEditor = getAllTabs().find(item => {
const initData = item.headElement.getAttribute("data-initdata");
if (initData) {
const initObj = JSON.parse(initData);
if (initObj.rootID === options.rootID || initObj.blockId === options.rootID) {
initObj.blockId = options.id
initObj.mode = options.mode
if (options.zoomIn) {
initObj.action = [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS]
} else {
initObj.action = options.action
}
delete initObj.scrollAttr
item.headElement.setAttribute("data-initdata", JSON.stringify(initObj));
item.parent.switchTab(item.headElement);
return true;
}
}
});
if (hasEditor) {
return;
}
}
let wnd: Wnd = undefined;

View file

@ -318,7 +318,7 @@ export class Wnd {
tab: currentTab,
blockId: json.blockId,
mode: json.mode,
action: [json.action],
action: typeof json.action === "string" ? [json.action] : json.action,
scrollAttr: json.scrollAttr,
}));
currentTab.headElement.removeAttribute("data-initdata");

View file

@ -322,6 +322,7 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
json.instance = "Tab";
} else if (layout instanceof Editor) {
json.blockId = layout.editor.protyle.block.id;
json.rootID = layout.editor.protyle.block.rootID;
json.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";
json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";
json.instance = "Editor";