This commit is contained in:
Vanessa 2022-11-07 21:57:02 +08:00
parent cd82976170
commit a7d951856c
7 changed files with 1564 additions and 61 deletions

View file

@ -31,6 +31,7 @@ export const openFileById = (options: {
action?: string[]
keepCursor?: boolean
zoomIn?: boolean
removeCurrentTab?: boolean
}) => {
fetchPost("/api/block/getBlockInfo", {id: options.id}, (data) => {
if (data.code === 2) {
@ -41,13 +42,14 @@ export const openFileById = (options: {
openFile({
fileName: data.data.rootTitle,
rootIcon: data.data.rootIcon,
id: options.id,
rootID: data.data.rootID,
id: options.id,
position: options.position,
mode: options.mode,
action: options.action,
zoomIn: options.zoomIn,
keepCursor: options.keepCursor
keepCursor: options.keepCursor,
removeCurrentTab: options.removeCurrentTab
});
});
};
@ -178,8 +180,8 @@ const openFile = (options: IOpenFileOptions) => {
}
});
wnd.addTab(newTab(options));
if (unUpdateTab && !window.siyuan.ctrlIsPressed) {
wnd.removeTab(unUpdateTab.id);
if (unUpdateTab && options.removeCurrentTab) {
wnd.removeTab(unUpdateTab.id, false, true, false);
}
} else {
wnd.addTab(newTab(options));

View file

@ -231,17 +231,27 @@ export class Files extends Model {
break;
} else if (target.tagName === "LI") {
needFocus = false;
if (!event.metaKey && !event.ctrlKey) {
if ((event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey) {
setPanelFocus(this.element.parentElement);
target.classList.toggle("b3-list-item--focus");
} else {
this.setCurrent(target, false);
if (target.getAttribute("data-type") === "navigation-file") {
if (window.siyuan.altIsPressed) {
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]
});
} 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]
});
} else {
openFileById({
removeCurrentTab: !((event.altKey && (event.metaKey || event.ctrlKey) && !event.shiftKey)),
id: target.getAttribute("data-node-id"),
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
});
@ -250,9 +260,6 @@ export class Files extends Model {
this.getLeaf(target, notebookId);
setPanelFocus(this.element.parentElement);
}
} else {
setPanelFocus(this.element.parentElement);
target.classList.toggle("b3-list-item--focus");
}
this.element.querySelector('[select-end="true"]')?.removeAttribute("select-end");
this.element.querySelector('[select-start="true"]')?.removeAttribute("select-start");

View file

@ -266,6 +266,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
}, {
icon: "iconLayoutBottom",
label: window.siyuan.languages.insertBottom,
accelerator: "⇧Click",
click: () => {
openFileById({id, position: "bottom", action: [Constants.CB_GET_FOCUS]});
}
@ -273,14 +274,12 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
openSubmenus.push({
label: window.siyuan.languages.openInNewTab,
accelerator: "⌘Click",
accelerator: "⌘Click",
click: () => {
window.siyuan.ctrlIsPressed = true;
openFileById({id, action: [Constants.CB_GET_FOCUS]});
setTimeout(() => {
// 勾选在当前页签中打开后,右键在新页签中打开,不重置的话后续点击都会打开新页签
window.siyuan.ctrlIsPressed = false;
}, Constants.TIMEOUT_INPUT);
openFileById({
id, action: [Constants.CB_GET_FOCUS],
removeCurrentTab: false
});
}
});
}

View file

@ -211,6 +211,7 @@ declare interface IOpenFileOptions {
action?: string[]
keepCursor?: boolean // file是否跳转到新 tab 上
zoomIn?: boolean // 是否缩放
removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签
}
declare interface ILayoutOptions {