From 5822519f063692039b60d84bb3ccc093962aea6e Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 6 Jan 2025 18:15:59 +0800 Subject: [PATCH] :recycle: https://github.com/siyuan-note/siyuan/pull/13585 --- app/src/emoji/index.ts | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.ts index 700d75a7f..4d0a525a2 100644 --- a/app/src/emoji/index.ts +++ b/app/src/emoji/index.ts @@ -216,6 +216,19 @@ const genWeekdayOptions = (lang: string, weekdayType: string) => { `; }; +const renderEmojiContent = (previousIndex: string, previousContentElement: Element) => { + if (!previousIndex) { + return; + } + let html = ""; + window.siyuan.emojis[parseInt(previousIndex)].items.forEach(emoji => { + html += ``; + }); + previousContentElement.innerHTML = html; + previousContentElement.removeAttribute("data-index"); + previousContentElement.removeAttribute("style") +} + export const openEmojiPanel = (id: string, type: "doc" | "notebook" | "av", position: IPosition, callback?: (emoji: string) => void, dynamicImgElement?: HTMLElement) => { if (type !== "av") { window.siyuan.menus.menu.remove(); @@ -524,30 +537,11 @@ export const openEmojiPanel = (id: string, type: "doc" | "notebook" | "av", posi if (target.classList.contains("emojis__type")) { const titleElement = emojisContentElement.querySelector(`[data-type="${target.getAttribute("data-type")}"]`) as HTMLElement; if (titleElement) { - const previousElement = titleElement.previousElementSibling as HTMLElement; - const previousIndex = previousElement?.getAttribute("data-index"); - const nextElement = titleElement.nextElementSibling as HTMLElement; - const index = nextElement?.getAttribute("data-index"); - - if (previousIndex) { - let html = ""; - window.siyuan.emojis[parseInt(previousIndex)].items.forEach(emoji => { - html += ``; - }); - previousElement.innerHTML = html; - previousElement.removeAttribute("data-index"); - previousElement.style.minHeight = ""; - } + const index = titleElement.nextElementSibling.getAttribute("data-index"); if (index) { - let html = ""; - window.siyuan.emojis[parseInt(index)].items.forEach(emoji => { - html += ``; - }); - nextElement.innerHTML = html; - nextElement.removeAttribute("data-index"); - nextElement.style.minHeight = ""; + renderEmojiContent(titleElement.previousElementSibling?.getAttribute("data-index"), titleElement.previousElementSibling); + renderEmojiContent(index, titleElement.nextElementSibling); } - emojisContentElement.scrollTo({ top: titleElement.offsetTop - 77, // behavior: "smooth" 不能使用,否则无法定位