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 = `