An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: fix https://github.com/siyuan-note/siyuan/issues/10091
Vanessac6d51b0362eb
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex b80bdd0bcd..66992d6ff7 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -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);});- });- }- 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);+ } else {+ getSavePath(protyle.path, protyle.notebookId, (pathString) => {+ newFileBySelect(protyle, selectText, nodeElement, pathString);});- });+ }}event.preventDefault();event.stopPropagation();diff --git a/app/src/util/newFile.ts b/app/src/util/newFile.tsindex cf5ad27173..db99efc6d0 100644--- a/app/src/util/newFile.ts+++ b/app/src/util/newFile.ts@@ -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);+ });+};