cleaning custom icons

This commit is contained in:
2025-06-25 21:49:48 +02:00
parent d821344ade
commit 46a5d3d114
2 changed files with 11 additions and 228 deletions
+7 -55
View File
@@ -1,8 +1,10 @@
<script lang="ts">
import { setIcon, TFile } from 'obsidian'
import { showExcerpt } from 'src/settings/utils'
import { onMount } from 'svelte'
import type { ResultNote } from '../globals'
import type LocatorPlugin from '../main'
import { getDefaultIconSVG } from '../tools/icon-utils'
import {
getExtension,
isFileCanvas,
@@ -12,15 +14,6 @@
pathWithoutFilename,
} from '../tools/utils'
import ResultItemContainer from './ResultItemContainer.svelte'
// Import icon utility functions
import { showExcerpt } from 'src/settings/utils'
import {
getDefaultIconSVG,
getIconNameForPath,
initializeIconPacks,
loadIconData,
loadIconSVG,
} from '../tools/icon-utils'
export let selected = false
export let note: ResultNote
@@ -29,19 +22,12 @@
let imagePath: string | null = null
let title = ''
let notePath = ''
let iconData = {}
let folderIconSVG: string | null = null
let fileIconSVG: string | null = null
let prefixToIconPack: { [prefix: string]: string } = {}
let iconsPath: string
const folderIconSVG = getDefaultIconSVG('folder')
const fileIconSVG = getDefaultIconSVG(note.path)
let iconDataLoaded = false // Flag to indicate iconData is loaded
// Initialize icon data and icon packs once when the component mounts
onMount(async () => {
iconData = await loadIconData(plugin)
const iconPacks = await initializeIconPacks(plugin)
prefixToIconPack = iconPacks.prefixToIconPack
iconsPath = iconPacks.iconsPath
iconDataLoaded = true // Set the flag after iconData is loaded
})
@@ -51,40 +37,9 @@
// Update title and notePath before loading icons
title = note.displayTitle || note.basename
notePath = pathWithoutFilename(note.path)
await loadIcons()
})()
}
async function loadIcons() {
// Load folder icon
const folderIconName = getIconNameForPath(notePath, iconData)
if (folderIconName) {
folderIconSVG = await loadIconSVG(
folderIconName,
plugin,
iconsPath,
prefixToIconPack
)
} else {
// Fallback to default folder icon
folderIconSVG = getDefaultIconSVG('folder', plugin)
}
// Load file icon
const fileIconName = getIconNameForPath(note.path, iconData)
if (fileIconName) {
fileIconSVG = await loadIconSVG(
fileIconName,
plugin,
iconsPath,
prefixToIconPack
)
} else {
// Fallback to default icons based on file type
fileIconSVG = getDefaultIconSVG(note.path, plugin)
}
}
// Svelte action to render SVG content with dynamic updates
function renderSVG(node: HTMLElement, svgContent: string) {
node.innerHTML = svgContent
@@ -163,9 +118,7 @@
title="The document above is embedded in this note" />
{:else}
<!-- File Icon -->
{#if fileIconSVG}
<span class="omnisearch-result__icon" use:renderSVG={fileIconSVG} />
{/if}
<span class="omnisearch-result__icon" use:renderSVG={fileIconSVG} />
{/if}
<span>
{@html plugin.textProcessor.highlightText(title, matchesTitle)}
@@ -191,9 +144,8 @@
{#if notePath}
<div class="omnisearch-result__folder-path">
<!-- Folder Icon -->
{#if folderIconSVG}
<span class="omnisearch-result__icon" use:renderSVG={folderIconSVG} />
{/if}
<span class="omnisearch-result__icon" use:renderSVG={folderIconSVG} />
<span>
{@html plugin.textProcessor.highlightText(notePath, matchesNotePath)}
</span>