Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: fix https://github.com/siyuan-note/siyuan/issues/5202

Vanessa7898a21d85d5
diff --git a/app/src/assets/scss/_protyle.scss b/app/src/assets/scss/_protyle.scss
index 0774f150d3..3f7d6a65d8 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 9e7863879c..a245c68d85 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 a50c056f31..cf5812e710 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 => {