|
@@ -9,7 +9,7 @@ import {Constants} from "../constants";
|
|
import {setEditMode} from "../protyle/util/setEditMode";
|
|
import {setEditMode} from "../protyle/util/setEditMode";
|
|
import {Files} from "../layout/dock/Files";
|
|
import {Files} from "../layout/dock/Files";
|
|
import {setPadding} from "../protyle/ui/initUI";
|
|
import {setPadding} from "../protyle/ui/initUI";
|
|
-import {fetchPost} from "../util/fetch";
|
|
|
|
|
|
+import {fetchPost, fetchSyncPost} from "../util/fetch";
|
|
import {focusBlock, focusByRange} from "../protyle/util/selection";
|
|
import {focusBlock, focusByRange} from "../protyle/util/selection";
|
|
import {onGet} from "../protyle/util/onGet";
|
|
import {onGet} from "../protyle/util/onGet";
|
|
/// #if !BROWSER
|
|
/// #if !BROWSER
|
|
@@ -40,25 +40,24 @@ export const openFileById = async (options: {
|
|
removeCurrentTab?: boolean
|
|
removeCurrentTab?: boolean
|
|
afterOpen?: () => void
|
|
afterOpen?: () => void
|
|
}) => {
|
|
}) => {
|
|
- fetchPost("/api/block/getBlockInfo", {id: options.id}, (data) => {
|
|
|
|
- if (data.code === 3) {
|
|
|
|
- showMessage(data.msg);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- openFile({
|
|
|
|
- app: options.app,
|
|
|
|
- fileName: data.data.rootTitle,
|
|
|
|
- rootIcon: data.data.rootIcon,
|
|
|
|
- rootID: data.data.rootID,
|
|
|
|
- id: options.id,
|
|
|
|
- position: options.position,
|
|
|
|
- mode: options.mode,
|
|
|
|
- action: options.action,
|
|
|
|
- zoomIn: options.zoomIn,
|
|
|
|
- keepCursor: options.keepCursor,
|
|
|
|
- removeCurrentTab: options.removeCurrentTab,
|
|
|
|
- afterOpen: options.afterOpen
|
|
|
|
- });
|
|
|
|
|
|
+ const response = await fetchSyncPost("/api/block/getBlockInfo", {id: options.id});
|
|
|
|
+ if (response.code === 3) {
|
|
|
|
+ showMessage(response.msg);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ return openFile({
|
|
|
|
+ app: options.app,
|
|
|
|
+ fileName: response.data.rootTitle,
|
|
|
|
+ rootIcon: response.data.rootIcon,
|
|
|
|
+ rootID: response.data.rootID,
|
|
|
|
+ id: options.id,
|
|
|
|
+ position: options.position,
|
|
|
|
+ mode: options.mode,
|
|
|
|
+ action: options.action,
|
|
|
|
+ zoomIn: options.zoomIn,
|
|
|
|
+ keepCursor: options.keepCursor,
|
|
|
|
+ removeCurrentTab: options.removeCurrentTab,
|
|
|
|
+ afterOpen: options.afterOpen
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
@@ -97,7 +96,7 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
if (options.afterOpen) {
|
|
if (options.afterOpen) {
|
|
options.afterOpen();
|
|
options.afterOpen();
|
|
}
|
|
}
|
|
- return;
|
|
|
|
|
|
+ return asset.parent;
|
|
}
|
|
}
|
|
} else if (options.custom) {
|
|
} else if (options.custom) {
|
|
const custom = allModels.custom.find((item) => {
|
|
const custom = allModels.custom.find((item) => {
|
|
@@ -113,14 +112,14 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
if (options.afterOpen) {
|
|
if (options.afterOpen) {
|
|
options.afterOpen();
|
|
options.afterOpen();
|
|
}
|
|
}
|
|
- return;
|
|
|
|
|
|
+ return custom.parent;
|
|
}
|
|
}
|
|
const hasModel = getUnInitTab(options);
|
|
const hasModel = getUnInitTab(options);
|
|
if (hasModel) {
|
|
if (hasModel) {
|
|
if (options.afterOpen) {
|
|
if (options.afterOpen) {
|
|
options.afterOpen();
|
|
options.afterOpen();
|
|
}
|
|
}
|
|
- return;
|
|
|
|
|
|
+ return hasModel;
|
|
}
|
|
}
|
|
} else if (options.searchData) {
|
|
} else if (options.searchData) {
|
|
const search = allModels.search.find((item) => {
|
|
const search = allModels.search.find((item) => {
|
|
@@ -133,7 +132,7 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
if (search) {
|
|
if (search) {
|
|
- return;
|
|
|
|
|
|
+ return search.parent;
|
|
}
|
|
}
|
|
} else if (!options.position) {
|
|
} else if (!options.position) {
|
|
let editor: Editor;
|
|
let editor: Editor;
|
|
@@ -159,7 +158,7 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
if (options.afterOpen) {
|
|
if (options.afterOpen) {
|
|
options.afterOpen();
|
|
options.afterOpen();
|
|
}
|
|
}
|
|
- return true;
|
|
|
|
|
|
+ return editor.parent;
|
|
}
|
|
}
|
|
// 没有初始化的页签无法检测到
|
|
// 没有初始化的页签无法检测到
|
|
const hasEditor = getUnInitTab(options);
|
|
const hasEditor = getUnInitTab(options);
|
|
@@ -167,7 +166,7 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
if (options.afterOpen) {
|
|
if (options.afterOpen) {
|
|
options.afterOpen();
|
|
options.afterOpen();
|
|
}
|
|
}
|
|
- return;
|
|
|
|
|
|
+ return hasEditor;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -208,6 +207,7 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
|
|
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
|
|
}
|
|
}
|
|
if (wnd) {
|
|
if (wnd) {
|
|
|
|
+ let createdTab: Tab;
|
|
if ((options.position === "right" || options.position === "bottom") && wnd.children[0].headElement) {
|
|
if ((options.position === "right" || options.position === "bottom") && wnd.children[0].headElement) {
|
|
const direction = options.position === "right" ? "lr" : "tb";
|
|
const direction = options.position === "right" ? "lr" : "tb";
|
|
let targetWnd: Wnd;
|
|
let targetWnd: Wnd;
|
|
@@ -239,18 +239,21 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
});
|
|
});
|
|
if (!hasEditor) {
|
|
if (!hasEditor) {
|
|
hasEditor = getUnInitTab(options);
|
|
hasEditor = getUnInitTab(options);
|
|
|
|
+ createdTab = hasEditor;
|
|
}
|
|
}
|
|
if (!hasEditor) {
|
|
if (!hasEditor) {
|
|
- targetWnd.addTab(newTab(options));
|
|
|
|
|
|
+ createdTab = newTab(options);
|
|
|
|
+ targetWnd.addTab(createdTab);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- wnd.split(direction).addTab(newTab(options));
|
|
|
|
|
|
+ createdTab = newTab(options);
|
|
|
|
+ wnd.split(direction).addTab(createdTab);
|
|
}
|
|
}
|
|
wnd.showHeading();
|
|
wnd.showHeading();
|
|
if (options.afterOpen) {
|
|
if (options.afterOpen) {
|
|
options.afterOpen();
|
|
options.afterOpen();
|
|
}
|
|
}
|
|
- return;
|
|
|
|
|
|
+ return createdTab;
|
|
}
|
|
}
|
|
if (pdfIsLoading(wnd.element)) {
|
|
if (pdfIsLoading(wnd.element)) {
|
|
if (options.afterOpen) {
|
|
if (options.afterOpen) {
|
|
@@ -259,9 +262,9 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if (options.keepCursor && wnd.children[0].headElement) {
|
|
if (options.keepCursor && wnd.children[0].headElement) {
|
|
- const tab = newTab(options);
|
|
|
|
- tab.headElement.setAttribute("keep-cursor", options.id);
|
|
|
|
- wnd.addTab(tab, options.keepCursor);
|
|
|
|
|
|
+ createdTab = newTab(options);
|
|
|
|
+ createdTab.headElement.setAttribute("keep-cursor", options.id);
|
|
|
|
+ wnd.addTab(createdTab, options.keepCursor);
|
|
} else if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
|
} else if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
|
let unUpdateTab: Tab;
|
|
let unUpdateTab: Tab;
|
|
// 不能 reverse, 找到也不能提前退出循环,否则 https://github.com/siyuan-note/siyuan/issues/3271
|
|
// 不能 reverse, 找到也不能提前退出循环,否则 https://github.com/siyuan-note/siyuan/issues/3271
|
|
@@ -274,17 +277,20 @@ export const openFile = (options: IOpenFileOptions) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- wnd.addTab(newTab(options));
|
|
|
|
|
|
+ createdTab = newTab(options)
|
|
|
|
+ wnd.addTab(createdTab);
|
|
if (unUpdateTab && options.removeCurrentTab) {
|
|
if (unUpdateTab && options.removeCurrentTab) {
|
|
wnd.removeTab(unUpdateTab.id, false, true, false);
|
|
wnd.removeTab(unUpdateTab.id, false, true, false);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- wnd.addTab(newTab(options));
|
|
|
|
|
|
+ createdTab = newTab(options)
|
|
|
|
+ wnd.addTab(createdTab);
|
|
}
|
|
}
|
|
wnd.showHeading();
|
|
wnd.showHeading();
|
|
if (options.afterOpen) {
|
|
if (options.afterOpen) {
|
|
options.afterOpen();
|
|
options.afterOpen();
|
|
}
|
|
}
|
|
|
|
+ return createdTab;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|