Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Move custom emoji access to the top toolbar https://github.com/siyuan-note/siyuan/issues/13563

Daniel2bd7ff32ae25
diff --git a/app/src/assets/scss/business/_emojis.scss b/app/src/assets/scss/business/_emojis.scss
index dbd59bf1c5..f13ac19f23 100644
--- a/app/src/assets/scss/business/_emojis.scss
+++ b/app/src/assets/scss/business/_emojis.scss
@@ -16,6 +16,12 @@
padding: 0 8px 8px;
}
+ &__tab-custom {
+ font-family: var(--b3-font-family-emoji);
+ font-size: 16px;
+ font-variant-emoji: emoji;
+ }
+
&__tabbody {
flex: 1;
overflow: auto;
diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.ts
index dc969458ad..fb37d7501e 100644
--- a/app/src/emoji/index.ts
+++ b/app/src/emoji/index.ts
@@ -870,6 +870,9 @@ export const openEmojiPanel = (
const popoverElement = options?.ownerElement?.closest<HTMLElement>(".block__popover");
const targetID = options?.targetID || id;
+ const customCategoryIndex = window.siyuan.emojis.findIndex((item) => item.id === "custom");
+ const customEmojiLabel = customCategoryIndex > -1 ?
+ getEmojiTitle(customCategoryIndex) : window.siyuan.languages.customEmoji;
const dynamicURL = "api/icon/getDynamicIcon?";
const dynamicCurrentObj: Record<string, any> = {
color: "#d23f31",
@@ -921,6 +924,8 @@ export const openEmojiPanel = (
<div class="emojis__tabheader">
<div data-type="tab-emoji" class="ariaLabel block__icon block__icon--show" aria-label="${window.siyuan.languages.emoji}"><svg><use xlink:href="#iconEmoji"></use></svg></div>
<div class="fn__space"></div>
+ <div data-type="tab-custom" class="ariaLabel block__icon block__icon--show emojis__tab-custom${options?.custom ? " fn__none" : ""}" aria-label="${escapeAttr(escapeHtml(customEmojiLabel))}">${unicode2Emoji(emojiCategoryIcons.custom)}</div>
+ <div class="fn__space"></div>
<div data-type="tab-dynamic" class="ariaLabel block__icon block__icon--show${options?.dynamic ? " fn__none" : ""}" aria-label="${window.siyuan.languages.dynamicIcon}"><svg><use xlink:href="#iconCalendar"></use></svg></div>
<div class="fn__space${type === "av" ? " fn__none" : ""}"></div>
<div data-type="tab-link" class="ariaLabel block__icon block__icon--show${type === "av" ? " fn__none" : ""}" aria-label="${window.siyuan.languages.upload} ${window.siyuan.languages.image}"><svg><use xlink:href="#iconUpload"></use></svg></div>
@@ -941,7 +946,7 @@ export const openEmojiPanel = (
<span class="fn__space"></span>
</div>
<div class="emojis__panel"></div>
- <div class="emojis__types">${genEmojiCategoryButtons(options?.custom)}</div>
+ <div class="emojis__types">${genEmojiCategoryButtons(true)}</div>
</div>
<div class="fn__none" data-type="tab-dynamic">
<div class="fn__flex emoji__dynamic-color">
@@ -1074,8 +1079,10 @@ export const openEmojiPanel = (
if (!currentTabElement || currentTabElement.classList.contains("fn__none")) {
currentTab = "emoji";
}
+ let customEmojiPage = currentTab === "custom";
+ const currentBodyTab = customEmojiPage ? "emoji" : currentTab;
dialog.element.querySelector(`.emojis__tabheader [data-type="tab-${currentTab}"]`).classList.add("block__icon--active");
- dialog.element.querySelector(`.emojis__tabbody [data-type="tab-${currentTab}"]`).classList.remove("fn__none");
+ dialog.element.querySelector(`.emojis__tabbody [data-type="tab-${currentBodyTab}"]`).classList.remove("fn__none");
setPosition(dialog.element.querySelector(".b3-dialog__container"), position.x, position.y, position.h, position.w);
const networkIconInputElement = dialog.element.querySelector('[data-type="network-icon-url"]') as HTMLTextAreaElement;
const customIconFileElement = dialog.element.querySelector('[data-type="custom-icon-file"]') as HTMLInputElement;
@@ -1309,10 +1316,13 @@ export const openEmojiPanel = (
event.preventDefault();
event.stopPropagation();
});
- if (currentTab === "emoji") {
+ if (customEmojiPage) {
+ emojiPanelController.renderCategory("custom");
+ emojiPanelController.activate();
+ } else if (currentTab === "emoji") {
emojiPanelController.activate();
}
- if (!isMobile() && currentTab === "emoji") {
+ if (!isMobile() && (currentTab === "emoji" || customEmojiPage)) {
emojiSearchInputElement.focus();
} else if (!isMobile() && currentTab === "link") {
linkIconElement.focus();
@@ -1322,6 +1332,11 @@ export const openEmojiPanel = (
let target = event.target as HTMLElement;
while (target && target !== dialog.element) {
if (target.classList.contains("emojis__type")) {
+ customEmojiPage = false;
+ dialogElement.querySelector('[data-type="tab-custom"]')?.classList.remove("block__icon--active");
+ dialogElement.querySelector('[data-type="tab-emoji"]')?.classList.add("block__icon--active");
+ window.siyuan.storage[Constants.LOCAL_EMOJIS].currentTab = "emoji";
+ setStorageVal(Constants.LOCAL_EMOJIS, window.siyuan.storage[Constants.LOCAL_EMOJIS]);
emojiPanelController.renderCategory(target.dataset.type);
break;
} else if (target.getAttribute("data-action") === "select-custom-icon") {
@@ -1418,8 +1433,9 @@ export const openEmojiPanel = (
item.classList.remove("block__icon--active");
}
});
+ const bodyType = target.dataset.type === "tab-custom" ? "tab-emoji" : target.dataset.type;
dialogElement.querySelectorAll(".emojis__tabbody > div").forEach((item: HTMLElement) => {
- if (item.dataset.type === target.dataset.type) {
+ if (item.dataset.type === bodyType) {
item.classList.remove("fn__none");
} else {
item.classList.add("fn__none");
@@ -1427,7 +1443,20 @@ export const openEmojiPanel = (
});
window.siyuan.storage[Constants.LOCAL_EMOJIS].currentTab = target.dataset.type.replace("tab-", "");
setStorageVal(Constants.LOCAL_EMOJIS, window.siyuan.storage[Constants.LOCAL_EMOJIS]);
- if (target.dataset.type === "tab-emoji") {
+ if (target.dataset.type === "tab-custom") {
+ customEmojiPage = true;
+ emojiSearchInputElement.value = "";
+ emojiPanelController.renderCategory("custom");
+ emojiPanelController.activate();
+ if (!isMobile()) {
+ emojiSearchInputElement.focus();
+ }
+ } else if (target.dataset.type === "tab-emoji") {
+ if (customEmojiPage) {
+ customEmojiPage = false;
+ emojiSearchInputElement.value = "";
+ emojiPanelController.renderInitial();
+ }
emojiPanelController.activate();
if (!isMobile()) {
emojiSearchInputElement.focus();