From 2ec037010a03998c877d5dd721a57a14ec3b31f9 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 18 Aug 2022 16:59:12 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/5636 --- app/src/protyle/toolbar/index.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 5d31628f0..2d65790ee 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -1022,7 +1022,7 @@ export class Toolbar { fetchPost("/api/search/searchTemplate", { k: "", }, (response) => { - let html = ""; + let html = `
  • ${window.siyuan.languages.emptyContent}
  • `; response.data.blocks.forEach((item: { path: string, content: string }, index: number) => { html += `
    ${item.content}
    `; }); @@ -1038,9 +1038,16 @@ export class Toolbar { if (event.isComposing) { return; } - upDownHint(this.subElement.lastElementChild.lastElementChild as HTMLElement, event); + const isEmpty = !this.subElement.querySelector(".b3-list-item") + if (!isEmpty) { + upDownHint(this.subElement.lastElementChild.lastElementChild as HTMLElement, event); + } if (event.key === "Enter") { - hintRenderTemplate(decodeURIComponent(this.subElement.querySelector(".b3-list-item--focus").getAttribute("data-value")), protyle, nodeElement); + if (!isEmpty) { + hintRenderTemplate(decodeURIComponent(this.subElement.querySelector(".b3-list-item--focus").getAttribute("data-value")), protyle, nodeElement); + } else { + focusByRange(this.range); + } this.subElement.classList.add("fn__none"); event.preventDefault(); } else if (event.key === "Escape") { @@ -1053,7 +1060,7 @@ export class Toolbar { fetchPost("/api/search/searchTemplate", { k: inputElement.value, }, (response) => { - let searchHTML = ""; + let searchHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; response.data.blocks.forEach((item: { path: string, content: string }, index: number) => { searchHTML += `
    ${item.content}
    `; }); @@ -1062,6 +1069,11 @@ export class Toolbar { }); this.subElement.lastElementChild.addEventListener("click", (event) => { const target = event.target as HTMLElement; + if (target.classList.contains("b3-list--empty")) { + this.subElement.classList.add("fn__none"); + focusByRange(this.range); + return; + } const listElement = hasClosestByClassName(target, "b3-list-item"); if (!listElement) { return;