Fix fmtp collapsed folder issue

See #168
This commit is contained in:
Lost Paul 2025-05-29 16:05:41 +02:00
parent a050c2673c
commit 04e611fb97

View file

@ -13,6 +13,7 @@ export async function addObserver(plugin: FolderNotesPlugin) {
.forEach(async (element: HTMLElement) => {
let folderTitle = element.querySelector('div.nav-folder-title-content') as HTMLElement;
const filePath = folderTitle.parentElement?.getAttribute('data-path') || '';
applyFMTPStyles(plugin, filePath, folderTitle);
applyCSSClassesToFolder(filePath, plugin);
@ -22,6 +23,10 @@ export async function addObserver(plugin: FolderNotesPlugin) {
const observer = new MutationObserver(async (mutations, obs) => {
folderTitle = element.querySelector('div.nav-folder-title-content') as HTMLElement;
const filePath = folderTitle.parentElement?.getAttribute('data-path') || '';
applyFMTPStyles(plugin, filePath, folderTitle);
if (folderTitle) {
await initializeFolderTitle(folderTitle, plugin);
obs.disconnect();
@ -77,6 +82,19 @@ export async function addObserver(plugin: FolderNotesPlugin) {
});
}
function applyFMTPStyles(plugin: FolderNotesPlugin, filePath: string, folderTitle: HTMLElement) {
if (!plugin.settings.frontMatterTitle.enabled) { return; }
const folder = plugin.fmtpHandler?.modifiedFolders.get(filePath);
if (folder && plugin.settings.frontMatterTitle.path) {
folderTitle.setAttribute('old-name', folder.name || '');
folderTitle.innerText = folder.newName || '';
} else {
folderTitle.removeAttribute('old-name');
folderTitle.innerText = folderTitle.innerText.trim();
}
}
async function initializeFolderTitle(folderTitle: HTMLElement, plugin: any) {
if (folderTitle.onclick) return;
if (Platform.isMobile && plugin.settings.disableOpenFolderNoteOnClick) return;