This commit is contained in:
parent
872b341d11
commit
905f02d847
8 changed files with 52 additions and 24 deletions
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -456,7 +456,8 @@
|
|||
"fontSize": "字型大小",
|
||||
"fontSizeTip": "字型大小預設為 16px,該設置僅影響編輯器內字體大小顯示",
|
||||
"font1": "該設置僅影響編輯器內字體顯示,選擇 <code class='fn__code'>預設</code> 則使用主題自帶字體",
|
||||
"newNameFile": "新建文檔名為",
|
||||
"newNameFile": "新建子文檔名為",
|
||||
"newNameSettingFile": "新建文檔名為",
|
||||
"newContentFile": "新建文檔內容為",
|
||||
"exporting": "正在匯出,請稍等...",
|
||||
"exported": "匯出完成",
|
||||
|
|
|
@ -456,7 +456,8 @@
|
|||
"fontSize": "字号",
|
||||
"fontSizeTip": "字号默认为 16px,该设置仅影响编辑器内字体大小显示",
|
||||
"font1": "该设置仅影响编辑器内字体显示,选择 <code class='fn__code'>默认</code> 则使用主题自带字体",
|
||||
"newNameFile": "新建文档名为",
|
||||
"newNameFile": "新建子文档名为",
|
||||
"newNameSettingFile": "新建文档名为",
|
||||
"newContentFile": "新建文档内容为",
|
||||
"exporting": "正在导出,请稍等...",
|
||||
"exported": "导出完成",
|
||||
|
|
|
@ -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"},
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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 !MOBILE
|
||||
import {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();
|
||||
|
|
Loading…
Add table
Reference in a new issue