An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Align Windows notebook and document emoji icons https://github.com/siyuan-note/siyuan/issues/20731
Daniel251c8b897f6a
diff --git a/app/src/assets/scss/component/_list.scss b/app/src/assets/scss/component/_list.scssindex b316cefb2e..6c6f0cddb0 100644--- a/app/src/assets/scss/component/_list.scss+++ b/app/src/assets/scss/component/_list.scss@@ -311,12 +311,20 @@align-items: center;justify-content: center;+ body.body--windows & > .b3-list-item__emoji {+ transform: translateY(-1px);+ }+&:hover {color: var(--b3-theme-on-background);background-color: var(--b3-list-icon-hover);}}+ &__emoji {+ pointer-events: none;+ }+&__hinttext {overflow: hidden;white-space: nowrap;diff --git a/app/src/emoji/fileTreeIcon.test.ts b/app/src/emoji/fileTreeIcon.test.tsindex ef1440188b..8161c9ae86 100644--- a/app/src/emoji/fileTreeIcon.test.ts+++ b/app/src/emoji/fileTreeIcon.test.ts@@ -74,16 +74,16 @@ describe("file tree icon", () => {});it("keeps the Emoji defaults when SVG icons are disabled", () => {- assert.equal(getFileTreeIconHTML("", "notebook", "", false, false), "🗃");- assert.equal(getFileTreeIconHTML("", "folder", "", false, false), "📑");- assert.equal(getFileTreeIconHTML("", "file", "", false, false), "📄");- assert.equal(getFileTreeIconHTML("", "lock", "", false, false), "🔒️");+ assert.equal(getFileTreeIconHTML("", "notebook", "", false, false), '<span class="b3-list-item__emoji">🗃</span>');+ assert.equal(getFileTreeIconHTML("", "folder", "", false, false), '<span class="b3-list-item__emoji">📑</span>');+ assert.equal(getFileTreeIconHTML("", "file", "", false, false), '<span class="b3-list-item__emoji">📄</span>');+ assert.equal(getFileTreeIconHTML("", "lock", "", false, false), '<span class="b3-list-item__emoji">🔒️</span>');assert.equal(getDocumentIconHTML("", "mobile-tabs__item-icon", false),'<span class="mobile-tabs__item-icon">📄</span>');});it("treats an explicitly configured icon as custom", () => {- assert.equal(getFileTreeIconHTML("1f4c4", "folder", "", false, true), "📄");+ assert.equal(getFileTreeIconHTML("1f4c4", "folder", "", false, true), '<span class="b3-list-item__emoji">📄</span>');assert.equal(getDocumentIconHTML("1f4c4", "mobile-tabs__item-icon", true),'<span class="mobile-tabs__item-icon">📄</span>');assert.equal(getFileTreeDefaultIconAttr("1f4c4", "folder"), "");@@ -111,13 +111,13 @@ describe("file tree icon", () => {updateFileTreeItemIcon(liElement, "1f4c4");assert.equal("defaultIcon" in dataset, false);- assert.equal(iconElement.innerHTML, "📄");+ assert.equal(iconElement.innerHTML, '<span class="b3-list-item__emoji">📄</span>');updateFileTreeItemIcon(liElement, "", "file");window.siyuan.config.fileTree.useSVGDefaultIcon = false;refreshDefaultFileTreeIcons({querySelectorAll: () => [liElement]} as unknown as ParentNode);assert.equal(dataset.defaultIcon, "file");- assert.equal(iconElement.innerHTML, "📄");+ assert.equal(iconElement.innerHTML, '<span class="b3-list-item__emoji">📄</span>');});it("refreshes locked notebook icons with the SVG setting", () => {@@ -131,6 +131,6 @@ describe("file tree icon", () => {assert.match(iconElement.innerHTML, /#iconLock/);window.siyuan.config.fileTree.useSVGDefaultIcon = false;refreshDefaultFileTreeIcons({querySelectorAll: () => [liElement]} as unknown as ParentNode);- assert.equal(iconElement.innerHTML, "🔒️");+ assert.equal(iconElement.innerHTML, '<span class="b3-list-item__emoji">🔒️</span>');});});diff --git a/app/src/emoji/fileTreeIcon.ts b/app/src/emoji/fileTreeIcon.tsindex b5897c253b..6ab6d69bf3 100644--- a/app/src/emoji/fileTreeIcon.ts+++ b/app/src/emoji/fileTreeIcon.ts@@ -28,6 +28,11 @@ const isDefaultIcon = (value: string | undefined): value is TFileTreeDefaultIconconst getDirectIconElement = (liElement: HTMLElement) => Array.from(liElement.children).find((item) =>item.classList.contains("b3-list-item__icon") || item.classList.contains("b3-list-item__graphic")) as HTMLElement | undefined;+const renderFileTreeEmoji = (icon: string, className: string, needSpan: boolean) => {+ const html = unicode2Emoji(icon, className, needSpan);+ return html && !html.startsWith("<") ? `<span class="b3-list-item__emoji">${html}</span>` : html;+};+export const getFileTreeDefaultIconAttr = (icon: string, defaultIcon: TFileTreeDefaultIcon, disabled = false) =>!icon && !disabled ? ` data-default-icon="${defaultIcon}"` : "";@@ -35,11 +40,11 @@ export const getFileTreeIconHTML = (icon: string, defaultIcon: TFileTreeDefaultIneedSpan = false, useSVGDefaultIcon =window.siyuan.config.fileTree.useSVGDefaultIcon === true) => {if (icon) {- return unicode2Emoji(icon, className, needSpan);+ return renderFileTreeEmoji(icon, className, needSpan);}if (!useSVGDefaultIcon) {- return unicode2Emoji(getDefaultEmoji(defaultIcon), className, needSpan);+ return renderFileTreeEmoji(getDefaultEmoji(defaultIcon), className, needSpan);}const classAttr = needSpan ? ` class="${escapeAttr(className)}"` : "";@@ -75,7 +80,7 @@ export const updateFileTreeItemIcon = (liElement: HTMLElement, icon: string,}if (icon) {delete liElement.dataset.defaultIcon;- iconElement.innerHTML = unicode2Emoji(icon);+ iconElement.innerHTML = getFileTreeIconHTML(icon, defaultIcon);return;}liElement.dataset.defaultIcon = defaultIcon;diff --git a/app/tests/fileTreeIconAlignment.test.js b/app/tests/fileTreeIconAlignment.test.jsnew file mode 100644index 0000000000..ca309bf532--- /dev/null+++ b/app/tests/fileTreeIconAlignment.test.js@@ -0,0 +1,101 @@+const assert = require("node:assert/strict");+const fs = require("node:fs");+const path = require("node:path");+const os = require("node:os");++const browserCases = (sources, styles) => {+ const assert = require("node:assert/strict");+ window.siyuan = {config: {fileTree: {useSVGDefaultIcon: false}},+ storage: {"local-images": {note: "1f600", folder: "1f4d2", file: "2b50"}}};+ const modules = {"../constants": {Constants: {LOCAL_IMAGES: "local-images"}}};+ for (const [name, source] of sources) {+ const exports = {};+ new Function("exports", "require", source)(exports, id => modules[id]);+ modules[name] = exports;+ }+ const {getFileTreeIconHTML, updateFileTreeItemIcon} = modules.fileTree;+ const row = (id, html) => `<li id="${id}" class="b3-list-item"><span class="b3-list-item__icon">${html}</span>` ++ '<span class="b3-list-item__text">Document</span></li>';+ const style = document.createElement("style");+ style.textContent = styles;+ document.head.append(style);+ document.body.innerHTML = '<ul class="b3-list">' ++ row("emoji", getFileTreeIconHTML("1f600", "notebook")) ++ row("image", getFileTreeIconHTML("custom.png", "file")) ++ row("svg", getFileTreeIconHTML("", "file", "", false, true)) + "</ul>";+ const icon = document.querySelector("#emoji .b3-list-item__icon");+ const emoji = icon.firstElementChild;+ for (const platform of ["windows", "mac", "linux", "android", "ios", "harmony"]) {+ document.body.className = `body--${platform}`;+ for (const size of [14, 24]) {+ document.body.style.fontSize = `${size}px`;+ const before = icon.getBoundingClientRect();+ emoji.style.transform = "none";+ const original = emoji.getBoundingClientRect();+ emoji.style.transform = "";+ const adjusted = emoji.getBoundingClientRect();+ assert.equal(adjusted.top - original.top, platform === "windows" ? -1 : 0);+ assert.equal(icon.getBoundingClientRect().top, before.top);+ assert.equal(icon.getBoundingClientRect().height, before.height);+ assert.equal(document.elementFromPoint(adjusted.x + adjusted.width / 2,+ adjusted.y + adjusted.height / 2), icon, "glyph wrappers preserve the icon click target");+ for (const id of ["image", "svg"]) {+ const graphic = document.querySelector(`#${id} .b3-list-item__icon`).firstElementChild;+ assert.equal(getComputedStyle(graphic).transform, "none");+ assert.equal(graphic.getBoundingClientRect().width, 16);+ assert.equal(graphic.getBoundingClientRect().height, 16);+ }+ }+ }+ updateFileTreeItemIcon(document.getElementById("emoji"), "2b50", "file");+ assert.equal(icon.firstElementChild.className, "b3-list-item__emoji");+ updateFileTreeItemIcon(document.getElementById("emoji"), "custom.png", "file");+ assert.equal(icon.firstElementChild.tagName, "IMG");+};++const runElectron = async () => {+ const {app, BrowserWindow} = require("electron");+ app.setPath("userData", path.join(process.argv[2], "profile"));+ app.commandLine.appendSwitch("disable-gpu");+ await app.whenReady();+ const win = new BrowserWindow({show: false, webPreferences: {nodeIntegration: true, contextIsolation: false}});+ try {+ const root = path.resolve(__dirname, "..");+ const ts = require("typescript");+ const sources = [["../util/escape", "util/escape.ts"], ["./iconValue", "emoji/iconValue.ts"],+ ["fileTree", "emoji/fileTreeIcon.ts"]].map(([name, file]) => [name,+ ts.transpileModule(fs.readFileSync(path.join(root, "src", file), "utf8"), {+ compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021},+ }).outputText]);+ const css = require("sass").compile(path.join(root, "src/assets/scss/base.scss"),+ {logger: {warn() {}, debug() {}}}).css;+ await win.loadURL("about:blank");+ await win.webContents.executeJavaScript(fs.readFileSync(path.join(root, "stage/protyle/js/lute/lute.min.js"), "utf8"));+ await win.webContents.executeJavaScript(`(${browserCases.toString()})(${JSON.stringify(sources)}, ${JSON.stringify(css)})`);+ app.exit(0);+ } catch (error) {+ console.error(error);+ app.exit(1);+ }+};++if (process.versions.electron && process.type === "browser") {+ runElectron().catch(error => { console.error(error); require("electron").app.exit(1); });+} else {+ require("node:test").it("adjusts only Windows file tree emoji glyphs while preserving image, SVG and click geometry", {+ skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,+ timeout: 60000,+ }, async () => {+ const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "siyuan-file-tree-icon-"));+ const env = {...process.env};+ delete env.ELECTRON_RUN_AS_NODE;+ try {+ await require("node:util").promisify(require("node:child_process").execFile)(+ require("electron"), [__filename, temporary], {env, windowsHide: true, timeout: 55000});+ } finally {+ assert.equal(path.dirname(path.resolve(temporary)), path.resolve(os.tmpdir()));+ assert.ok(path.basename(temporary).startsWith("siyuan-file-tree-icon-"));+ fs.rmSync(temporary, {recursive: true, force: true, maxRetries: 5, retryDelay: 100});+ }+ });+}