From 7898a21d85d5b4e3dbf4b0a634a423292d3947ca Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 16 Jun 2022 21:05:54 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/5202 --- app/src/assets/scss/_protyle.scss | 1 + app/src/protyle/header/Title.ts | 18 +++++++++++------- app/src/protyle/index.ts | 6 +++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/assets/scss/_protyle.scss b/app/src/assets/scss/_protyle.scss index 0774f150d..3f7d6a65d 100644 --- a/app/src/assets/scss/_protyle.scss +++ b/app/src/assets/scss/_protyle.scss @@ -385,6 +385,7 @@ font-weight: bold; line-height: 1.625; padding: 0 4px; + white-space: break-spaces; &:empty:after { content: attr(data-tip); diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 9e7863879..a245c68d8 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -30,6 +30,7 @@ import {code160to32} from "../util/code160to32"; export class Title { public element: HTMLElement; public editElement: HTMLElement; + private timeout: number constructor(protyle: IProtyle) { this.element = document.createElement("div"); @@ -228,16 +229,19 @@ export class Title { } private rename(protyle: IProtyle) { + clearTimeout(this.timeout) if (!validateName(this.editElement.textContent)) { return false; } - const fileName = replaceFileName(this.editElement.textContent); - fetchPost("/api/filetree/renameDoc", { - notebook: protyle.notebookId, - path: protyle.path, - title: fileName, - }); - this.setTitle(fileName) + this.timeout = window.setTimeout(() => { + const fileName = replaceFileName(this.editElement.textContent); + fetchPost("/api/filetree/renameDoc", { + notebook: protyle.notebookId, + path: protyle.path, + title: fileName, + }); + this.setTitle(fileName) + }, Constants.TIMEOUT_INPUT) } private renderMenu(protyle: IProtyle, iconElement: Element, position: { x: number, y: number }) { diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index a50c056f3..cf5812e71 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -108,7 +108,11 @@ class Protyle { this.protyle.model.parent.updateTitle(data.data.title); } if (this.protyle.options.render.title && this.protyle.block.parentID === data.data.id) { - this.protyle.title.setTitle(data.data.title); + if (getSelection().rangeCount > 0 && this.protyle.element.contains(getSelection().getRangeAt(0).startContainer)) { + // 编辑中的不用更新 + } else { + this.protyle.title.setTitle(data.data.title); + } } // update ref this.protyle.wysiwyg.element.querySelectorAll(`[data-type="block-ref"][data-id="${data.data.id}"]`).forEach(item => {