This commit is contained in:
Vanessa 2022-12-12 00:26:40 +08:00
parent a19ec991b0
commit 286e87259b

View file

@ -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(`<span data-type="block-ref" data-id="${id}" data-subtype="d">${escapeHtml(newName.substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen))}</span>`, protyle);
hideElements(["toolbar"], protyle)
path: protyle.path,
}, (response) => {
fetchPost("/api/filetree/createDocWithMd", {
notebook: protyle.notebookId,
path: pathPosix().join(response.data, newFileName),
markdown: ""
}, response => {
insertHTML(`<span data-type="block-ref" data-id="${response.data}" data-subtype="d">${escapeHtml(newFileName.substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen))}</span>`, 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),