mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
This commit is contained in:
parent
ae366b5c44
commit
c6d51b0362
2 changed files with 38 additions and 42 deletions
|
|
@ -13,6 +13,8 @@ import {replaceFileName, validateName} from "../editor/rename";
|
|||
import {hideElements} from "../protyle/ui/hideElements";
|
||||
import {openMobileFileById} from "../mobile/editor";
|
||||
import {App} from "../index";
|
||||
import {insertHTML} from "../protyle/util/insertHTML";
|
||||
import {escapeHtml} from "./escape";
|
||||
|
||||
export const getNewFilePath = (useSavePath: boolean) => {
|
||||
let notebookId = "";
|
||||
|
|
@ -192,3 +194,27 @@ export const newFileByName = (app: App, value: string) => {
|
|||
name: replaceFileName(value.trim()) || "Untitled"
|
||||
});
|
||||
};
|
||||
|
||||
export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeElement: HTMLElement, pathDir: string) => {
|
||||
const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML).replace(/\n/g, "")) || "Untitled";
|
||||
const hPath = pathPosix().join(pathDir, newFileName);
|
||||
fetchPost("/api/filetree/getIDsByHPath", {
|
||||
path: hPath,
|
||||
notebook: protyle.notebookId
|
||||
}, (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,
|
||||
path: hPath,
|
||||
parentID: protyle.block.rootID,
|
||||
markdown: ""
|
||||
}, response => {
|
||||
insertHTML(`<span data-type="block-ref" data-id="${response.data}" data-subtype="d">${refText}</span>`, protyle, false, true);
|
||||
});
|
||||
}
|
||||
hideElements(["toolbar"], protyle);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue