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"); const menu = new Menu("background-asset");
if (menu.isOpen) { if (menu.isOpen) {
return; return;
@ -135,11 +135,11 @@ export const assetMenu = (protyle: IProtyle, position: IPosition, callback?: (ur
if (event.key === "Enter") { if (event.key === "Enter") {
if (!isEmpty) { if (!isEmpty) {
const currentURL = element.querySelector(".b3-list-item--focus").getAttribute("data-value"); const currentElement = element.querySelector(".b3-list-item--focus");
if (callback) { if (callback) {
callback(currentURL); callback(currentElement.getAttribute("data-value"), currentElement.textContent);
} else { } else {
hintRenderAssets(currentURL, protyle); hintRenderAssets(currentElement.getAttribute("data-value"), protyle);
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
} }
} else if (!callback) { } 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(); event.stopPropagation();
renderAssetList(element, inputElement.value, position, exts); renderAssetList(element, inputElement.value, position, exts);
}); });
@ -178,7 +185,7 @@ export const assetMenu = (protyle: IProtyle, position: IPosition, callback?: (ur
event.stopPropagation(); event.stopPropagation();
const currentURL = listItemElement.getAttribute("data-value"); const currentURL = listItemElement.getAttribute("data-value");
if (callback) { if (callback) {
callback(currentURL); callback(currentURL, listItemElement.textContent);
} else { } else {
hintRenderAssets(currentURL, protyle); hintRenderAssets(currentURL, protyle);
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();

View file

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