From 286e87259bb4f597dea997ec189248eaf411f9d6 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 12 Dec 2022 00:26:40 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/6854 --- app/src/protyle/wysiwyg/keydown.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 1039e49b5..6b3cae866 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -1047,16 +1047,19 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (!selectText.trim()) { selectAll(protyle, nodeElement, range); } - const newName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML)) || "Untitled"; - const id = Lute.NewNodeID(); - fetchPost("/api/filetree/createDoc", { + const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML)) || "Untitled"; + fetchPost("/api/filetree/getHPathByPath", { notebook: protyle.notebookId, - path: pathPosix().join(getDisplayName(protyle.path, false, true), id + ".sy"), - title: newName, - md: "" - }, () => { - insertHTML(`${escapeHtml(newName.substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen))}`, protyle); - hideElements(["toolbar"], protyle) + path: protyle.path, + }, (response) => { + fetchPost("/api/filetree/createDocWithMd", { + notebook: protyle.notebookId, + path: pathPosix().join(response.data, newFileName), + markdown: "" + }, response => { + insertHTML(`${escapeHtml(newFileName.substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen))}`, protyle); + hideElements(["toolbar"], protyle) + }); }); } event.preventDefault(); @@ -1071,8 +1074,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (!selectText.trim()) { selectAll(protyle, nodeElement, range); } - const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML)); getSavePath(protyle.path, protyle.notebookId, (pathString) => { + const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML)) || "Untitled"; fetchPost("/api/filetree/createDocWithMd", { notebook: protyle.notebookId, path: pathPosix().join(pathString, newFileName),