Skip to content

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

:bug: Restore emoji lists in the editor picker https://github.com/siyuan-note/siyuan/issues/18635

Danielc81476c2dba7
diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.ts
index 99851ec5c6..392d234729 100644
--- a/app/src/emoji/index.ts
+++ b/app/src/emoji/index.ts
@@ -28,9 +28,11 @@ import {
collectEmojiMatches,
getActiveEmojiCategory,
getEmojiItemMap,
+ getEmojiPanelResizeAction,
getEmojiVirtualChunks,
getRandomEmojiCategories,
groupCustomEmojiItems,
+ type TEmojiPanelPageMode,
type TRandomEmojiScope,
} from "./panel";
@@ -199,7 +201,7 @@ export class EmojiPanelController {
private selectionObserver?: IntersectionObserver;
private resizeObserver: ResizeObserver;
private active = true;
- private pageMode: "common" | "custom" | "search" | "" = "";
+ private pageMode: TEmojiPanelPageMode = "";
private searchMode = false;
private scrollFrame = 0;
private virtualTimer = 0;
@@ -218,16 +220,19 @@ export class EmojiPanelController {
if (!this.active || this.pageMode === "search" || this.panelElement.clientWidth === 0) {
return;
}
- if (this.pageMode === "custom") {
- const columnCount = this.getColumnCount();
- if (columnCount !== this.columnCount) {
+ const columnCount = this.getColumnCount();
+ const resizeAction = getEmojiPanelResizeAction(this.pageMode, this.columnCount, columnCount);
+ if (resizeAction === "render") {
+ if (this.pageMode === "custom") {
this.renderCustomPage();
- }
- } else if (this.pageMode === "common") {
- const columnCount = this.getColumnCount();
- if (columnCount !== this.columnCount) {
+ } else {
this.renderCommonPage(this.categoryID);
}
+ } else if (resizeAction === "refresh") {
+ this.updateCategoryOffsets();
+ this.updateBuiltInChunkOffsets();
+ this.renderVisibleBuiltInChunks(this.categoryID);
+ this.ensureCurrentSelection();
}
});
this.resizeObserver.observe(this.panelElement);
@@ -812,7 +817,7 @@ const genWeekdayOptions = (lang: string, weekdayType: string) => {
export const openEmojiPanel = (
id: string,
- type: "doc" | "notebook" | "av",
+ type: "doc" | "notebook" | "av" | "insert",
position: IPosition,
callback?: (emoji: string) => void,
dynamicImgElement?: HTMLElement,
@@ -890,7 +895,7 @@ export const openEmojiPanel = (
<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>
<div class="fn__flex-1"></div>
- <span class="block__icon block__icon--show fn__flex-center ariaLabel" data-action="remove" aria-label="${window.siyuan.languages.remove}"><svg><use xlink:href="#iconTrashcan"></use></svg></span>
+ <span class="block__icon block__icon--show fn__flex-center ariaLabel${type === "insert" ? " fn__none" : ""}" data-action="remove" aria-label="${window.siyuan.languages.remove}"><svg><use xlink:href="#iconTrashcan"></use></svg></span>
</div>
<div class="emojis__tabbody">
<div class="fn__none" data-type="tab-emoji">
@@ -1222,8 +1227,12 @@ export const openEmojiPanel = (
showMessage(window.siyuan.languages.kernelFault8);
return;
}
- reloadEmoji();
- applyLinkIcon(response.data.path);
+ if (type === "insert") {
+ reloadEmoji(() => applyLinkIcon(response.data.path));
+ } else {
+ reloadEmoji();
+ applyLinkIcon(response.data.path);
+ }
});
};
customIconFileElement.addEventListener("change", () => {
@@ -1630,12 +1639,13 @@ const putEmojis = (protyle: IProtyle) => {
}
};
-export const reloadEmoji = () => {
+export const reloadEmoji = (callback?: () => void) => {
fetchPost("/api/system/getEmojiConf", {}, response => {
window.siyuan.emojis = response.data as IEmoji[];
const editors = getAllEditor();
if (editors.length > 0) {
putEmojis(editors[0].protyle);
}
+ callback?.();
});
};
diff --git a/app/src/emoji/panel.test.ts b/app/src/emoji/panel.test.ts
index f8ea6cdcb1..b7c35648da 100644
--- a/app/src/emoji/panel.test.ts
+++ b/app/src/emoji/panel.test.ts
@@ -4,6 +4,7 @@ import {
collectEmojiMatches,
getActiveEmojiCategory,
getEmojiItemMap,
+ getEmojiPanelResizeAction,
getEmojiVirtualChunks,
getRandomEmojiCategories,
groupCustomEmojiItems,
@@ -43,6 +44,22 @@ describe("getEmojiVirtualChunks", () => {
});
});
+describe("getEmojiPanelResizeAction", () => {
+ it("refreshes visible built-in chunks when a hidden panel becomes visible at the same column count", () => {
+ assert.equal(getEmojiPanelResizeAction("common", 10, 10), "refresh");
+ });
+
+ it("rerenders common and custom pages when the column count changes", () => {
+ assert.equal(getEmojiPanelResizeAction("common", 10, 8), "render");
+ assert.equal(getEmojiPanelResizeAction("custom", 10, 8), "render");
+ });
+
+ it("does not refresh unchanged custom or search pages", () => {
+ assert.equal(getEmojiPanelResizeAction("custom", 10, 10), "none");
+ assert.equal(getEmojiPanelResizeAction("search", 10, 10), "none");
+ });
+});
+
describe("getActiveEmojiCategory", () => {
const offsets = [{id: "recent", top: 0}, {id: "people", top: 100}, {id: "nature", top: 500}];
diff --git a/app/src/emoji/panel.ts b/app/src/emoji/panel.ts
index 24363526a9..30671536fd 100644
--- a/app/src/emoji/panel.ts
+++ b/app/src/emoji/panel.ts
@@ -7,6 +7,23 @@ export type TCustomEmojiGroup = {
export type TRandomEmojiScope = "all" | "builtIn" | "custom";
+export type TEmojiPanelPageMode = "common" | "custom" | "search" | "";
+export type TEmojiPanelResizeAction = "none" | "render" | "refresh";
+
+export const getEmojiPanelResizeAction = (
+ pageMode: TEmojiPanelPageMode,
+ columnCount: number,
+ nextColumnCount: number,
+): TEmojiPanelResizeAction => {
+ if (pageMode !== "common" && pageMode !== "custom") {
+ return "none";
+ }
+ if (columnCount !== nextColumnCount) {
+ return "render";
+ }
+ return pageMode === "common" ? "refresh" : "none";
+};
+
export const getRandomEmojiCategories = (categories: IEmoji[], scope: TRandomEmojiScope) => {
return categories.filter((category) => category.items.length > 0 &&
(scope === "all" || (category.id === "custom") === (scope === "custom")));
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index 5303ae1d22..5547f9d458 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -39,6 +39,7 @@ import {
addEmoji,
EmojiPanelController,
genEmojiCategoryButtons,
+ openEmojiPanel,
unicode2Emoji,
} from "../../emoji";
import {blockRender} from "../render/blockRender";
@@ -543,17 +544,37 @@ ${genHintItemHTML(item)}
}
this.emojiBrowseMode = value === "";
this.emojiPanel.renderSearch(value, 256);
- this.emojiPanel.activate();
const firstEmojiElement = this.element.querySelector(".emojis__item");
if (firstEmojiElement) {
this.element.classList.remove("fn__none");
const textareaPosition = getSelectionPosition(protyle.wysiwyg.element);
setPosition(this.element, textareaPosition.left, textareaPosition.top + 26, 30);
+ this.emojiPanel.activate();
} else {
this.element.classList.add("fn__none");
+ this.emojiPanel.deactivate();
}
}
+ private openEmojiInsertPanel(protyle: IProtyle, range: Range) {
+ const targetElement = hasClosestBlock(range.startContainer);
+ const targetID = targetElement ? targetElement.getAttribute("data-node-id") : protyle.block.rootID;
+ const textareaPosition = getSelectionPosition(protyle.wysiwyg.element);
+ protyle.toolbar.range = range.cloneRange();
+ openEmojiPanel("", "insert", {
+ x: textareaPosition.left,
+ y: textareaPosition.top + 26,
+ h: 30,
+ w: 30,
+ }, (unicode) => {
+ if (!unicode) {
+ return;
+ }
+ focusByRange(protyle.toolbar.range);
+ insertHTML(protyle.lute.SpinBlockDOM(genEmojiInsertHTML(unicode)), protyle, false, true);
+ }, undefined, {targetID});
+ }
+
private destroyEmojiPanel() {
this.emojiPanel?.destroy();
this.emojiPanel = undefined;
@@ -855,10 +876,9 @@ ${genHintItemHTML(item)}
return;
} else if (value === "emoji") {
range.deleteContents();
- range.insertNode(document.createTextNode(":"));
range.collapse(false);
focusByRange(range);
- this.genEmojiHTML(protyle);
+ this.openEmojiInsertPanel(protyle, range);
return;
} else if (value.startsWith("style")) {
range.deleteContents();