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

View file

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

View file

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