This commit is contained in:
Vanessa 2022-11-16 22:50:28 +08:00
parent a837d00520
commit 548491ba16

View file

@ -103,25 +103,7 @@ const openFile = (options: IOpenFileOptions) => {
return true; return true;
} }
// 没有初始化的页签无法检测到 // 没有初始化的页签无法检测到
const hasEditor = getAllTabs().find(item => { const hasEditor = getUnInitTab(options);
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) { if (hasEditor) {
return; return;
} }
@ -155,12 +137,15 @@ const openFile = (options: IOpenFileOptions) => {
} }
if (targetWnd) { if (targetWnd) {
// 在右侧/下侧打开已有页签将进行页签切换 https://github.com/siyuan-note/siyuan/issues/5366 // 在右侧/下侧打开已有页签将进行页签切换 https://github.com/siyuan-note/siyuan/issues/5366
const hasEditor = targetWnd.children.find(item => { let hasEditor = targetWnd.children.find(item => {
if (item.model && item.model instanceof Editor && item.model.editor.protyle.block.rootID === options.rootID) { if (item.model && item.model instanceof Editor && item.model.editor.protyle.block.rootID === options.rootID) {
switchEditor(item.model, options, allModels); switchEditor(item.model, options, allModels);
return true; return true;
} }
}); });
if (!hasEditor) {
hasEditor = getUnInitTab(options);
}
if (!hasEditor) { if (!hasEditor) {
targetWnd.addTab(newTab(options)); targetWnd.addTab(newTab(options));
} }
@ -194,6 +179,29 @@ const openFile = (options: IOpenFileOptions) => {
} }
}; };
// 没有初始化的页签无法检测到
const getUnInitTab = (options: IOpenFileOptions) => {
return 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;
}
}
});
}
const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IModels) => { const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IModels) => {
allModels.editor.forEach((item) => { allModels.editor.forEach((item) => {
if (!item.element.isSameNode(editor.element) && window.siyuan.editorIsFullscreen && item.element.classList.contains("fullscreen")) { if (!item.element.isSameNode(editor.element) && window.siyuan.editorIsFullscreen && item.element.classList.contains("fullscreen")) {