mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
This commit is contained in:
parent
c8a6d9db0b
commit
e37bfe027a
3 changed files with 18 additions and 17 deletions
|
|
@ -419,11 +419,11 @@ ${genHintItemHTML(item)}
|
|||
const realFileName = fileNames.length === 1 ? fileNames[0] : fileNames[1];
|
||||
const newID = Lute.NewNodeID();
|
||||
rowElement.dataset.id = newID;
|
||||
getSavePath(protyle.path, protyle.notebookId, (pathString) => {
|
||||
getSavePath(protyle.path, protyle.notebookId, (pathString, targetNotebookId) => {
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
notebook: protyle.notebookId,
|
||||
notebook: targetNotebookId,
|
||||
path: pathPosix().join(pathString, realFileName),
|
||||
parentID: protyle.block.rootID,
|
||||
parentID: protyle.notebookId === targetNotebookId ? protyle.block.rootID : "",
|
||||
markdown: "",
|
||||
id: newID,
|
||||
}, () => {
|
||||
|
|
@ -507,11 +507,11 @@ ${genHintItemHTML(item)}
|
|||
if (Constants.BLOCK_HINT_KEYS.includes(this.splitChar) && value.startsWith("((newFile ") && value.endsWith(`${Lute.Caret}'))`)) {
|
||||
const fileNames = value.substring(11, value.length - 4).split(`"${Constants.ZWSP}'`);
|
||||
const realFileName = fileNames.length === 1 ? fileNames[0] : fileNames[1];
|
||||
getSavePath(protyle.path, protyle.notebookId, (pathString) => {
|
||||
getSavePath(protyle.path, protyle.notebookId, (pathString, targetNotebookId) => {
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
notebook: protyle.notebookId,
|
||||
notebook: targetNotebookId,
|
||||
path: pathPosix().join(pathString, realFileName),
|
||||
parentID: protyle.block.rootID,
|
||||
parentID: protyle.notebookId === targetNotebookId ? protyle.block.rootID : "",
|
||||
markdown: ""
|
||||
}, response => {
|
||||
// https://github.com/siyuan-note/siyuan/issues/10133
|
||||
|
|
|
|||
|
|
@ -1026,11 +1026,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
notebook: protyle.notebookId,
|
||||
path: protyle.path,
|
||||
}, (response) => {
|
||||
newFileBySelect(protyle, selectText, nodeElement, response.data);
|
||||
newFileBySelect(protyle, selectText, nodeElement, response.data, protyle.notebookId);
|
||||
});
|
||||
} else {
|
||||
getSavePath(protyle.path, protyle.notebookId, (pathString) => {
|
||||
newFileBySelect(protyle, selectText, nodeElement, pathString);
|
||||
getSavePath(protyle.path, protyle.notebookId, (pathString, targetNotebookId) => {
|
||||
newFileBySelect(protyle, selectText, nodeElement, pathString, targetNotebookId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ export const newFile = (optios: {
|
|||
/// #endif
|
||||
});
|
||||
} else {
|
||||
// TODO
|
||||
fetchPost("/api/filetree/getHPathByPath", {
|
||||
notebook: data.data.box,
|
||||
path: optios.currentPath.endsWith(".sy") ? optios.currentPath : optios.currentPath + ".sy"
|
||||
|
|
@ -160,7 +161,7 @@ export const newFile = (optios: {
|
|||
});
|
||||
};
|
||||
|
||||
export const getSavePath = (pathString: string, notebookId: string, cb: (p: string) => void) => {
|
||||
export const getSavePath = (pathString: string, notebookId: string, cb: (p: string, notebookId: string) => void) => {
|
||||
fetchPost("/api/filetree/getRefCreateSavePath", {
|
||||
notebook: notebookId
|
||||
}, (data) => {
|
||||
|
|
@ -170,13 +171,13 @@ export const getSavePath = (pathString: string, notebookId: string, cb: (p: stri
|
|||
}
|
||||
if (data.data.path) {
|
||||
if (data.data.path.startsWith("/")) {
|
||||
cb(getDisplayName(data.data.path, false, true));
|
||||
cb(getDisplayName(data.data.path, false, true), data.data.box);
|
||||
} else {
|
||||
fetchPost("/api/filetree/getHPathByPath", {
|
||||
notebook: data.data.box,
|
||||
path: targetPath
|
||||
}, (response) => {
|
||||
cb(getDisplayName(pathPosix().join(response.data, data.data.path), false, true));
|
||||
cb(getDisplayName(pathPosix().join(response.data, data.data.path), false, true), data.data.box);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
|
@ -184,7 +185,7 @@ export const getSavePath = (pathString: string, notebookId: string, cb: (p: stri
|
|||
notebook: data.data.box,
|
||||
path: targetPath
|
||||
}, (response) => {
|
||||
cb(getDisplayName(response.data, false, true));
|
||||
cb(getDisplayName(response.data, false, true), data.data.box);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -199,21 +200,21 @@ export const newFileByName = (app: App, value: string) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeElement: HTMLElement, pathDir: string) => {
|
||||
export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeElement: HTMLElement, pathDir: string, targetNotebookId: string) => {
|
||||
const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML).replace(/\n/g, "")) || window.siyuan.languages.untitled;
|
||||
const hPath = pathPosix().join(pathDir, newFileName);
|
||||
fetchPost("/api/filetree/getIDsByHPath", {
|
||||
path: hPath,
|
||||
notebook: protyle.notebookId
|
||||
notebook: targetNotebookId
|
||||
}, (idResponse) => {
|
||||
const refText = escapeHtml(newFileName.substring(0, window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen));
|
||||
if (idResponse.data && idResponse.data.length > 0) {
|
||||
insertHTML(`<span data-type="block-ref" data-id="${idResponse.data[0]}" data-subtype="d">${refText}</span>`, protyle, false, true);
|
||||
} else {
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
notebook: protyle.notebookId,
|
||||
notebook: targetNotebookId,
|
||||
path: hPath,
|
||||
parentID: protyle.block.rootID,
|
||||
parentID: protyle.notebookId === targetNotebookId ? protyle.block.rootID : "",
|
||||
markdown: ""
|
||||
}, response => {
|
||||
insertHTML(`<span data-type="block-ref" data-id="${response.data}" data-subtype="d">${refText}</span>`, protyle, false, true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue