mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-30 21:38:48 +01:00
This commit is contained in:
parent
80ff759d90
commit
4ca9c0f57a
1 changed files with 53 additions and 10 deletions
|
|
@ -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 += `<div data-value="${item.path}" class="b3-list-item--hide-action b3-list-item${index === 0 ? " b3-list-item--focus" : ""}">
|
||||
<span class="b3-list-item__text">${item.content}</span>`;
|
||||
/// #if !BROWSER
|
||||
html += `<span class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.showInFolder}">
|
||||
html += `<span data-type="open" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.showInFolder}">
|
||||
<svg><use xlink:href="#iconFolder"></use></svg>
|
||||
</span></div>`;
|
||||
/// #else
|
||||
html += "</div>";
|
||||
</span>`;
|
||||
/// #endif
|
||||
html += `<span data-type="remove" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.remove}">
|
||||
<svg><use xlink:href="#iconTrashcan"></use></svg>
|
||||
</span></div>`;
|
||||
});
|
||||
if (html === "") {
|
||||
html = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
|
||||
|
|
@ -1360,14 +1362,20 @@ export class Toolbar {
|
|||
</div>`;
|
||||
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 += `<div data-value="${item.path}" class="b3-list-item${index === 0 ? " b3-list-item--focus" : ""}">${item.content}</div>`;
|
||||
});
|
||||
listElement.innerHTML = searchHTML || `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
|
||||
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 = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
|
||||
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();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue