From 9729b72a9e63314c886f3ab4e33c31c2b4ea8919 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 10 Apr 2025 11:34:20 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/14548 --- app/src/protyle/header/Background.ts | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/app/src/protyle/header/Background.ts b/app/src/protyle/header/Background.ts index ca40c1f22..f5f9be572 100644 --- a/app/src/protyle/header/Background.ts +++ b/app/src/protyle/header/Background.ts @@ -419,11 +419,15 @@ export class Background { }); } - private removeTag(protyle: IProtyle) { + private removeTag(protyle: IProtyle, cb?: () => void) { const tags = this.getTags(); fetchPost("/api/attr/setBlockAttrs", { id: protyle.block.rootID, attrs: {"tags": tags.toString()} + }, () => { + if (cb) { + cb(); + } }); if (tags.length === 0) { delete this.ial.tags; @@ -540,13 +544,10 @@ export class Background { upDownHint(listElement, event); if (event.key === "Enter") { const currentElement = listElement.querySelector(".b3-list-item--focus"); - if (currentElement) { - this.addTags(currentElement.textContent.trim(), protyle); - } else { - this.addTags(inputElement.value.trim(), protyle); - } - inputElement.value = ""; - inputElement.dispatchEvent(new CustomEvent("input")); + this.addTags(currentElement ? currentElement.textContent.trim() : inputElement.value.trim(), protyle, () => { + inputElement.value = ""; + inputElement.dispatchEvent(new CustomEvent("input")); + }); } else if (event.key === "Escape") { window.siyuan.menus.menu.remove(); } @@ -554,7 +555,7 @@ export class Background { inputElement.addEventListener("input", (event) => { event.stopPropagation(); fetchPost("/api/search/searchTag", { - k: inputElement.value, + k: inputElement.value.trim(), }, (response) => { let searchHTML = ""; let hasKey = false; @@ -569,7 +570,7 @@ export class Background { } }); if (!hasKey && response.data.k) { - searchHTML = `
${window.siyuan.languages.new} ${escapeHtml(response.data.k)}
` + searchHTML; + searchHTML = `
${window.siyuan.languages.new} ${escapeHtml(response.data.k)}
` + searchHTML; } listElement.innerHTML = searchHTML; }); @@ -580,8 +581,11 @@ export class Background { if (!listItemElement) { return; } - this.addTags(listItemElement.textContent.trim(), protyle); - inputElement.dispatchEvent(new CustomEvent("input")); + this.addTags(listItemElement.dataset.type === "new" ? listItemElement.querySelector("mark").textContent.trim() : listItemElement.textContent.trim(), + protyle, () => { + inputElement.value = ""; + inputElement.dispatchEvent(new CustomEvent("input")); + }); }); } }); @@ -609,16 +613,18 @@ export class Background { return tags; } - private addTags(tag: string, protyle: IProtyle) { + private addTags(tag: string, protyle: IProtyle, cb: () => void) { const tags = this.getTags(tag); if (tags.includes(tag)) { - this.removeTag(protyle); + this.removeTag(protyle, cb); return; } tags.push(tag); fetchPost("/api/attr/setBlockAttrs", { id: protyle.block.rootID, attrs: {"tags": tags.toString()} + }, () => { + cb(); }); this.ial.tags = tags.toString(); this.render(this.ial, protyle.block.rootID);