Skip to content

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

:art: Use SVG default icons in the document tree https://github.com/siyuan-note/siyuan/issues/18095

Daniele01d562a9afd
diff --git a/app/appearance/icons/index.html b/app/appearance/icons/index.html
index f91f2967bd..5cd66fadba 100644
--- a/app/appearance/icons/index.html
+++ b/app/appearance/icons/index.html
@@ -1294,6 +1294,12 @@
</svg>
iconFile
</div>
+ <div>
+ <svg>
+ <use xlink:href="#iconFileText"></use>
+ </svg>
+ iconFileText
+ </div>
<div>
<svg>
<use xlink:href="#iconHeart"></use>
diff --git a/app/appearance/icons/litheness/icon.js b/app/appearance/icons/litheness/icon.js
index a1bf3d5f93..efdb66516a 100644
--- a/app/appearance/icons/litheness/icon.js
+++ b/app/appearance/icons/litheness/icon.js
@@ -646,6 +646,9 @@ document.body.insertAdjacentHTML('afterbegin', `<svg id="iconsLitheness" style="
<symbol id="iconFile" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/>
</symbol>
+ <symbol id="iconFileText" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/>
+ </symbol>
<symbol id="iconHeart" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<path d="M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5"/>
</symbol>
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.json
index 92974097bd..98f04cf730 100644
--- a/app/appearance/langs/ar.json
+++ b/app/appearance/langs/ar.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "استخدام أيقونات SVG الافتراضية",
+ "useSVGDefaultIconTip": "استخدام أيقونات SVG لدفاتر الملاحظات والمستندات التي لا تحتوي على أيقونة مخصصة",
"bootAppearance": "مظهر صفحة بدء التشغيل",
"bootAppearanceTip": "اختر مظهر صفحة بدء التشغيل الذي توفره إضافة مثبتة؛ ولا يُطبق إلا على هذا الجهاز بعد إعادة التشغيل",
"monospaceFont": "خط أحادي المسافة",
diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.json
index aca992acec..64d4b242f5 100644
--- a/app/appearance/langs/de.json
+++ b/app/appearance/langs/de.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "SVG-Standardsymbole verwenden",
+ "useSVGDefaultIconTip": "SVG-Symbole für Notizbücher und Dokumente ohne benutzerdefiniertes Symbol verwenden",
"bootAppearance": "Erscheinungsbild der Startseite",
"bootAppearanceTip": "Wählen Sie ein von einem installierten Plugin bereitgestelltes Erscheinungsbild der Startseite; es gilt nach dem Neustart nur für dieses Gerät",
"monospaceFont": "Festbreitenschrift",
diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.json
index 7241a62fd6..53abad636b 100644
--- a/app/appearance/langs/en.json
+++ b/app/appearance/langs/en.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Use SVG default icons",
+ "useSVGDefaultIconTip": "Use SVG icons for notebooks and documents without a custom icon",
"bootAppearance": "Startup appearance",
"bootAppearanceTip": "Choose a startup appearance provided by an installed plugin; it applies only to this device after restart",
"monospaceFont": "Monospace Font",
diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.json
index 3647b1d85c..87c3419ec2 100644
--- a/app/appearance/langs/es.json
+++ b/app/appearance/langs/es.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Usar iconos SVG predeterminados",
+ "useSVGDefaultIconTip": "Usar iconos SVG para cuadernos y documentos sin un icono personalizado",
"bootAppearance": "Apariencia de la página de inicio",
"bootAppearanceTip": "Elige una apariencia de página de inicio proporcionada por un complemento instalado; solo se aplica a este dispositivo después de reiniciar",
"monospaceFont": "Fuente monoespaciada",
diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.json
index 01aaf6132c..8784c44e24 100644
--- a/app/appearance/langs/fr.json
+++ b/app/appearance/langs/fr.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Utiliser les icônes SVG par défaut",
+ "useSVGDefaultIconTip": "Utiliser des icônes SVG pour les carnets et les documents sans icône personnalisée",
"bootAppearance": "Apparence de la page de démarrage",
"bootAppearanceTip": "Choisissez une apparence de page de démarrage fournie par une extension installée ; elle ne s’applique qu’à cet appareil après le redémarrage",
"monospaceFont": "Police à chasse fixe",
diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.json
index fc675e7402..c50073ab27 100644
--- a/app/appearance/langs/he.json
+++ b/app/appearance/langs/he.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "שימוש בסמלי SVG כברירת מחדל",
+ "useSVGDefaultIconTip": "שימוש בסמלי SVG עבור מחברות ומסמכים ללא סמל מותאם אישית",
"bootAppearance": "מראה דף ההפעלה",
"bootAppearanceTip": "יש לבחור מראה לדף ההפעלה שמסופק על ידי תוסף מותקן; הוא יחול רק על מכשיר זה לאחר הפעלה מחדש",
"monospaceFont": "גופן ברוחב קבוע",
diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.json
index 4b27299e74..2caa9a609c 100644
--- a/app/appearance/langs/hi.json
+++ b/app/appearance/langs/hi.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "डिफ़ॉल्ट SVG आइकन का उपयोग करें",
+ "useSVGDefaultIconTip": "कस्टम आइकन के बिना नोटबुक और दस्तावेज़ों के लिए SVG आइकन का उपयोग करें",
"bootAppearance": "स्टार्टअप पृष्ठ का रूप",
"bootAppearanceTip": "इंस्टॉल किए गए प्लगइन द्वारा दिया गया स्टार्टअप पृष्ठ रूप चुनें; पुनः आरंभ के बाद यह केवल इस डिवाइस पर लागू होगा",
"monospaceFont": "मोनोस्पेस फ़ॉन्ट",
diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.json
index d3effc58bc..134aeda9a6 100644
--- a/app/appearance/langs/id.json
+++ b/app/appearance/langs/id.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Gunakan ikon SVG bawaan",
+ "useSVGDefaultIconTip": "Gunakan ikon SVG untuk buku catatan dan dokumen tanpa ikon khusus",
"bootAppearance": "Tampilan halaman mulai",
"bootAppearanceTip": "Pilih tampilan halaman mulai yang disediakan oleh plugin terpasang; pilihan hanya berlaku di perangkat ini setelah dimulai ulang",
"monospaceFont": "Font monospace",
diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.json
index 47702cc504..398cc1052a 100644
--- a/app/appearance/langs/it.json
+++ b/app/appearance/langs/it.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Usa icone SVG predefinite",
+ "useSVGDefaultIconTip": "Usa icone SVG per taccuini e documenti senza un'icona personalizzata",
"bootAppearance": "Aspetto della pagina di avvio",
"bootAppearanceTip": "Scegli un aspetto della pagina di avvio fornito da un plugin installato; si applica solo a questo dispositivo dopo il riavvio",
"monospaceFont": "Carattere monospaziato",
diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.json
index 5318890fbd..15a3c0f4e0 100644
--- a/app/appearance/langs/ja.json
+++ b/app/appearance/langs/ja.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "デフォルトの SVG アイコンを使用",
+ "useSVGDefaultIconTip": "カスタムアイコンがないノートブックと文書に SVG アイコンを使用",
"bootAppearance": "起動画面の外観",
"bootAppearanceTip": "インストール済みのプラグインが提供する起動画面の外観を選択し、再起動後にこのデバイスだけに適用します",
"monospaceFont": "等幅フォント",
diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.json
index c591da39e4..45bee6f4be 100644
--- a/app/appearance/langs/ko.json
+++ b/app/appearance/langs/ko.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "기본 SVG 아이콘 사용",
+ "useSVGDefaultIconTip": "사용자 지정 아이콘이 없는 노트북과 문서에 SVG 아이콘 사용",
"bootAppearance": "시작 페이지 모양",
"bootAppearanceTip": "설치된 플러그인이 제공하는 시작 페이지 모양을 선택하며 다시 시작한 후 이 기기에만 적용됩니다",
"monospaceFont": "고정폭 글꼴",
diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.json
index 0efcabb08f..f34630a948 100644
--- a/app/appearance/langs/nl.json
+++ b/app/appearance/langs/nl.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Standaard SVG-pictogrammen gebruiken",
+ "useSVGDefaultIconTip": "SVG-pictogrammen gebruiken voor notitieboeken en documenten zonder aangepast pictogram",
"bootAppearance": "Uiterlijk van de opstartpagina",
"bootAppearanceTip": "Kies een uiterlijk voor de opstartpagina dat door een geïnstalleerde plug-in wordt geleverd; dit geldt na opnieuw opstarten alleen voor dit apparaat",
"monospaceFont": "Monospacelettertype",
diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.json
index 61cc2635cb..39f9191cfa 100644
--- a/app/appearance/langs/pl.json
+++ b/app/appearance/langs/pl.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Używaj domyślnych ikon SVG",
+ "useSVGDefaultIconTip": "Używaj ikon SVG dla notatników i dokumentów bez niestandardowej ikony",
"bootAppearance": "Wygląd strony startowej",
"bootAppearanceTip": "Wybierz wygląd strony startowej dostarczony przez zainstalowaną wtyczkę; po ponownym uruchomieniu obowiązuje tylko na tym urządzeniu",
"monospaceFont": "Czcionka o stałej szerokości",
diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.json
index bf9f9133e9..9c08d00a21 100644
--- a/app/appearance/langs/pt-BR.json
+++ b/app/appearance/langs/pt-BR.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Usar ícones SVG padrão",
+ "useSVGDefaultIconTip": "Usar ícones SVG para cadernos e documentos sem um ícone personalizado",
"bootAppearance": "Aparência da tela de inicialização",
"bootAppearanceTip": "Escolha uma aparência da tela de inicialização fornecida por um plugin instalado; ela se aplica somente a este dispositivo após reiniciar",
"monospaceFont": "Fonte monoespaçada",
diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.json
index 129313367f..3ecc7b3ff3 100644
--- a/app/appearance/langs/ru.json
+++ b/app/appearance/langs/ru.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Использовать стандартные значки SVG",
+ "useSVGDefaultIconTip": "Использовать значки SVG для блокнотов и документов без пользовательского значка",
"bootAppearance": "Вид страницы запуска",
"bootAppearanceTip": "Выберите вид страницы запуска из установленного плагина; после перезапуска он применяется только на этом устройстве",
"monospaceFont": "Моноширинный шрифт",
diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.json
index 083e377e6b..a0b1da1dbc 100644
--- a/app/appearance/langs/sk.json
+++ b/app/appearance/langs/sk.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Používať predvolené ikony SVG",
+ "useSVGDefaultIconTip": "Používať ikony SVG pre zápisníky a dokumenty bez vlastnej ikony",
"bootAppearance": "Vzhľad úvodnej stránky",
"bootAppearanceTip": "Vyberte vzhľad úvodnej stránky poskytovaný nainštalovaným doplnkom; po reštarte sa použije iba na tomto zariadení",
"monospaceFont": "Písmo s pevnou šírkou",
diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.json
index 0047924aba..57ec3a8520 100644
--- a/app/appearance/langs/th.json
+++ b/app/appearance/langs/th.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "ใช้ไอคอน SVG เริ่มต้น",
+ "useSVGDefaultIconTip": "ใช้ไอคอน SVG สำหรับสมุดบันทึกและเอกสารที่ไม่มีไอคอนแบบกำหนดเอง",
"bootAppearance": "รูปลักษณ์หน้าเริ่มต้น",
"bootAppearanceTip": "เลือกรูปลักษณ์หน้าเริ่มต้นที่ปลั๊กอินซึ่งติดตั้งไว้มีให้ โดยจะมีผลเฉพาะอุปกรณ์นี้หลังจากเริ่มระบบใหม่",
"monospaceFont": "แบบอักษรความกว้างคงที่",
diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.json
index bf7c7b7922..9b30ace7f4 100644
--- a/app/appearance/langs/tr.json
+++ b/app/appearance/langs/tr.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Varsayılan SVG simgelerini kullan",
+ "useSVGDefaultIconTip": "Özel simgesi olmayan not defterleri ve belgeler için SVG simgelerini kullan",
"bootAppearance": "Başlangıç sayfası görünümü",
"bootAppearanceTip": "Yüklü bir eklentinin sağladığı başlangıç sayfası görünümünü seçin; yeniden başlatıldıktan sonra yalnızca bu cihazda uygulanır",
"monospaceFont": "Eş aralıklı yazı tipi",
diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.json
index 810b81cf3a..24b8294fbb 100644
--- a/app/appearance/langs/uk.json
+++ b/app/appearance/langs/uk.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "Використовувати стандартні значки SVG",
+ "useSVGDefaultIconTip": "Використовувати значки SVG для блокнотів і документів без власного значка",
"bootAppearance": "Вигляд сторінки запуску",
"bootAppearanceTip": "Виберіть вигляд сторінки запуску зі встановленого плагіна; після перезапуску він застосовується лише на цьому пристрої",
"monospaceFont": "Моноширинний шрифт",
diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.json
index 5bbe03fc08..d748e08e45 100644
--- a/app/appearance/langs/zh-CN.json
+++ b/app/appearance/langs/zh-CN.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "使用 SVG 默认图标",
+ "useSVGDefaultIconTip": "为未自定义图标的笔记本和文档使用 SVG 图标",
"bootAppearance": "启动页外观",
"bootAppearanceTip": "选择已安装插件提供的启动页外观,仅在重启后应用于当前设备",
"monospaceFont": "等宽字体",
diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.json
index 8e748b97cd..39d691a87f 100644
--- a/app/appearance/langs/zh-TW.json
+++ b/app/appearance/langs/zh-TW.json
@@ -1,4 +1,6 @@
{
+ "useSVGDefaultIcon": "使用 SVG 預設圖示",
+ "useSVGDefaultIconTip": "為未自訂圖示的筆記本與文件使用 SVG 圖示",
"bootAppearance": "啟動頁外觀",
"bootAppearanceTip": "選擇已安裝外掛提供的啟動頁外觀,僅在重新啟動後套用於目前裝置",
"monospaceFont": "等寬字型",
diff --git a/app/src/config/tabs/fileTab.ts b/app/src/config/tabs/fileTab.ts
index 5297ab4e96..931624b5fa 100644
--- a/app/src/config/tabs/fileTab.ts
+++ b/app/src/config/tabs/fileTab.ts
@@ -7,6 +7,7 @@ import type {SettingTabBuilder} from "../setting/builder";
import {controlNumber, controlSelect, controlString} from "../setting/control";
import {genConfigItemName} from "../render/fragments";
import {genButtonHtml, genNumberInputHtml} from "../render/render";
+import {refreshDefaultFileTreeIcons} from "../../emoji/fileTreeIcon";
/// #if !MOBILE
import {getAllModels} from "../../layout/getAll";
/// #endif
@@ -309,6 +310,13 @@ const registerFileManagementGroup = (tab: SettingTabBuilder) => {
const registerFileOthersGroup = (tab: SettingTabBuilder) => {
const group = tab.group("others", window.siyuan.languages.configGroupOthers);
+ group.switch("fileTree.useSVGDefaultIcon", {
+ title: window.siyuan.languages.useSVGDefaultIcon,
+ desc: window.siyuan.languages.useSVGDefaultIconTip,
+ save: (value) => fileConfigApi.patch("useSVGDefaultIcon", value, () => {
+ refreshDefaultFileTreeIcons();
+ }),
+ });
group.switch("fileTree.boxDocEnabled", {
title: window.siyuan.languages.boxDocEnabled,
desc: window.siyuan.languages.boxDocEnabledTip,
diff --git a/app/src/emoji/fileTreeIcon.test.ts b/app/src/emoji/fileTreeIcon.test.ts
new file mode 100644
index 0000000000..ffb22578ff
--- /dev/null
+++ b/app/src/emoji/fileTreeIcon.test.ts
@@ -0,0 +1,109 @@
+import {after, before, describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+
+const originalLute = Object.getOwnPropertyDescriptor(globalThis, "Lute");
+const originalWindow = Object.getOwnPropertyDescriptor(globalThis, "window");
+const originalNodeEnv = Object.getOwnPropertyDescriptor(globalThis, "NODE_ENV");
+const originalSiYuanVersion = Object.getOwnPropertyDescriptor(globalThis, "SIYUAN_VERSION");
+let getFileTreeDefaultIconAttr: typeof import("./fileTreeIcon").getFileTreeDefaultIconAttr;
+let getFileTreeIconHTML: typeof import("./fileTreeIcon").getFileTreeIconHTML;
+let refreshDefaultFileTreeIcons: typeof import("./fileTreeIcon").refreshDefaultFileTreeIcons;
+let syncFileTreeItemDefaultIcon: typeof import("./fileTreeIcon").syncFileTreeItemDefaultIcon;
+let updateFileTreeItemIcon: typeof import("./fileTreeIcon").updateFileTreeItemIcon;
+
+before(async () => {
+ Object.defineProperty(globalThis, "NODE_ENV", {configurable: true, value: "test"});
+ Object.defineProperty(globalThis, "SIYUAN_VERSION", {configurable: true, value: "test"});
+ Object.defineProperty(globalThis, "Lute", {
+ configurable: true,
+ value: {Sanitize: (value: string) => value},
+ });
+ Object.defineProperty(globalThis, "window", {
+ configurable: true,
+ value: {
+ siyuan: {
+ config: {fileTree: {useSVGDefaultIcon: false}},
+ storage: {"local-images": {file: "1f4c4", folder: "1f4d1", note: "1f5c3"}},
+ },
+ },
+ });
+ ({
+ getFileTreeDefaultIconAttr,
+ getFileTreeIconHTML,
+ refreshDefaultFileTreeIcons,
+ syncFileTreeItemDefaultIcon,
+ updateFileTreeItemIcon,
+ } = await import("./fileTreeIcon"));
+});
+
+after(() => {
+ if (originalLute) {
+ Object.defineProperty(globalThis, "Lute", originalLute);
+ } else {
+ Reflect.deleteProperty(globalThis, "Lute");
+ }
+ if (originalWindow) {
+ Object.defineProperty(globalThis, "window", originalWindow);
+ } else {
+ Reflect.deleteProperty(globalThis, "window");
+ }
+ if (originalNodeEnv) {
+ Object.defineProperty(globalThis, "NODE_ENV", originalNodeEnv);
+ } else {
+ Reflect.deleteProperty(globalThis, "NODE_ENV");
+ }
+ if (originalSiYuanVersion) {
+ Object.defineProperty(globalThis, "SIYUAN_VERSION", originalSiYuanVersion);
+ } else {
+ Reflect.deleteProperty(globalThis, "SIYUAN_VERSION");
+ }
+});
+
+describe("file tree icon", () => {
+ it("renders the configured SVG defaults", () => {
+ assert.match(getFileTreeIconHTML("", "notebook", "", false, true), /#iconFilesRoot/);
+ assert.match(getFileTreeIconHTML("", "folder", "", false, true), /#iconFileText/);
+ assert.match(getFileTreeIconHTML("", "file", "", false, true), /#iconFile/);
+ });
+
+ 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), "📄");
+ });
+
+ it("treats an explicitly configured icon as custom", () => {
+ assert.equal(getFileTreeIconHTML("1f4c4", "folder", "", false, true), "📄");
+ assert.equal(getFileTreeDefaultIconAttr("1f4c4", "folder"), "");
+ assert.equal(getFileTreeDefaultIconAttr("", "folder"), ' data-default-icon="folder"');
+ assert.equal(getFileTreeDefaultIconAttr("", "notebook", true), "");
+ });
+
+ it("updates only marked default icons when document state or the setting changes", () => {
+ const classes = (...values: string[]) => ({contains: (value: string) => values.includes(value)});
+ const toggleElement = {classList: classes("b3-list-item__toggle")};
+ const iconElement = {classList: classes("b3-list-item__icon"), innerHTML: ""};
+ const dataset: Record<string, string> = {defaultIcon: "file"};
+ const liElement = {
+ children: [toggleElement, iconElement],
+ dataset,
+ getAttribute: (name: string) => name === "data-type" ? "navigation-file" : null,
+ hasAttribute: (name: string) => name === "data-default-icon" && "defaultIcon" in dataset,
+ } as unknown as HTMLElement;
+ window.siyuan.config.fileTree.useSVGDefaultIcon = true;
+
+ syncFileTreeItemDefaultIcon(liElement);
+ assert.equal(dataset.defaultIcon, "folder");
+ assert.match(iconElement.innerHTML, /#iconFileText/);
+
+ updateFileTreeItemIcon(liElement, "1f4c4");
+ assert.equal("defaultIcon" in dataset, false);
+ assert.equal(iconElement.innerHTML, "📄");
+
+ 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, "📄");
+ });
+});
diff --git a/app/src/emoji/fileTreeIcon.ts b/app/src/emoji/fileTreeIcon.ts
new file mode 100644
index 0000000000..5abfc27746
--- /dev/null
+++ b/app/src/emoji/fileTreeIcon.ts
@@ -0,0 +1,94 @@
+import {Constants} from "../constants";
+import {escapeAttr} from "../util/escape";
+import {unicode2Emoji} from "./iconValue";
+
+export type TFileTreeDefaultIcon = "notebook" | "folder" | "file";
+
+const FILE_TREE_SVG_ICONS: Record<TFileTreeDefaultIcon, string> = {
+ notebook: "iconFilesRoot",
+ folder: "iconFileText",
+ file: "iconFile",
+};
+
+const getDefaultEmoji = (defaultIcon: TFileTreeDefaultIcon) => {
+ const images = window.siyuan.storage[Constants.LOCAL_IMAGES];
+ if (defaultIcon === "notebook") {
+ return images.note;
+ }
+ return images[defaultIcon];
+};
+
+const isDefaultIcon = (value: string | undefined): value is TFileTreeDefaultIcon =>
+ value === "notebook" || value === "folder" || value === "file";
+
+const 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;
+
+export const getFileTreeDefaultIconAttr = (icon: string, defaultIcon: TFileTreeDefaultIcon, disabled = false) =>
+ !icon && !disabled ? ` data-default-icon="${defaultIcon}"` : "";
+
+export const getFileTreeIconHTML = (icon: string, defaultIcon: TFileTreeDefaultIcon, className = "",
+ needSpan = false, useSVGDefaultIcon =
+ window.siyuan.config.fileTree.useSVGDefaultIcon === true) => {
+ if (icon) {
+ return unicode2Emoji(icon, className, needSpan);
+ }
+
+ if (!useSVGDefaultIcon) {
+ return unicode2Emoji(getDefaultEmoji(defaultIcon), className, needSpan);
+ }
+
+ const svg = `<svg><use xlink:href="#${FILE_TREE_SVG_ICONS[defaultIcon]}"></use></svg>`;
+ return needSpan ? `<span class="${escapeAttr(className)}">${svg}</span>` : svg;
+};
+
+const resolveDefaultIcon = (liElement: HTMLElement): TFileTreeDefaultIcon => {
+ if (liElement.getAttribute("data-type") === "navigation-root" ||
+ liElement.dataset.defaultIcon === "notebook") {
+ return "notebook";
+ }
+ const toggleElement = Array.from(liElement.children).find((item) =>
+ item.classList.contains("b3-list-item__toggle"));
+ return toggleElement?.classList.contains("fn__hidden") ? "file" : "folder";
+};
+
+export const updateFileTreeItemIcon = (liElement: HTMLElement, icon: string,
+ defaultIcon = resolveDefaultIcon(liElement)) => {
+ const iconElement = getDirectIconElement(liElement);
+ if (!iconElement || !iconElement.classList.contains("b3-list-item__icon")) {
+ return;
+ }
+ if (icon) {
+ delete liElement.dataset.defaultIcon;
+ iconElement.innerHTML = unicode2Emoji(icon);
+ return;
+ }
+ liElement.dataset.defaultIcon = defaultIcon;
+ iconElement.innerHTML = getFileTreeIconHTML("", defaultIcon);
+};
+
+export const syncFileTreeItemDefaultIcon = (liElement: HTMLElement,
+ defaultIcon = resolveDefaultIcon(liElement)) => {
+ if (!liElement.hasAttribute("data-default-icon")) {
+ return;
+ }
+ updateFileTreeItemIcon(liElement, "", defaultIcon);
+};
+
+export const refreshDefaultFileTreeIcons = (root: ParentNode = document) => {
+ root.querySelectorAll<HTMLElement>("[data-default-icon]").forEach((liElement) => {
+ const defaultIcon = liElement.dataset.defaultIcon;
+ if (!isDefaultIcon(defaultIcon)) {
+ return;
+ }
+ const iconElement = getDirectIconElement(liElement);
+ if (!iconElement) {
+ return;
+ }
+ if (iconElement.classList.contains("b3-list-item__icon")) {
+ iconElement.innerHTML = getFileTreeIconHTML("", defaultIcon);
+ } else {
+ iconElement.outerHTML = getFileTreeIconHTML("", defaultIcon, "b3-list-item__graphic", true);
+ }
+ });
+};
diff --git a/app/src/emoji/iconValue.ts b/app/src/emoji/iconValue.ts
index d4b64b2d33..98b8e0036f 100644
--- a/app/src/emoji/iconValue.ts
+++ b/app/src/emoji/iconValue.ts
@@ -185,3 +185,32 @@ export const genEmojiImageHTML = (value: string, className = "", lazy = false):
const safeSrc = escapeAttr(escapeHtml(src));
return `<img class="${safeClassName}" ${lazy ? "data-" : ""}src="${safeSrc}"${network ? ' referrerpolicy="no-referrer"' : ""}/>`;
};
+
+export const unicode2Emoji = (unicode: string, className = "", needSpan = false, lazy = false) => {
+ if (!unicode) {
+ return "";
+ }
+ let emoji = "";
+ const imageHTML = genEmojiImageHTML(unicode, className, lazy);
+ if (imageHTML) {
+ emoji = Lute.Sanitize(imageHTML);
+ } else {
+ try {
+ unicode.split("-").forEach(item => {
+ if (item.length < 5) {
+ emoji += String.fromCodePoint(parseInt("0" + item, 16));
+ } else {
+ emoji += String.fromCodePoint(parseInt(item, 16));
+ }
+ });
+ } catch (e) {
+ // 自定义表情搜索报错 https://github.com/siyuan-note/siyuan/issues/5883
+ // 这里忽略错误不做处理
+ }
+ emoji = Lute.Sanitize(emoji);
+ if (needSpan) {
+ emoji = `<span class="${className}">${emoji}</span>`;
+ }
+ }
+ return emoji;
+};
diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.ts
index 7c7eadefe9..02496e83e6 100644
--- a/app/src/emoji/index.ts
+++ b/app/src/emoji/index.ts
@@ -13,13 +13,13 @@ import {getLuteInstance} from "../protyle/render/setLute";
import * as dayjs from "dayjs";
import {
bindDynamicIconTarget,
- genEmojiImageHTML,
getIconSearchText,
getIconValueKind,
getNetworkIconName,
normalizeNetworkIconURL,
normalizeRecentIconValue,
parseBase64Image,
+ unicode2Emoji,
updateRecentIconValues,
} from "./iconValue";
import {showMessage} from "../dialog/message";
@@ -35,6 +35,9 @@ import {
type TEmojiPanelPageMode,
type TRandomEmojiScope,
} from "./panel";
+import {updateFileTreeItemIcon} from "./fileTreeIcon";
+
+export {unicode2Emoji};
export const getRandomEmoji = (scope: TRandomEmojiScope = "all") => {
const categories = getRandomEmojiCategories(window.siyuan.emojis, scope);
@@ -45,35 +48,6 @@ export const getRandomEmoji = (scope: TRandomEmojiScope = "all") => {
return category.items[getRandom(0, category.items.length - 1)].unicode;
};
-export const unicode2Emoji = (unicode: string, className = "", needSpan = false, lazy = false) => {
- if (!unicode) {
- return "";
- }
- let emoji = "";
- const imageHTML = genEmojiImageHTML(unicode, className, lazy);
- if (imageHTML) {
- emoji = Lute.Sanitize(imageHTML);
- } else {
- try {
- unicode.split("-").forEach(item => {
- if (item.length < 5) {
- emoji += String.fromCodePoint(parseInt("0" + item, 16));
- } else {
- emoji += String.fromCodePoint(parseInt(item, 16));
- }
- });
- } catch (e) {
- // 自定义表情搜索报错 https://github.com/siyuan-note/siyuan/issues/5883
- // 这里忽略错误不做处理
- }
- emoji = Lute.Sanitize(emoji);
- if (needSpan) {
- emoji = `<span class="${className}">${emoji}</span>`;
- }
- }
- return emoji;
-};
-
const genEmojiButton = (unicode: string, label: string, lazy = false) => {
const safeUnicode = escapeAttr(escapeHtml(unicode));
const safeLabel = escapeAttr(escapeHtml(label));
@@ -1602,8 +1576,9 @@ export const updateFileTreeEmoji = (unicode: string, id: string, icon = "iconFil
}
}
/// #endif
- if (emojiElement) {
- emojiElement.innerHTML = unicode2Emoji(unicode || (!isNotebookIcon ? (emojiElement.previousElementSibling.classList.contains("fn__hidden") ? window.siyuan.storage[Constants.LOCAL_IMAGES].file : window.siyuan.storage[Constants.LOCAL_IMAGES].folder) : window.siyuan.storage[Constants.LOCAL_IMAGES].note));
+ const liElement = emojiElement?.closest("li") as HTMLElement | null;
+ if (liElement) {
+ updateFileTreeItemIcon(liElement, unicode, isNotebookIcon ? "notebook" : undefined);
}
};
diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.ts
index bc2495accf..5d76b9b61e 100644
--- a/app/src/layout/dock/Files.ts
+++ b/app/src/layout/dock/Files.ts
@@ -16,7 +16,13 @@ import {
openPublishAccessDialog
} from "../../protyle/util/publishAccess";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
-import {openEmojiPanel, unicode2Emoji} from "../../emoji";
+import {openEmojiPanel} from "../../emoji";
+import {
+ getFileTreeDefaultIconAttr,
+ getFileTreeIconHTML,
+ syncFileTreeItemDefaultIcon,
+ updateFileTreeItemIcon,
+} from "../../emoji/fileTreeIcon";
import {importNotebook, newEncryptedNotebook, newNotebook, openEncryptedNotebook} from "../../util/mount";
import {isNotCtrl, isOnlyMeta, setStorageVal, updateHotkeyAfterTip} from "../../protyle/util/compatibility";
import {openFileById} from "../../editor/util";
@@ -1192,6 +1198,7 @@ export class Files extends Model {
} else {
liElement.querySelector(".b3-list-item__toggle")?.classList.remove("fn__hidden");
}
+ syncFileTreeItemDefaultIcon(liElement);
this.updateDocActionElement(liElement);
}
@@ -1273,6 +1280,7 @@ export class Files extends Model {
if (hiddenElement) {
// 原先无子文档:显示展开箭头
hiddenElement.classList.remove("fn__hidden");
+ syncFileTreeItemDefaultIcon(liElement as HTMLElement);
} else if (liElement.querySelector(".b3-list-item__arrow--open")) {
// 父文档已展开:刷新子列表
this.getLeaf(liElement, notebookId, true);
@@ -1299,21 +1307,19 @@ export class Files extends Model {
this.element.querySelector<HTMLElement>(
`ul[data-url="${data.boxID}"] > li[data-type="navigation-root"]`
);
- const iconElement = liElement?.querySelector<HTMLElement>(".b3-list-item__icon");
- if (iconElement) {
- const iconHTML = unicode2Emoji(data.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].note);
- if (iconElement.innerHTML !== iconHTML) {
- iconElement.innerHTML = iconHTML;
- }
+ if (liElement) {
+ updateFileTreeItemIcon(liElement, data.icon, "notebook");
}
}
private genNotebook(item: INotebook) {
const editingPublishAccess = this.element.classList.contains("file-tree__publish-access--active");
- // 加密笔记本关闭(锁定)时用 🔒 提示需解锁;打开(解锁)后恢复正常 emoji
- const iconContent = (item.encrypted && item.closed)
+ // 加密笔记本关闭(锁定)时用 🔒 提示需解锁
+ const locked = item.encrypted && item.closed;
+ const iconContent = locked
? "🔒️"
- : unicode2Emoji(item.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].note);
+ : getFileTreeIconHTML(item.icon, "notebook");
+ const defaultIconAttr = getFileTreeDefaultIconAttr(item.icon, "notebook", locked);
const isBoxDoc = !item.closed && window.siyuan.config.fileTree.boxDocEnabled;
const hasChildren = !item.closed && item.subFileCount > 0;
const iconExpands = window.siyuan.config.fileTree.docIconClickExpand && hasChildren;
@@ -1326,7 +1332,7 @@ export class Files extends Model {
const emojiHTML = `<span class="b3-list-item__icon ariaLabel${isBoxDoc ? " popover__block" : ""}${editingPublishAccess && !item.encrypted ? " fn__none" : ""}" data-position="8east"${isBoxDoc ? ` data-id="${item.id}"` : ""} aria-label="${iconAriaLabel}">${iconContent}</span>`;
const switchHTML = `<span class="b3-list-item__switch b3-tooltips b3-tooltips__e${editingPublishAccess && !item.encrypted ? "" : " fn__none"}" aria-label="${window.siyuan.languages.publishAccess}">${getPublishAccessOptionByLevel("public").iconHTML}</span>`;
if (item.closed) {
- return `<li data-url="${item.id}" class="b3-list-item b3-list-item--hide-action"${item.encrypted ? ' data-encrypted="true"' : ""}>
+ return `<li data-url="${item.id}" class="b3-list-item b3-list-item--hide-action"${item.encrypted ? ' data-encrypted="true"' : ""}${defaultIconAttr}>
<span class="b3-list-item__toggle fn__hidden">
<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
</span>
@@ -1341,7 +1347,7 @@ export class Files extends Model {
return `<ul class="b3-list b3-list--background" data-url="${item.id}" data-sort="${item.sort}" data-sortmode="${item.sortMode}"${item.encrypted ? " data-encrypted=\"true\"" : ""}>
<li class="b3-list-item b3-list-item--hide-action${actionClasses}" ${window.siyuan.config.fileTree.sort === 6 ? 'draggable="true"' : ""}
style="--file-toggle-width:22px;--file-action-offset:22px"
-data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}" data-node-id="${window.siyuan.config.fileTree.boxDocEnabled ? item.id : ""}">
+data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}" data-node-id="${window.siyuan.config.fileTree.boxDocEnabled ? item.id : ""}"${defaultIconAttr}>
<span class="b3-list-item__toggle b3-list-item__toggle--hl${isBoxDoc && !hasChildren ? " fn__hidden" : ""}">
<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
</span>
@@ -1454,10 +1460,7 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"
}
parentElement.setAttribute("data-count", "0");
this.updateDocActionElement(parentElement);
- const emojiElement = iconElement.parentElement.nextElementSibling;
- if (emojiElement.innerHTML === unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].folder)) {
- emojiElement.innerHTML = unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].file);
- }
+ syncFileTreeItemDefaultIcon(parentElement);
}
targetElement.parentElement.remove();
} else {
@@ -1619,14 +1622,7 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"
);
parentLiElement.setAttribute("data-count", "0");
this.updateDocActionElement(parentLiElement);
- const emojiElement = parentLiElement.querySelector(".b3-list-item__icon");
- if (emojiElement.innerHTML === unicode2Emoji(
- window.siyuan.storage[Constants.LOCAL_IMAGES].folder
- )) {
- emojiElement.innerHTML = unicode2Emoji(
- window.siyuan.storage[Constants.LOCAL_IMAGES].file
- );
- }
+ syncFileTreeItemDefaultIcon(parentLiElement);
}
sourceListElement.remove();
} else {
@@ -1642,6 +1638,7 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"
parentElement.querySelector(".b3-list-item__arrow").classList.remove(
"b3-list-item__arrow--open"
);
+ syncFileTreeItemDefaultIcon(parentElement);
}
}
@@ -1660,10 +1657,7 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"
);
this.updateDocActionElement(targetElement);
}
- const emojiElement = targetElement.querySelector(".b3-list-item__icon");
- if (emojiElement.innerHTML === unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].file)) {
- emojiElement.innerHTML = unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].folder);
- }
+ syncFileTreeItemDefaultIcon(targetElement);
const targetListElement = getFileTreeChildList(targetElement);
const targetExpanded = Boolean(targetElement.querySelector(".b3-list-item__arrow--open"));
@@ -1794,10 +1788,7 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"
const arrowElement = liElement.querySelector(".b3-list-item__arrow");
arrowElement.classList.add("b3-list-item__arrow--open");
arrowElement.parentElement.classList.remove("fn__hidden");
- const emojiElement = liElement.querySelector(".b3-list-item__icon");
- if (emojiElement.textContent === unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].file)) {
- emojiElement.textContent = unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].folder);
- }
+ syncFileTreeItemDefaultIcon(liElement as HTMLElement);
const effectiveSortMode = getResponseEffectiveSortMode(data, data.box);
liElement.insertAdjacentHTML("afterend", `<ul ${FILE_TREE_EFFECTIVE_SORT_MODE}="${effectiveSortMode}">${fileHTML}</ul>`);
this.restoreMovedExpandedItems(liElement.nextElementSibling, data.box);
@@ -1991,14 +1982,15 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"
const actionClasses = `${iconExpands && item.subFileCount > 0 && !editingPublishAccess ? " file-tree__item--icon-expand" : ""}${
iconExpands && item.subFileCount === 0 && !editingPublishAccess ? " file-tree__item--icon-open" : ""}${
window.siyuan.config.fileTree.parentDocClickExpand && item.subFileCount > 0 ? " file-tree__item--title-expand" : ""}`;
+ const defaultIcon = item.subFileCount === 0 ? "file" : "folder";
return `<li data-node-id="${item.id}" data-name="${Lute.EscapeHTMLStr(item.name)}" draggable="true" data-count="${item.subFileCount}" ${FILE_TREE_CHILDREN_SORT_MODE}="${item.childrenSortMode ?? ""}"
data-type="navigation-file"
style="--file-toggle-width:${paddingLeft + 18}px;--file-action-offset:${paddingLeft + 20}px"
-class="b3-list-item b3-list-item--hide-action${actionClasses}" data-path="${item.path}">
+class="b3-list-item b3-list-item--hide-action${actionClasses}" data-path="${item.path}"${getFileTreeDefaultIconAttr(item.icon, defaultIcon)}>
<span style="padding-left: ${paddingLeft}px" class="b3-list-item__toggle b3-list-item__toggle--hl${item.subFileCount === 0 ? " fn__hidden" : ""}">
<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
</span>
- <span class="b3-list-item__icon ariaLabel popover__block${editingPublishAccess ? " fn__none" : ""}" data-position="8east" data-id="${item.id}" aria-label="${iconAriaLabel}">${unicode2Emoji(item.icon || (item.subFileCount === 0 ? window.siyuan.storage[Constants.LOCAL_IMAGES].file : window.siyuan.storage[Constants.LOCAL_IMAGES].folder))}</span>
+ <span class="b3-list-item__icon ariaLabel popover__block${editingPublishAccess ? " fn__none" : ""}" data-position="8east" data-id="${item.id}" aria-label="${iconAriaLabel}">${getFileTreeIconHTML(item.icon, defaultIcon)}</span>
<span class="b3-list-item__switch b3-tooltips b3-tooltips__n${editingPublishAccess ? "" : " fn__none"}" aria-label="${window.siyuan.languages.publishAccess}">${getPublishAccessOptionByLevel("public").iconHTML}</span>
<span class="b3-list-item__text ariaLabel" data-delay="200" data-position="parentE"
aria-label="${ariaLabel}">${getDocDisplayName(item.name, item.titleEmpty, true)}</span>
diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts
index b218ac2c87..c5ec5bf75c 100644
--- a/app/src/menus/navigation.ts
+++ b/app/src/menus/navigation.ts
@@ -41,6 +41,7 @@ import {
getConfiguredChildrenSortMode,
isCustomFileTreeList
} from "../util/fileTreeSort";
+import {syncFileTreeItemDefaultIcon} from "../emoji/fileTreeIcon";
/// #if MOBILE
import {openEmojiPanel} from "../emoji";
import {openMobileFileByIdInNewTab} from "../mobile/editor";
@@ -1007,6 +1008,7 @@ export const genImportMenu = (notebookId: string, pathString: string) => {
/// #endif
const liElement = files.element.querySelector(`[data-path="${pathString}"]`);
liElement.querySelector(".b3-list-item__toggle").classList.remove("fn__hidden");
+ syncFileTreeItemDefaultIcon(liElement as HTMLElement);
files.getLeaf(liElement, notebookId, true);
window.siyuan.menus.menu.remove();
};
diff --git a/app/src/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.ts
index 6d67f4e231..e161a50d13 100644
--- a/app/src/mobile/dock/MobileFiles.ts
+++ b/app/src/mobile/dock/MobileFiles.ts
@@ -12,7 +12,12 @@ import {
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {genUUID} from "../../util/genID";
import {openMobileFileById} from "../editor";
-import {unicode2Emoji} from "../../emoji";
+import {
+ getFileTreeDefaultIconAttr,
+ getFileTreeIconHTML,
+ syncFileTreeItemDefaultIcon,
+ updateFileTreeItemIcon,
+} from "../../emoji/fileTreeIcon";
import {newNotebook, openEncryptedNotebook} from "../../util/mount";
import {newFileInTree} from "../../util/newFile";
import {MenuItem} from "../../menus/Menu";
@@ -677,12 +682,8 @@ export class MobileFiles extends Model {
this.element.querySelector<HTMLElement>(
`ul[data-url="${data.boxID}"] > li[data-type="navigation-root"]`
);
- const iconElement = liElement?.querySelector<HTMLElement>(".b3-list-item__icon");
- if (iconElement) {
- const iconHTML = unicode2Emoji(data.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].note);
- if (iconElement.innerHTML !== iconHTML) {
- iconElement.innerHTML = iconHTML;
- }
+ if (liElement) {
+ updateFileTreeItemIcon(liElement, data.icon, "notebook");
}
}
@@ -769,6 +770,7 @@ export class MobileFiles extends Model {
if (hiddenElement) {
// 原先无子文档:显示展开箭头
hiddenElement.classList.remove("fn__hidden");
+ syncFileTreeItemDefaultIcon(liElement as HTMLElement);
} else if (liElement.querySelector(".b3-list-item__arrow--open")) {
// 父文档已展开:刷新子列表
this.getLeaf(liElement, notebookId, true);
@@ -804,6 +806,7 @@ export class MobileFiles extends Model {
} else {
liElement.querySelector(".b3-list-item__toggle")?.classList.remove("fn__hidden");
}
+ syncFileTreeItemDefaultIcon(liElement);
this.updateDocActionElement(liElement);
}
@@ -838,10 +841,12 @@ export class MobileFiles extends Model {
private genNotebook(item: INotebook) {
const editingPublishAccess = this.actionsElement.querySelector('[data-type="publish-access"]').classList.contains("block__icon--active");
- // 加密笔记本关闭(锁定)时用 🔒 提示需解锁;打开(解锁)后恢复正常 emoji
- const iconContent = (item.encrypted && item.closed)
+ // 加密笔记本关闭(锁定)时用 🔒 提示需解锁
+ const locked = item.encrypted && item.closed;
+ const iconContent = locked
? "🔒️"
- : unicode2Emoji(item.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].note);
+ : getFileTreeIconHTML(item.icon, "notebook");
+ const defaultIconAttr = getFileTreeDefaultIconAttr(item.icon, "notebook", locked);
const isBoxDoc = !item.closed && window.siyuan.config.fileTree.boxDocEnabled;
const hasChildren = isBoxDoc && item.subFileCount > 0;
const iconAriaLabel = isBoxDoc ?
@@ -850,7 +855,7 @@ export class MobileFiles extends Model {
const emojiHTML = `<span class="b3-list-item__icon b3-tooltips b3-tooltips__e${editingPublishAccess && !item.encrypted ? " fn__none" : ""}" aria-label="${iconAriaLabel}">${iconContent}</span>`;
const switchHTML = `<span class="b3-list-item__switch b3-tooltips b3-tooltips__e${editingPublishAccess && !item.encrypted ? "" : " fn__none"}" aria-label="${window.siyuan.languages.publishAccess}">${getPublishAccessOptionByLevel("public").iconHTML}</span>`;
if (item.closed) {
- return `<li data-url="${item.id}" class="b3-list-item"${item.encrypted ? ' data-encrypted="true"' : ""}>
+ return `<li data-url="${item.id}" class="b3-list-item"${item.encrypted ? ' data-encrypted="true"' : ""}${defaultIconAttr}>
<span class="b3-list-item__toggle fn__hidden">
<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
</span>
@@ -863,7 +868,7 @@ export class MobileFiles extends Model {
</li>`;
} else {
return `<ul class="b3-list b3-list--background" data-url="${item.id}" data-sortmode="${item.sortMode}"${item.encrypted ? " data-encrypted=\"true\"" : ""}>
-<li class="b3-list-item" data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}" data-node-id="${window.siyuan.config.fileTree.boxDocEnabled ? item.id : ""}" style="--file-toggle-width:24px">
+<li class="b3-list-item" data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}" data-node-id="${window.siyuan.config.fileTree.boxDocEnabled ? item.id : ""}" style="--file-toggle-width:24px"${defaultIconAttr}>
<span class="b3-list-item__toggle${isBoxDoc && !hasChildren ? " fn__hidden" : ""}">
<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
</span>
@@ -956,14 +961,7 @@ export class MobileFiles extends Model {
);
parentLiElement.setAttribute("data-count", "0");
this.updateDocActionElement(parentLiElement);
- const emojiElement = parentLiElement.querySelector(".b3-list-item__icon");
- if (emojiElement.innerHTML === unicode2Emoji(
- window.siyuan.storage[Constants.LOCAL_IMAGES].folder
- )) {
- emojiElement.innerHTML = unicode2Emoji(
- window.siyuan.storage[Constants.LOCAL_IMAGES].file
- );
- }
+ syncFileTreeItemDefaultIcon(parentLiElement);
}
sourceListElement.remove();
} else {
@@ -979,6 +977,7 @@ export class MobileFiles extends Model {
parentElement.querySelector(".b3-list-item__arrow").classList.remove(
"b3-list-item__arrow--open"
);
+ syncFileTreeItemDefaultIcon(parentElement);
}
}
@@ -997,10 +996,7 @@ export class MobileFiles extends Model {
);
this.updateDocActionElement(targetElement);
}
- const emojiElement = targetElement.querySelector(".b3-list-item__icon");
- if (emojiElement.innerHTML === unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].file)) {
- emojiElement.innerHTML = unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].folder);
- }
+ syncFileTreeItemDefaultIcon(targetElement);
const targetListElement = getFileTreeChildList(targetElement);
const targetExpanded = Boolean(targetElement.querySelector(".b3-list-item__arrow--open"));
@@ -1099,10 +1095,7 @@ export class MobileFiles extends Model {
}
parentElement.setAttribute("data-count", "0");
this.updateDocActionElement(parentElement);
- const emojiElement = iconElement.parentElement.nextElementSibling;
- if (emojiElement.innerHTML === unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].folder)) {
- emojiElement.innerHTML = unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].file);
- }
+ syncFileTreeItemDefaultIcon(parentElement);
}
targetElement.parentElement.remove();
} else {
@@ -1298,10 +1291,7 @@ export class MobileFiles extends Model {
const arrowElement = liElement.querySelector(".b3-list-item__arrow");
arrowElement.classList.add("b3-list-item__arrow--open");
arrowElement.parentElement.classList.remove("fn__hidden");
- const emojiElement = liElement.querySelector(".b3-list-item__icon");
- if (emojiElement.textContent === unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].file)) {
- emojiElement.textContent = unicode2Emoji(window.siyuan.storage[Constants.LOCAL_IMAGES].folder);
- }
+ syncFileTreeItemDefaultIcon(liElement as HTMLElement);
const effectiveSortMode = getResponseEffectiveSortMode(data, data.box);
liElement.insertAdjacentHTML("afterend", `<ul ${FILE_TREE_EFFECTIVE_SORT_MODE}="${effectiveSortMode}">${fileHTML}</ul>`);
this.restoreMovedExpandedItems(liElement.nextElementSibling, data.box);
@@ -1464,12 +1454,13 @@ export class MobileFiles extends Model {
}
const paddingLeft = (item.path.split("/").length - 1) * 20;
const editingPublishAccess = this.actionsElement.querySelector('[data-type="publish-access"]').classList.contains("block__icon--active");
+ const defaultIcon = item.subFileCount === 0 ? "file" : "folder";
return `<li data-node-id="${item.id}" data-name="${Lute.EscapeHTMLStr(item.name)}" data-count="${item.subFileCount}" ${FILE_TREE_CHILDREN_SORT_MODE}="${item.childrenSortMode ?? ""}" data-type="navigation-file"
-class="b3-list-item" data-path="${item.path}" style="--file-toggle-width:${paddingLeft + 20}px" >
+class="b3-list-item" data-path="${item.path}" style="--file-toggle-width:${paddingLeft + 20}px"${getFileTreeDefaultIconAttr(item.icon, defaultIcon)}>
<span style="padding-left: ${paddingLeft}px" class="b3-list-item__toggle${item.subFileCount === 0 ? " fn__hidden" : ""}">
<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
</span>
- <span class="b3-list-item__icon"${editingPublishAccess ? " fn__none" : ""}>${unicode2Emoji(item.icon || (item.subFileCount === 0 ? window.siyuan.storage[Constants.LOCAL_IMAGES].file : window.siyuan.storage[Constants.LOCAL_IMAGES].folder))}</span>
+ <span class="b3-list-item__icon"${editingPublishAccess ? " fn__none" : ""}>${getFileTreeIconHTML(item.icon, defaultIcon)}</span>
<span class="b3-list-item__switch${editingPublishAccess ? "" : " fn__none"}">${getPublishAccessOptionByLevel("public").iconHTML}</span>
<span class="b3-list-item__text">${getDocDisplayName(item.name, item.titleEmpty, true)}</span>
<span data-type="more-file" class="b3-list-item__action b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.more}">
diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts
index b70fd7447a..3f406902a8 100644
--- a/app/src/types/config.d.ts
+++ b/app/src/types/config.d.ts
@@ -896,6 +896,10 @@ declare namespace Config {
* Whether to enable top-level notebook documents
*/
boxDocEnabled: boolean;
+ /**
+ * Whether to use SVG icons as the default icons for notebooks and documents
+ */
+ useSVGDefaultIcon: boolean;
/**
* Whether to close all tabs when starting
*/
diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts
index 8759d2e90e..890c107747 100644
--- a/app/src/util/pathName.ts
+++ b/app/src/util/pathName.ts
@@ -4,8 +4,8 @@ import {Dialog} from "../dialog";
import {escapeAriaLabel, escapeHtml} from "./escape";
import {isMobile} from "./functions";
import {focusByRange} from "../protyle/util/selection";
-import {unicode2Emoji} from "../emoji";
import {Constants} from "../constants";
+import {getFileTreeDefaultIconAttr, getFileTreeIconHTML} from "../emoji/fileTreeIcon";
/// #if !BROWSER
import {ipcRenderer} from "electron";
/// #endif
@@ -303,11 +303,11 @@ export const movePathTo = (options: {
<span class="counter counter--right b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.flashcardCard}">${item.flashcardCount}</span>`;
}
html += `<ul class="b3-list b3-list--background">
-<li class="b3-list-item${html === "" ? " b3-list-item--focus" : ""}" data-path="/" data-box="${item.id}">
+<li class="b3-list-item${html === "" ? " b3-list-item--focus" : ""}" data-path="/" data-box="${item.id}"${getFileTreeDefaultIconAttr(item.icon, "notebook")}>
<span class="b3-list-item__toggle b3-list-item__toggle--hl">
<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
</span>
- ${unicode2Emoji(item.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].note, "b3-list-item__graphic", true)}
+ ${getFileTreeIconHTML(item.icon, "notebook", "b3-list-item__graphic", true)}
<span class="b3-list-item__text">${escapeHtml(item.name)}</span>
${countHTML}
</li></ul>`;
@@ -355,8 +355,8 @@ export const movePathTo = (options: {
<span class="counter counter--right b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.flashcardDueCard}">${item.dueFlashcardCount}</span>
<span class="counter counter--right b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.flashcardCard}">${item.flashcardCount}</span>`;
}
- fileHTML += `<li class="b3-list-item${fileHTML === "" ? " b3-list-item--focus" : ""}" data-path="${item.path}" data-box="${item.box}">
- ${unicode2Emoji(item.boxIcon || window.siyuan.storage[Constants.LOCAL_IMAGES].note, "b3-list-item__graphic", true)}
+ fileHTML += `<li class="b3-list-item${fileHTML === "" ? " b3-list-item--focus" : ""}" data-path="${item.path}" data-box="${item.box}"${getFileTreeDefaultIconAttr(item.boxIcon, "notebook")}>
+ ${getFileTreeIconHTML(item.boxIcon, "notebook", "b3-list-item__graphic", true)}
<span class="b3-list-item__showall" style="padding: 4px 0">${escapeHtml(item.hPath)}</span>
${countHTML}
</li>`;
@@ -725,11 +725,12 @@ const getLeaf = (liElement: HTMLElement, flashcard: boolean) => {
} else if (item.count && item.count > 0) {
countHTML = `<span class="popover__block counter b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.ref}">${item.count}</span>`;
}
- fileHTML += `<li data-box="${notebookId}" class="b3-list-item" data-path="${item.path}">
+ const defaultIcon = item.subFileCount === 0 ? "file" : "folder";
+ fileHTML += `<li data-box="${notebookId}" class="b3-list-item" data-path="${item.path}"${getFileTreeDefaultIconAttr(item.icon, defaultIcon)}>
<span style="padding-left: ${item.path.split("/").length * 8}px" class="b3-list-item__toggle b3-list-item__toggle--hl${item.subFileCount === 0 ? " fn__hidden" : ""}">
<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
</span>
- ${unicode2Emoji(item.icon || (item.subFileCount === 0 ? window.siyuan.storage[Constants.LOCAL_IMAGES].file : window.siyuan.storage[Constants.LOCAL_IMAGES].folder), "b3-list-item__graphic", true)}
+ ${getFileTreeIconHTML(item.icon, defaultIcon, "b3-list-item__graphic", true)}
<span class="b3-list-item__text ariaLabel" data-position="parentE" aria-label="${getDocDisplayName(item.name, item.titleEmpty, true)} <small class='ft__on-surface'>${item.hSize}</small>${item.bookmark ? "<br>" + window.siyuan.languages.bookmark + " " + escapeAriaLabel(item.bookmark) : ""}${item.name1 ? "<br>" + window.siyuan.languages.name + " " + escapeAriaLabel(item.name1) : ""}${item.alias ? "<br>" + window.siyuan.languages.alias + " " + escapeAriaLabel(item.alias) : ""}${item.memo ? "<br>" + window.siyuan.languages.memo + " " + escapeAriaLabel(item.memo) : ""}${item.subFileCount !== 0 ? window.siyuan.languages.includeSubFile.replace("x", item.subFileCount) : ""}<br>${window.siyuan.languages.modifiedAt} ${item.hMtime}<br>${window.siyuan.languages.createdAt} ${item.hCtime}">${getDocDisplayName(item.name, item.titleEmpty, true)}</span>
${countHTML}
</li>`;
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index 3da5ff176c..5f1e64a428 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -586,6 +586,7 @@ func setFiletree(c *gin.Context) {
fileTree := conf.NewFileTree()
fileTree.BoxDocEnabled = nil
+ fileTree.UseSVGDefaultIcon = nil
if err = gulu.JSON.UnmarshalJSON(param, fileTree); err != nil {
ret.Code = -1
ret.Msg = err.Error()
@@ -598,6 +599,13 @@ func setFiletree(c *gin.Context) {
fileTree.BoxDocEnabled = new(bool)
}
}
+ if nil == fileTree.UseSVGDefaultIcon {
+ if nil != model.Conf.FileTree && nil != model.Conf.FileTree.UseSVGDefaultIcon {
+ fileTree.UseSVGDefaultIcon = model.Conf.FileTree.UseSVGDefaultIcon
+ } else {
+ fileTree.UseSVGDefaultIcon = new(bool)
+ }
+ }
oldBoxDocEnabled := model.IsBoxDocEnabled()
fileTree.DocCreateSavePath = util.TrimSpaceInPath(fileTree.DocCreateSavePath)
diff --git a/kernel/api/setting_test.go b/kernel/api/setting_test.go
index 0198bc58b7..665d789c3c 100644
--- a/kernel/api/setting_test.go
+++ b/kernel/api/setting_test.go
@@ -16,7 +16,18 @@
package api
-import "testing"
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/conf"
+ "github.com/siyuan-note/siyuan/kernel/model"
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
func TestBazaarPluginReloadExcludeApp(t *testing.T) {
for _, test := range []struct {
@@ -35,3 +46,49 @@ func TestBazaarPluginReloadExcludeApp(t *testing.T) {
})
}
}
+
+func TestSetFiletreePreservesUseSVGDefaultIconWhenMissing(t *testing.T) {
+ gin.SetMode(gin.TestMode)
+ previousConf := model.Conf
+ previousReadOnly := util.ReadOnly
+ util.ReadOnly = true
+ t.Cleanup(func() {
+ model.Conf = previousConf
+ util.ReadOnly = previousReadOnly
+ })
+
+ engine := gin.New()
+ engine.POST("/api/setting/setFiletree", setFiletree)
+ for _, test := range []struct {
+ name string
+ enabled bool
+ }{
+ {name: "enabled", enabled: true},
+ {name: "disabled"},
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ model.Conf = model.NewAppConf()
+ model.Conf.FileTree = conf.NewFileTree()
+ model.Conf.FileTree.UseSVGDefaultIcon = new(test.enabled)
+
+ recorder := httptest.NewRecorder()
+ request := httptest.NewRequest(http.MethodPost, "/api/setting/setFiletree", strings.NewReader(`{}`))
+ request.Header.Set("Content-Type", "application/json")
+ engine.ServeHTTP(recorder, request)
+
+ response := &struct {
+ Code int `json:"code"`
+ }{}
+ if err := json.Unmarshal(recorder.Body.Bytes(), response); err != nil {
+ t.Fatalf("unmarshal setFiletree response failed: %v", err)
+ }
+ if 0 != response.Code {
+ t.Fatalf("setFiletree failed: %s", recorder.Body.String())
+ }
+ if nil == model.Conf.FileTree.UseSVGDefaultIcon ||
+ test.enabled != *model.Conf.FileTree.UseSVGDefaultIcon {
+ t.Fatalf("missing setting changed the current value: %#v", model.Conf.FileTree.UseSVGDefaultIcon)
+ }
+ })
+ }
+}
diff --git a/kernel/conf/filetree.go b/kernel/conf/filetree.go
index bda1d3193f..1de4f13d43 100644
--- a/kernel/conf/filetree.go
+++ b/kernel/conf/filetree.go
@@ -27,6 +27,7 @@ type FileTree struct {
DocIconClickExpand bool `json:"docIconClickExpand"` // 单击文档或笔记本图标时展开或折叠下级文档
ParentDocClickExpand bool `json:"parentDocClickExpand"` // 单击父文档标题时展开或折叠下级文档
BoxDocEnabled *bool `json:"boxDocEnabled"` // 是否启用顶层笔记本文档
+ UseSVGDefaultIcon *bool `json:"useSVGDefaultIcon"` // 是否使用 SVG 默认图标
RefCreateSaveBox string `json:"refCreateSaveBox"` // 块引时新建文档存储笔记本
RefCreateSavePath string `json:"refCreateSavePath"` // 块引时新建文档存储路径
DocCreateSaveBox string `json:"docCreateSaveBox"` // 新建文档存储笔记本
@@ -56,6 +57,7 @@ func NewFileTree() *FileTree {
DocIconClickExpand: false,
ParentDocClickExpand: false,
BoxDocEnabled: new(bool),
+ UseSVGDefaultIcon: new(true),
Sort: util.SortModeCustom,
MaxListCount: 512,
MaxOpenTabCount: 8,
diff --git a/kernel/conf/filetree_test.go b/kernel/conf/filetree_test.go
index 7695bb7d63..a7e69c0fe0 100644
--- a/kernel/conf/filetree_test.go
+++ b/kernel/conf/filetree_test.go
@@ -18,7 +18,7 @@ package conf
import "testing"
-func TestNewFileTreeDisablesBoxDoc(t *testing.T) {
+func TestNewFileTreeDefaults(t *testing.T) {
fileTree := NewFileTree()
if nil == fileTree.BoxDocEnabled {
t.Fatal("box document setting should be initialized")
@@ -26,4 +26,10 @@ func TestNewFileTreeDisablesBoxDoc(t *testing.T) {
if *fileTree.BoxDocEnabled {
t.Fatal("box documents should be disabled for new users")
}
+ if nil == fileTree.UseSVGDefaultIcon {
+ t.Fatal("default icon setting should be initialized")
+ }
+ if !*fileTree.UseSVGDefaultIcon {
+ t.Fatal("SVG default icons should be enabled for new users")
+ }
}
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 69ab51bfe8..046071027f 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -396,9 +396,7 @@ func InitConf() {
Conf.Appearance.Notifications = util.NewNotifications()
}
util.NotificationsCfg = Conf.Appearance.Notifications
- if nil == Conf.FileTree {
- Conf.FileTree = conf.NewFileTree()
- }
+ Conf.FileTree = normalizeFileTreeDefaultIcon(Conf.FileTree, confFileExists)
if 1 > Conf.FileTree.MaxListCount {
Conf.FileTree.MaxListCount = 512
}
@@ -887,6 +885,21 @@ func InitConf() {
go util.InitTesseract()
}
+func normalizeFileTreeDefaultIcon(fileTree *conf.FileTree, confFileExists bool) *conf.FileTree {
+ if nil == fileTree {
+ fileTree = conf.NewFileTree()
+ if confFileExists {
+ fileTree.UseSVGDefaultIcon = new(bool)
+ }
+ return fileTree
+ }
+ if nil == fileTree.UseSVGDefaultIcon {
+ useSVGDefaultIcon := !confFileExists
+ fileTree.UseSVGDefaultIcon = &useSVGDefaultIcon
+ }
+ return fileTree
+}
+
func readCookieKey() (cookieKey string) {
cookieKeyPath := filepath.Join(util.HomeDir, ".config", "siyuan", "cookie.key")
if !gulu.File.IsExist(cookieKeyPath) {
diff --git a/kernel/model/conf_filetree_test.go b/kernel/model/conf_filetree_test.go
new file mode 100644
index 0000000000..31fcb5ca07
--- /dev/null
+++ b/kernel/model/conf_filetree_test.go
@@ -0,0 +1,57 @@
+// SiYuan - From thought to insight, with agents
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package model
+
+import (
+ "testing"
+
+ "github.com/siyuan-note/siyuan/kernel/conf"
+)
+
+func TestNormalizeFileTreeDefaultIcon(t *testing.T) {
+ for _, test := range []struct {
+ name string
+ fileTree *conf.FileTree
+ confFileExists bool
+ want bool
+ }{
+ {name: "new user", want: true},
+ {name: "existing configuration without file tree", confFileExists: true},
+ {name: "existing configuration without setting", fileTree: &conf.FileTree{}, confFileExists: true},
+ {
+ name: "existing configuration with setting enabled",
+ fileTree: &conf.FileTree{UseSVGDefaultIcon: new(true)},
+ confFileExists: true,
+ want: true,
+ },
+ {
+ name: "existing configuration with setting disabled",
+ fileTree: &conf.FileTree{UseSVGDefaultIcon: new(false)},
+ confFileExists: true,
+ },
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ fileTree := normalizeFileTreeDefaultIcon(test.fileTree, test.confFileExists)
+ if nil == fileTree.UseSVGDefaultIcon {
+ t.Fatal("default icon setting should be initialized")
+ }
+ if test.want != *fileTree.UseSVGDefaultIcon {
+ t.Fatalf("unexpected default icon setting: got %t, want %t", *fileTree.UseSVGDefaultIcon, test.want)
+ }
+ })
+ }
+}