Vanessa 2024-01-23 10:06:51 +08:00
parent d540b7242a
commit 1e08b29735
2 changed files with 15 additions and 8 deletions

View file

@ -86,7 +86,7 @@ const renderAssetList = (element: Element, k: string, position: IPosition, exts:
});
};
export const assetMenu = (protyle: IProtyle, position: IPosition, callback?: (url: string) => void, exts?: string[]) => {
export const assetMenu = (protyle: IProtyle, position: IPosition, callback?: (url: string, name: string) => void, exts?: string[]) => {
const menu = new Menu("background-asset");
if (menu.isOpen) {
return;
@ -135,11 +135,11 @@ export const assetMenu = (protyle: IProtyle, position: IPosition, callback?: (ur
if (event.key === "Enter") {
if (!isEmpty) {
const currentURL = element.querySelector(".b3-list-item--focus").getAttribute("data-value");
const currentElement = element.querySelector(".b3-list-item--focus");
if (callback) {
callback(currentURL);
callback(currentElement.getAttribute("data-value"), currentElement.textContent);
} else {
hintRenderAssets(currentURL, protyle);
hintRenderAssets(currentElement.getAttribute("data-value"), protyle);
window.siyuan.menus.menu.remove();
}
} else if (!callback) {
@ -155,7 +155,14 @@ export const assetMenu = (protyle: IProtyle, position: IPosition, callback?: (ur
}
}
});
inputElement.addEventListener("input", (event) => {
inputElement.addEventListener("input", (event: InputEvent) => {
if (event.isComposing) {
return;
}
event.stopPropagation();
renderAssetList(element, inputElement.value, position, exts);
});
inputElement.addEventListener("compositionend", (event: InputEvent) => {
event.stopPropagation();
renderAssetList(element, inputElement.value, position, exts);
});
@ -178,7 +185,7 @@ export const assetMenu = (protyle: IProtyle, position: IPosition, callback?: (ur
event.stopPropagation();
const currentURL = listItemElement.getAttribute("data-value");
if (callback) {
callback(currentURL);
callback(currentURL, listItemElement.textContent);
} else {
hintRenderAssets(currentURL, protyle);
window.siyuan.menus.menu.remove();

View file

@ -975,7 +975,7 @@ export const openMenuPanel = (options: {
y: rect.bottom,
w: target.parentElement.clientWidth + 8,
h: rect.height
}, (url) => {
}, (url, name) => {
let value: IAVCellAssetValue;
if (Constants.SIYUAN_ASSETS_IMAGE.includes(pathPosix().extname(url).toLowerCase())) {
value = {
@ -987,7 +987,7 @@ export const openMenuPanel = (options: {
value = {
type: "file",
content: url,
name: pathPosix().basename(url).substring(0, Constants.SIZE_LINK_TEXT_MAX)
name
};
}
updateAssetCell({