diff --git a/app/src/assets/scss/_protyle.scss b/app/src/assets/scss/_protyle.scss index 20bc4d6e3..0774f150d 100644 --- a/app/src/assets/scss/_protyle.scss +++ b/app/src/assets/scss/_protyle.scss @@ -394,10 +394,6 @@ &:focus { outline: none; } - - &--untitled { - color: var(--b3-theme-on-surface); - } } } diff --git a/app/src/editor/rename.ts b/app/src/editor/rename.ts index bc1ff5bcb..d0b4cf9e3 100644 --- a/app/src/editor/rename.ts +++ b/app/src/editor/rename.ts @@ -19,7 +19,7 @@ export const validateName = (name: string) => { }; export const replaceFileName = (name: string) => { - return name.replace(/\r\n|\r|\n|\u2028|\u2029|\t|\//g, "").trim(); + return name.replace(/\r\n|\r|\n|\u2028|\u2029|\t|\//g, ""); }; export const rename = (options: { @@ -130,7 +130,7 @@ export const newFileBySelect = (fileName: string, protyle: IProtyle) => { const id = Lute.NewNodeID(); fetchPost("/api/filetree/createDoc", { notebook: protyle.notebookId, - path: pathPosix().join(getDisplayName(protyle.path, false, true), id+ ".sy"), + path: pathPosix().join(getDisplayName(protyle.path, false, true), id + ".sy"), title: fileName, md: "" }, () => { diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 2e4e187c4..9e7863879 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -25,6 +25,7 @@ import {setTitle} from "../../dialog/processSystem"; import {getNoContainerElement} from "../wysiwyg/getBlock"; import {commonHotkey} from "../wysiwyg/commonHotkey"; import {setPosition} from "../../util/setPosition"; +import {code160to32} from "../util/code160to32"; export class Title { public element: HTMLElement; @@ -228,22 +229,15 @@ export class Title { private rename(protyle: IProtyle) { if (!validateName(this.editElement.textContent)) { - this.editElement.textContent = replaceFileName(this.editElement.textContent); return false; } - if (this.editElement.textContent.trim() === "" || this.editElement.textContent.trim() === window.siyuan.languages.untitled) { - this.editElement.textContent = window.siyuan.languages.untitled; - this.editElement.classList.add("protyle-title__input--untitled"); - } else { - this.editElement.classList.remove("protyle-title__input--untitled"); - } const fileName = replaceFileName(this.editElement.textContent); fetchPost("/api/filetree/renameDoc", { notebook: protyle.notebookId, path: protyle.path, title: fileName, }); - this.editElement.textContent = fileName; + this.setTitle(fileName) } private renderMenu(protyle: IProtyle, iconElement: Element, position: { x: number, y: number }) { @@ -333,6 +327,12 @@ ${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14)) }); } + public setTitle(title: string) { + if (code160to32(title) !== code160to32(this.editElement.textContent)) { + this.editElement.textContent = title === "Untitled" ? "" : title; + } + } + public render(protyle: IProtyle, refresh = false) { if (this.editElement.getAttribute("data-render") === "true" && !refresh) { return; @@ -344,12 +344,7 @@ ${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14)) protyle.background.render(response.data.ial, protyle.block.rootID); protyle.wysiwyg.renderCustom(response.data.ial); this.editElement.setAttribute("data-render", "true"); - this.editElement.textContent = response.data.ial.title; - if (response.data.ial.title === window.siyuan.languages.untitled) { - this.editElement.classList.add("protyle-title__input--untitled"); - } else { - this.editElement.classList.remove("protyle-title__input--untitled"); - } + this.setTitle(response.data.ial.title); let nodeAttrHTML = ""; if (response.data.ial.bookmark) { nodeAttrHTML += `