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/6420
Vanessa905f02d8474a
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.jsonindex 41a0352903..8be1ae783c 100644--- a/app/appearance/langs/en_US.json+++ b/app/appearance/langs/en_US.json@@ -456,7 +456,8 @@"fontSize": "Font Size","fontSizeTip": "The default font size is 16px, this setting only affects the font size display in the editor","font1": "This setting only affects the font family display in the editor, choose <code class='fn__code'>Default</code> to use the theme's font family",- "newNameFile": "The name of the new document is",+ "newNameFile": "The name of the new subdocument is",+ "newNameSettingFile": "The name of the new document is","newContentFile": "The content of the new document is","exporting": "Exporting, please wait...","exported": "Export complete",diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.jsonindex 137a02e4ce..47650401a4 100644--- a/app/appearance/langs/es_ES.json+++ b/app/appearance/langs/es_ES.json@@ -455,7 +455,8 @@"fontSize": "Tamaño de la fuente","fontSizeTip": "El tamaño de la fuente por defecto es de 16px, este ajuste sólo afecta a la visualización del tamaño de la fuente en el editor","font1": "Este ajuste sólo afecta a la visualización de la familia de fuentes en el editor, elija <code class='fn__code'>Por defecto</code> para utilizar la familia de fuentes del tema",- "newNameFile": "El nombre del nuevo documento es",+ "newNameFile": "El nombre del nuevo subdocumento es",+ "newNameSettingFile": "El nombre del nuevo documento es","newContentFile": "El contenido del nuevo documento es","exporting": "Exportando, por favor espere...","exported": "Exportación completada",diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.jsonindex d881cc0b63..4b1af4445f 100644--- a/app/appearance/langs/fr_FR.json+++ b/app/appearance/langs/fr_FR.json@@ -456,7 +456,8 @@"fontSize": "Taille de la police","fontSizeTip": "La taille de la police par défaut est de 16px, ce paramètre n'affecte que la taille de la police affichée dans l'éditeur.","font1": "Ce paramètre n'affecte que l'affichage de la famille de polices dans l'éditeur, choisissez <code class='fn__code'>Default</code> pour utiliser la famille de polices du thème.",- "newNameFile": "Le nom du nouveau document est",+ "newNameFile": "Le nom du nouveau sous-document est",+ "newNameSettingFile": "Le nom du nouveau document est","newContentFile": "Le contenu du nouveau document est","exporting": "En cours d'exportation, veuillez patienter...","exported": "Exportation terminée",diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.jsonindex 4d2ff6d99d..ef9b679a57 100644--- a/app/appearance/langs/zh_CHT.json+++ b/app/appearance/langs/zh_CHT.json@@ -456,7 +456,8 @@"fontSize": "字型大小","fontSizeTip": "字型大小預設為 16px,該設置僅影響編輯器內字體大小顯示","font1": "該設置僅影響編輯器內字體顯示,選擇 <code class='fn__code'>預設</code> 則使用主題自帶字體",- "newNameFile": "新建文檔名為",+ "newNameFile": "新建子文檔名為",+ "newNameSettingFile": "新建文檔名為","newContentFile": "新建文檔內容為","exporting": "正在匯出,請稍等...","exported": "匯出完成",diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.jsonindex 36cc7ccab7..44f6789322 100644--- a/app/appearance/langs/zh_CN.json+++ b/app/appearance/langs/zh_CN.json@@ -456,7 +456,8 @@"fontSize": "字号","fontSizeTip": "字号默认为 16px,该设置仅影响编辑器内字体大小显示","font1": "该设置仅影响编辑器内字体显示,选择 <code class='fn__code'>默认</code> 则使用主题自带字体",- "newNameFile": "新建文档名为",+ "newNameFile": "新建子文档名为",+ "newNameSettingFile": "新建文档名为","newContentFile": "新建文档内容为","exporting": "正在导出,请稍等...","exported": "导出完成",diff --git a/app/src/constants.ts b/app/src/constants.tsindex 72b20e5aea..d691d50546 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -164,6 +164,7 @@ export abstract class Constants {rename: {default: "F2", custom: "F2"},newNameFile: {default: "F3", custom: "F3"},newContentFile: {default: "F4", custom: "F4"},+ newNameSettingFile: {default: "⌘F3", custom: "⌘F3"},showInFolder: {default: "⌥A", custom: "⌥A"},outline: {default: "⌥O", custom: "⌥O"},backlinks: {default: "⌥B", custom: "⌥B"},diff --git a/app/src/editor/rename.ts b/app/src/editor/rename.tsindex 70a6c0df64..d1e63e966e 100644--- a/app/src/editor/rename.ts+++ b/app/src/editor/rename.ts@@ -3,11 +3,9 @@ import {Dialog} from "../dialog";import {focusByRange} from "../protyle/util/selection";import {hasClosestBlock} from "../protyle/util/hasClosest";import {removeEmbed} from "../protyle/wysiwyg/removeEmbed";-import {insertHTML} from "../protyle/util/insertHTML";import {isMobile} from "../util/functions";import {getAssetName, getDisplayName, pathPosix, setNotebookName} from "../util/pathName";import {fetchPost} from "../util/fetch";-import {escapeHtml} from "../util/escape";import {Constants} from "../constants";import {showTooltip} from "../dialog/tooltip";@@ -175,16 +173,3 @@ export const newFileContentBySelect = (protyle: IProtyle) => {md: protyle.lute.BlockDOM2StdMd(html)});};--export const newFileBySelect = (fileName: string, protyle: IProtyle) => {- const newName = replaceFileName(fileName) || "Untitled";- const id = Lute.NewNodeID();- fetchPost("/api/filetree/createDoc", {- 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);- });-};diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex a7d4e44609..1039e49b5f 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -36,9 +36,9 @@ import {} from "./transaction";import {fontEvent} from "../toolbar/Font";import {listIndent, listOutdent} from "./list";-import {newFileBySelect, newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";+import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";import {insertEmptyBlock, jumpToParentNext} from "../../block/util";-import {isLocalPath} from "../../util/pathName";+import {getDisplayName, isLocalPath, pathPosix} from "../../util/pathName";/// #if !MOBILEimport {openBy, openFileById} from "../../editor/util";/// #endif@@ -67,6 +67,9 @@ import {openMobileFileById} from "../../mobile/editor";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";export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {@@ -690,7 +693,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const previousSibling = hasPreviousSibling(range.startContainer) as HTMLElement;if (range.toString() === "" && event.key === "Backspace" &&range.startOffset === range.startContainer.textContent.length &&- range.startContainer.textContent.endsWith("\n"+Constants.ZWSP)) {+ range.startContainer.textContent.endsWith("\n" + Constants.ZWSP)) {range.setStart(range.startContainer, range.startOffset - 1);range.collapse(true);event.stopPropagation();@@ -1044,7 +1047,41 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {if (!selectText.trim()) {selectAll(protyle, nodeElement, range);}- newFileBySelect(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML), protyle);+ const newName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML)) || "Untitled";+ const id = Lute.NewNodeID();+ fetchPost("/api/filetree/createDoc", {+ 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)+ });+ }+ 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()) {+ selectAll(protyle, nodeElement, range);+ }+ const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML));+ getSavePath(protyle.path, protyle.notebookId, (pathString) => {+ fetchPost("/api/filetree/createDocWithMd", {+ notebook: protyle.notebookId,+ path: pathPosix().join(pathString, 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();event.stopPropagation();