This commit is contained in:
Vanessa 2022-06-16 21:05:54 +08:00
parent 2aeb531d65
commit 7898a21d85
3 changed files with 17 additions and 8 deletions

View file

@ -385,6 +385,7 @@
font-weight: bold;
line-height: 1.625;
padding: 0 4px;
white-space: break-spaces;
&:empty:after {
content: attr(data-tip);

View file

@ -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 }) {

View file

@ -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 => {