From b102219a130cef1d74e5c8486dfc132c18970a87 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 25 Apr 2024 23:41:05 +0800 Subject: [PATCH] :art: Supports specifying the notebook to save new docs https://github.com/siyuan-note/siyuan/issues/10671 --- app/src/menus/onGetnotebookconf.ts | 8 ++++---- app/src/util/newFile.ts | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/src/menus/onGetnotebookconf.ts b/app/src/menus/onGetnotebookconf.ts index db88c429f..a7de89d44 100644 --- a/app/src/menus/onGetnotebookconf.ts +++ b/app/src/menus/onGetnotebookconf.ts @@ -20,14 +20,14 @@ declare interface INotebookConf { } } -export const genNotebookOption = (id: string) => { +export const genNotebookOption = (id: string, notebookId?: string) => { let html = ``; const helpIds: string[] = []; Object.keys(Constants.HELP_PATH).forEach((key: "zh_CN") => { helpIds.push(Constants.HELP_PATH[key]); }); window.siyuan.notebooks.forEach((item) => { - if (helpIds.includes(item.id)) { + if (helpIds.includes(item.id) || item.id === notebookId) { return; } html += ``; @@ -45,7 +45,7 @@ export const onGetnotebookconf = (data: INotebookConf) => {
${window.siyuan.languages.fileTree13}
- +
@@ -55,7 +55,7 @@ export const onGetnotebookconf = (data: INotebookConf) => {
${window.siyuan.languages.fileTree6}
- +
diff --git a/app/src/util/newFile.ts b/app/src/util/newFile.ts index bc12bf090..36b8a5598 100644 --- a/app/src/util/newFile.ts +++ b/app/src/util/newFile.ts @@ -92,6 +92,9 @@ export const newFile = (optios: { optios.currentPath = resultData.currentPath; } fetchPost("/api/filetree/getDocCreateSavePath", {notebook: optios.notebookId}, (data) => { + if (!optios.useSavePath) { + data.data.box = optios.notebookId; + } if ((data.data.path.indexOf("/") > -1 && optios.useSavePath) || optios.name) { if (data.data.path.startsWith("/") || optios.currentPath === "/") { fetchPost("/api/filetree/createDocWithMd", { @@ -138,8 +141,27 @@ export const newFile = (optios: { if (!validateName(title)) { return; } + if (optios.notebookId !== data.data.box) { + fetchPost("/api/filetree/createDocWithMd", { + notebook: data.data.box, + path: pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")), + markdown: "" + }, response => { + /// #if !MOBILE + openFileById({ + app: optios.app, + id: response.data, + action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] + }); + /// #else + openMobileFileById(optios.app, response.data, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]); + /// #endif + }); + return; + } + const id = Lute.NewNodeID(); - const newPath = optios.notebookId === data.data.box ? (pathPosix().join(getDisplayName(optios.currentPath, false, true), id + ".sy")) : (data.data.path || "/"); + const newPath = (pathPosix().join(getDisplayName(optios.currentPath, false, true), id + ".sy")); if (optios.paths) { optios.paths[optios.paths.indexOf(undefined)] = newPath; }