From 4f9c1cb5269f5e3d06a3638bee2784c6e8f7b011 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 3 Oct 2022 17:00:57 +0800 Subject: [PATCH] :sparkles: fix https://github.com/siyuan-note/siyuan/issues/6053 --- app/src/editor/rename.ts | 6 +++--- app/src/protyle/wysiwyg/keydown.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/editor/rename.ts b/app/src/editor/rename.ts index 928fd3b02..b97ab7331 100644 --- a/app/src/editor/rename.ts +++ b/app/src/editor/rename.ts @@ -161,14 +161,14 @@ export const newFileContentBySelect = (protyle: IProtyle) => { }; export const newFileBySelect = (fileName: string, protyle: IProtyle) => { - fileName = replaceFileName(fileName); + const newName = replaceFileName(fileName) || "Untitled"; const id = Lute.NewNodeID(); fetchPost("/api/filetree/createDoc", { notebook: protyle.notebookId, path: pathPosix().join(getDisplayName(protyle.path, false, true), id + ".sy"), - title: fileName, + title: newName, md: "" }, () => { - insertHTML(genEmptyBlock(false, false, `${escapeHtml(fileName)}`), protyle); + insertHTML(genEmptyBlock(false, false, `${escapeHtml(newName)}`), protyle); }); }; diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index fb45f6116..72f9f3b70 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -996,8 +996,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { return; } - if (selectText.trim() && matchHotKey(window.siyuan.config.keymap.editor.general.newNameFile.custom, event)) { - newFileBySelect(selectText, protyle); + if (matchHotKey(window.siyuan.config.keymap.editor.general.newNameFile.custom, event)) { + newFileBySelect(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML), protyle); event.preventDefault(); event.stopPropagation(); return;