Vanessa 2024-05-12 22:57:07 +08:00
parent 6bfdaf35e4
commit 84819beaf7
2 changed files with 24 additions and 5 deletions

View file

@ -621,6 +621,9 @@ ${genHintItemHTML(item)}
notebookId: protyle.notebookId,
useSavePath: true,
currentPath: protyle.path,
afterCB: (createDocId, createDocTitle) => {
insertHTML(`<span data-type="block-ref" data-id="${createDocId}" data-subtype="d">${createDocTitle}</span>`, protyle);
}
});
return;
} else if (value === Constants.ZWSP + 6) {
@ -632,7 +635,7 @@ ${genHintItemHTML(item)}
title: window.siyuan.languages.untitled,
md: ""
}, () => {
insertHTML(`<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`, protyle);
insertHTML(`<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">${window.siyuan.languages.untitled}</span>`, protyle);
/// #if MOBILE
openMobileFileById(protyle.app, newSubDocId, [Constants.CB_GET_CONTEXT, Constants.CB_GET_OPENNEW]);
/// #else

View file

@ -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