From 787476064291bba1e20164841ea04a8f69f200a9 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 20 Oct 2023 23:25:23 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/9462 --- app/src/protyle/header/Background.ts | 38 +++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/app/src/protyle/header/Background.ts b/app/src/protyle/header/Background.ts index cf9f0cefb..2a997d538 100644 --- a/app/src/protyle/header/Background.ts +++ b/app/src/protyle/header/Background.ts @@ -359,17 +359,7 @@ export class Background { break; } else if (type === "remove-tag") { target.parentElement.remove(); - const tags = this.getTags(); - fetchPost("/api/attr/setBlockAttrs", { - id: protyle.block.rootID, - attrs: {"tags": tags.toString()} - }); - if (tags.length === 0) { - delete this.ial.tags; - } else { - this.ial.tags = tags.toString(); - } - this.render(this.ial, protyle.block.rootID); + this.removeTag(protyle); event.preventDefault(); event.stopPropagation(); break; @@ -379,6 +369,20 @@ export class Background { }); } + private removeTag(protyle: IProtyle) { + const tags = this.getTags(); + fetchPost("/api/attr/setBlockAttrs", { + id: protyle.block.rootID, + attrs: {"tags": tags.toString()} + }); + if (tags.length === 0) { + delete this.ial.tags; + } else { + this.ial.tags = tags.toString(); + } + this.render(this.ial, protyle.block.rootID); + } + public render(ial: IObject, rootId: string) { const img = ial["title-img"]; const icon = ial.icon; @@ -502,18 +506,22 @@ export class Background { }); } - private getTags() { + private getTags(removeTag?: string) { const tags: string[] = []; this.tagsElement.querySelectorAll(".b3-chip").forEach(item => { - tags.push(item.textContent.trim()); + const tagText = item.textContent.trim(); + if (removeTag && tagText === removeTag) { + item.remove(); + } + tags.push(tagText); }); return tags; } private addTags(tag: string, protyle: IProtyle) { - window.siyuan.menus.menu.remove(); - const tags = this.getTags(); + const tags = this.getTags(tag); if (tags.includes(tag)) { + this.removeTag(protyle); return; } tags.push(tag);