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;