diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index f17ab800b..45979b462 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -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(); diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts index b3f1eb0d1..57313a9a5 100644 --- a/app/src/protyle/render/av/openMenuPanel.ts +++ b/app/src/protyle/render/av/openMenuPanel.ts @@ -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({