diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index 75e51a55c..e7ebffa3c 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -621,6 +621,9 @@ ${genHintItemHTML(item)} notebookId: protyle.notebookId, useSavePath: true, currentPath: protyle.path, + afterCB: (createDocId, createDocTitle) => { + insertHTML(`${createDocTitle}`, protyle); + } }); return; } else if (value === Constants.ZWSP + 6) { @@ -632,7 +635,7 @@ ${genHintItemHTML(item)} title: window.siyuan.languages.untitled, md: "" }, () => { - insertHTML(`Untitled`, protyle); + insertHTML(`${window.siyuan.languages.untitled}`, protyle); /// #if MOBILE openMobileFileById(protyle.app, newSubDocId, [Constants.CB_GET_CONTEXT, Constants.CB_GET_OPENNEW]); /// #else diff --git a/app/src/util/newFile.ts b/app/src/util/newFile.ts index 9b3542d3f..91b1957d0 100644 --- a/app/src/util/newFile.ts +++ b/app/src/util/newFile.ts @@ -80,7 +80,8 @@ export const newFile = (optios: { currentPath?: string, paths?: string[], useSavePath: boolean, - name?: string + name?: string, + afterCB?: (id: string, title: string) => void }) => { if (getOpenNotebookCount() === 0) { showMessage(window.siyuan.languages.newFileTip); @@ -97,12 +98,16 @@ export const newFile = (optios: { } if ((data.data.path.indexOf("/") > -1 && optios.useSavePath) || optios.name) { if (data.data.path.startsWith("/") || optios.currentPath === "/") { + const createPath = pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")) fetchPost("/api/filetree/createDocWithMd", { notebook: data.data.box, - path: pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")), + path: createPath, // 根目录时无法确定 parentID markdown: "" }, response => { + if (optios.afterCB) { + optios.afterCB(response.data, pathPosix().basename(createPath)); + } /// #if !MOBILE openFileById({ app: optios.app, @@ -118,12 +123,16 @@ export const newFile = (optios: { notebook: data.data.box, path: optios.notebookId === data.data.box ? (optios.currentPath.endsWith(".sy") ? optios.currentPath : optios.currentPath + ".sy") : (data.data.path || "/") }, (responseHPath) => { + const createPath = pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")) fetchPost("/api/filetree/createDocWithMd", { notebook: data.data.box, - path: pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")), + path: createPath, parentID: getDisplayName(optios.currentPath, true, true), markdown: "" }, response => { + if (optios.afterCB) { + optios.afterCB(response.data, pathPosix().basename(createPath)); + } /// #if !MOBILE openFileById({ app: optios.app, @@ -142,11 +151,15 @@ export const newFile = (optios: { return; } if (optios.notebookId !== data.data.box) { + const createPath = pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")) fetchPost("/api/filetree/createDocWithMd", { notebook: data.data.box, - path: pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")), + path: createPath, markdown: "" }, response => { + if (optios.afterCB) { + optios.afterCB(response.data, pathPosix().basename(createPath)); + } /// #if !MOBILE openFileById({ app: optios.app, @@ -172,6 +185,9 @@ export const newFile = (optios: { md: "", sorts: optios.paths }, () => { + if (optios.afterCB) { + optios.afterCB(id, title); + } /// #if !MOBILE openFileById({app: optios.app, id, action: [Constants.CB_GET_CONTEXT, Constants.CB_GET_OPENNEW]}); /// #else