diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index fc3039058..12a30f08a 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -41,6 +41,7 @@ import {InlineMemo} from "./InlineMemo";
import {mathRender} from "../markdown/mathRender";
import {linkMenu} from "../../menus/protyle";
import {addScript} from "../util/addScript";
+import {confirmDialog} from "../../dialog/confirmDialog";
export class Toolbar {
public element: HTMLElement;
@@ -1333,12 +1334,13 @@ export class Toolbar {
html += `
${item.content}`;
/// #if !BROWSER
- html += `
+ html += `
-
`;
- /// #else
- html += "";
+`;
/// #endif
+ html += `
+
+`;
});
if (html === "") {
html = `${window.siyuan.languages.emptyContent}`;
@@ -1360,14 +1362,20 @@ export class Toolbar {
`;
const listElement = this.subElement.querySelector(".b3-list");
const previewElement = this.subElement.firstElementChild.lastElementChild;
- previewTemplate(listElement.firstElementChild.getAttribute("data-value"), previewElement, protyle.block.parentID);
+ let previewPath = listElement.firstElementChild.getAttribute("data-value")
+ previewTemplate(previewPath, previewElement, protyle.block.parentID);
listElement.addEventListener("mouseover", (event) => {
const target = event.target as HTMLElement;
const hoverItemElement = hasClosestByClassName(target, "b3-list-item");
if (!hoverItemElement) {
return;
}
- previewTemplate(hoverItemElement.getAttribute("data-value"), previewElement, protyle.block.parentID);
+ const currentPath = hoverItemElement.getAttribute("data-value")
+ if (previewPath === currentPath) {
+ return;
+ }
+ previewPath = currentPath
+ previewTemplate(previewPath, previewElement, protyle.block.parentID);
});
const inputElement = this.subElement.querySelector("input");
inputElement.addEventListener("keydown", (event: KeyboardEvent) => {
@@ -1379,7 +1387,12 @@ export class Toolbar {
if (!isEmpty) {
const currentElement = upDownHint(listElement, event);
if (currentElement) {
- previewTemplate(currentElement.getAttribute("data-value"), previewElement, protyle.block.parentID);
+ const currentPath = currentElement.getAttribute("data-value")
+ if (previewPath === currentPath) {
+ return;
+ }
+ previewPath = currentPath
+ previewTemplate(previewPath, previewElement, protyle.block.parentID);
}
}
if (event.key === "Enter") {
@@ -1405,7 +1418,12 @@ export class Toolbar {
searchHTML += `${item.content}
`;
});
listElement.innerHTML = searchHTML || `${window.siyuan.languages.emptyContent}`;
- previewTemplate(response.data.blocks[0]?.path, previewElement, protyle.block.parentID);
+ const currentPath = response.data.blocks[0]?.path
+ if (previewPath === currentPath) {
+ return;
+ }
+ previewPath = currentPath
+ previewTemplate(previewPath, previewElement, protyle.block.parentID);
});
});
this.subElement.lastElementChild.addEventListener("click", (event) => {
@@ -1416,14 +1434,38 @@ export class Toolbar {
event.stopPropagation();
return;
}
- /// #if !BROWSER
const iconElement = hasClosestByClassName(target, "b3-list-item__action");
- if (iconElement) {
+ /// #if !BROWSER
+ if (iconElement && iconElement.getAttribute("data-type") === "open") {
openBy(iconElement.parentElement.getAttribute("data-value"), "folder");
event.stopPropagation();
return;
}
/// #endif
+ if (iconElement && iconElement.getAttribute("data-type") === "remove") {
+ confirmDialog(window.siyuan.languages.remove, window.siyuan.languages.confirmDelete + "?", () => {
+ fetchPost("/api/search/removeTemplate", {path: iconElement.parentElement.getAttribute("data-value")}, () => {
+ if (iconElement.parentElement.parentElement.childElementCount === 1) {
+ iconElement.parentElement.parentElement.innerHTML = `${window.siyuan.languages.emptyContent}`;
+ previewTemplate("", previewElement, protyle.block.parentID);
+ } else {
+ if (iconElement.parentElement.classList.contains("b3-list-item--focus")) {
+ const sideElement = iconElement.parentElement.previousElementSibling || iconElement.parentElement.nextElementSibling;
+ sideElement.classList.add("b3-list-item--focus");
+ const currentPath = sideElement.getAttribute("data-value")
+ if (previewPath === currentPath) {
+ return;
+ }
+ previewPath = currentPath
+ previewTemplate(previewPath, previewElement, protyle.block.parentID);
+ }
+ iconElement.parentElement.remove();
+ }
+ });
+ });
+ event.stopPropagation();
+ return;
+ }
const previousElement = hasClosestByAttribute(target, "data-type", "previous");
if (previousElement) {
inputElement.dispatchEvent(new KeyboardEvent("keydown", {key: "ArrowUp"}));
@@ -1446,6 +1488,7 @@ export class Toolbar {
this.subElement.classList.remove("fn__none");
this.subElementCloseCB = undefined;
setPosition(this.subElement, rangePosition.left, rangePosition.top + 18, Constants.SIZE_TOOLBAR_HEIGHT);
+ (this.subElement.firstElementChild as HTMLElement).style.maxHeight = (window.innerHeight - this.subElement.getBoundingClientRect().top - 16) + "px";
this.element.classList.add("fn__none");
inputElement.select();
});