mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-19 02:21:38 +08:00
This commit is contained in:
parent
ae366b5c44
commit
c6d51b0362
@ -63,9 +63,7 @@ import {countBlockWord} from "../../layout/status";
|
||||
import {moveToDown, moveToUp} from "./move";
|
||||
import {pasteAsPlainText} from "../util/paste";
|
||||
import {preventScroll} from "../scroll/preventScroll";
|
||||
import {getSavePath} from "../../util/newFile";
|
||||
import {escapeHtml} from "../../util/escape";
|
||||
import {insertHTML} from "../util/insertHTML";
|
||||
import {getSavePath, newFileBySelect} from "../../util/newFile";
|
||||
import {removeSearchMark} from "../toolbar/util";
|
||||
import {avKeydown} from "../render/av/keydown";
|
||||
import {checkFold} from "../../util/noRelyPCFunction";
|
||||
@ -1021,7 +1019,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.newNameFile.custom, event)) {
|
||||
const isNewNameFile = matchHotKey(window.siyuan.config.keymap.editor.general.newNameFile.custom, event);
|
||||
if (isNewNameFile || matchHotKey(window.siyuan.config.keymap.editor.general.newNameSettingFile.custom, event)) {
|
||||
if (!selectText.trim() && (nodeElement.querySelector("tr") || nodeElement.querySelector("span"))) {
|
||||
// 没选中时,都是纯文本就创建子文档 https://ld246.com/article/1663073488381/comment/1664804353295#comments
|
||||
} else {
|
||||
@ -1030,47 +1029,18 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||
) {
|
||||
selectAll(protyle, nodeElement, range);
|
||||
}
|
||||
const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML).replace(/\n/g, "")) || "Untitled";
|
||||
fetchPost("/api/filetree/getHPathByPath", {
|
||||
notebook: protyle.notebookId,
|
||||
path: protyle.path,
|
||||
}, (response) => {
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
if (isNewNameFile) {
|
||||
fetchPost("/api/filetree/getHPathByPath", {
|
||||
notebook: protyle.notebookId,
|
||||
path: pathPosix().join(response.data, newFileName),
|
||||
parentID: protyle.block.rootID,
|
||||
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, false, true);
|
||||
hideElements(["toolbar"], protyle);
|
||||
path: protyle.path,
|
||||
}, (response) => {
|
||||
newFileBySelect(protyle, selectText, nodeElement, response.data);
|
||||
});
|
||||
} else {
|
||||
getSavePath(protyle.path, protyle.notebookId, (pathString) => {
|
||||
newFileBySelect(protyle, selectText, nodeElement, pathString);
|
||||
});
|
||||
});
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.newNameSettingFile.custom, event)) {
|
||||
if (!selectText.trim() && (nodeElement.querySelector("tr") || nodeElement.querySelector("span"))) {
|
||||
// 没选中时,都是纯文本就创建子文档 https://ld246.com/article/1663073488381/comment/1664804353295#comments
|
||||
} else {
|
||||
if (!selectText.trim() && getContenteditableElement(nodeElement).textContent) {
|
||||
selectAll(protyle, nodeElement, range);
|
||||
}
|
||||
getSavePath(protyle.path, protyle.notebookId, (pathString) => {
|
||||
const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML).replace(/\n/g, "")) || "Untitled";
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
notebook: protyle.notebookId,
|
||||
path: pathPosix().join(pathString, newFileName),
|
||||
parentID: protyle.block.rootID,
|
||||
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();
|
||||
event.stopPropagation();
|
||||
|
@ -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…
Reference in New Issue
Block a user