This commit is contained in:
Vanessa 2023-04-14 23:02:44 +08:00
parent 671f182d5c
commit 2ee6b54bc7
3 changed files with 57 additions and 10 deletions

View File

@ -34,6 +34,7 @@ export const openFileById = async (options: {
keepCursor?: boolean
zoomIn?: boolean
removeCurrentTab?: boolean
afterOpen?: () => void
}) => {
fetchPost("/api/block/getBlockInfo", {id: options.id}, (data) => {
if (data.code === 3) {
@ -53,7 +54,8 @@ export const openFileById = async (options: {
action: options.action,
zoomIn: options.zoomIn,
keepCursor: options.keepCursor,
removeCurrentTab: options.removeCurrentTab
removeCurrentTab: options.removeCurrentTab,
afterOpen: options.afterOpen
});
});
};
@ -82,6 +84,9 @@ const openFile = (options: IOpenFileOptions) => {
}
});
if (asset) {
if (options.afterOpen) {
options.afterOpen();
}
return;
}
} else if (!options.position) {
@ -105,11 +110,17 @@ const openFile = (options: IOpenFileOptions) => {
if (!pdfIsLoading(editor.parent.parent.element)) {
switchEditor(editor, options, allModels);
}
if (options.afterOpen) {
options.afterOpen();
}
return true;
}
// 没有初始化的页签无法检测到
const hasEditor = getUnInitTab(options);
if (hasEditor) {
if (options.afterOpen) {
options.afterOpen();
}
return;
}
}
@ -134,6 +145,9 @@ const openFile = (options: IOpenFileOptions) => {
});
/// #endif
if (hasOpen) {
if (options.afterOpen) {
options.afterOpen();
}
return;
}
@ -165,6 +179,9 @@ const openFile = (options: IOpenFileOptions) => {
}
if (targetWnd) {
if (pdfIsLoading(targetWnd.element)) {
if (options.afterOpen) {
options.afterOpen();
}
return;
}
// 在右侧/下侧打开已有页签将进行页签切换 https://github.com/siyuan-note/siyuan/issues/5366
@ -184,9 +201,15 @@ const openFile = (options: IOpenFileOptions) => {
wnd.split(direction).addTab(newTab(options));
}
wnd.showHeading();
if (options.afterOpen) {
options.afterOpen();
}
return;
}
if (pdfIsLoading(wnd.element)) {
if (options.afterOpen) {
options.afterOpen();
}
return;
}
if (options.keepCursor && wnd.children[0].headElement) {
@ -213,6 +236,9 @@ const openFile = (options: IOpenFileOptions) => {
wnd.addTab(newTab(options));
}
wnd.showHeading();
if (options.afterOpen) {
options.afterOpen();
}
}
};

View File

@ -190,11 +190,15 @@ export class Files extends Model {
}
let target = event.target as HTMLElement;
while (target && !target.isEqualNode(this.element)) {
if (target.tagName === "LI") {
if (target.tagName === "LI" && !target.getAttribute("data-opening")) {
target.setAttribute("data-opening", "true")
openFileById({
removeCurrentTab: false,
id: target.getAttribute("data-node-id"),
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
afterOpen() {
target.removeAttribute("data-opening")
}
});
event.stopPropagation();
event.preventDefault();
@ -252,29 +256,45 @@ export class Files extends Model {
this.setCurrent(target, false);
if (target.getAttribute("data-type") === "navigation-file") {
needFocus = false;
if (target.getAttribute("data-opening")) {
return
}
target.setAttribute("data-opening", "true");
if (event.altKey && !event.metaKey && !event.ctrlKey && !event.shiftKey) {
openFileById({
id: target.getAttribute("data-node-id"),
position: "right",
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
afterOpen() {
target.removeAttribute("data-opening")
}
});
} else if (!event.altKey && !event.metaKey && !event.ctrlKey && event.shiftKey) {
openFileById({
id: target.getAttribute("data-node-id"),
position: "bottom",
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
afterOpen() {
target.removeAttribute("data-opening")
}
});
} else if (window.siyuan.config.fileTree.openFilesUseCurrentTab &&
event.altKey && (event.metaKey || event.ctrlKey) && !event.shiftKey) {
openFileById({
removeCurrentTab: false,
id: target.getAttribute("data-node-id"),
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
afterOpen() {
target.removeAttribute("data-opening")
}
});
} else {
openFileById({
id: target.getAttribute("data-node-id"),
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
afterOpen() {
target.removeAttribute("data-opening")
}
});
}
} else if (target.getAttribute("data-type") === "navigation-root") {
@ -562,7 +582,7 @@ export class Files extends Model {
if (hasMove) {
fetchPost("/api/filetree/listDocsByPath", {
notebook: toURL,
path: toDir === "/" ? "/" : toDir + ".sy",
path: toDir === "/" ? "/" : toDir + ".sy",
sort: window.siyuan.config.fileTree.sort,
}, response => {
if (response.data.path === "/" && response.data.files.length === 0) {
@ -998,7 +1018,7 @@ class="b3-list-item b3-list-item--hide-action" data-path="${item.path}">
}
}).element);
if (!window.siyuan.config.readonly) {
const subMenu = sortMenu("notebooks", window.siyuan.config.fileTree.sort, (sort: number) => {
const subMenu = sortMenu("notebooks", window.siyuan.config.fileTree.sort, (sort: number) => {
window.siyuan.config.fileTree.sort = sort;
fetchPost("/api/setting/setFiletree", {
sort: window.siyuan.config.fileTree.sort,
@ -1017,7 +1037,7 @@ class="b3-list-item b3-list-item--hide-action" data-path="${item.path}">
icon: "iconSort",
label: window.siyuan.languages.sort,
type: "submenu",
submenu:subMenu,
submenu: subMenu,
}).element);
}
return window.siyuan.menus.menu;

View File

@ -291,6 +291,7 @@ declare interface IOpenFileOptions {
keepCursor?: boolean // file是否跳转到新 tab 上
zoomIn?: boolean // 是否缩放
removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签
afterOpen?: () => void // 打开后回调
}
declare interface ILayoutOptions {