mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
fix: startup error and settings tab reset issues
- Handle missing file explorer during early startup to prevent "Cannot read properties of undefined" error - Use renderSettingsPage instead of display when adding excluded/ whitelisted folders to stay on current settings tab Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
88cb9541f0
commit
a044e6c2eb
4 changed files with 16 additions and 11 deletions
|
|
@ -40,7 +40,7 @@ export default class WhitelistedFoldersSettings extends Modal {
|
|||
this.plugin.settingsTab, contentEl, whitelistedFolder,
|
||||
);
|
||||
addWhitelistedFolder(this.plugin, whitelistedFolder);
|
||||
this.settingsTab.display();
|
||||
this.settingsTab.renderSettingsPage(this.settingsTab.plugin.settings.settingsTab);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,10 @@ import type FolderOverviewPlugin from 'src/obsidian-folder-overview/src/main';
|
|||
* @description Refreshes the CSS classes for all folder notes in the file explorer.
|
||||
*/
|
||||
export function refreshAllFolderStyles(forceReload = false, plugin: FolderNotesPlugin): void {
|
||||
if (plugin.activeFileExplorer === getFileExplorer(plugin) && !forceReload) { return; }
|
||||
plugin.activeFileExplorer = getFileExplorer(plugin);
|
||||
const fileExplorer = getFileExplorer(plugin);
|
||||
if (!fileExplorer) { return; }
|
||||
if (plugin.activeFileExplorer === fileExplorer && !forceReload) { return; }
|
||||
plugin.activeFileExplorer = fileExplorer;
|
||||
plugin.app.vault.getAllLoadedFiles().forEach(async (file) => {
|
||||
if (file instanceof TFolder) {
|
||||
await updateCSSClassesForFolder(file.path, plugin);
|
||||
|
|
|
|||
|
|
@ -42,15 +42,17 @@ export function getParentFolderPath(path: string): string {
|
|||
|
||||
export function getFileExplorer(
|
||||
plugin: FolderNotesPlugin | FolderOverviewPlugin,
|
||||
): FileExplorerWorkspaceLeaf {
|
||||
): FileExplorerWorkspaceLeaf | undefined {
|
||||
// eslint-disable-next-line max-len
|
||||
let leaf = plugin.app.workspace.getLeavesOfType('file-explorer')[0] as unknown as FileExplorerWorkspaceLeaf;
|
||||
|
||||
if (!leaf) { return undefined; }
|
||||
|
||||
/* make.md plugin integration */
|
||||
if (leaf.containerEl.lastChild.dataset.type == 'mk-path-view') {
|
||||
if ((leaf.containerEl?.lastChild as HTMLElement)?.dataset?.type == 'mk-path-view') {
|
||||
plugin.app.workspace.iterateAllLeaves((x) => {
|
||||
if (x.tabHeaderEl.dataset.type == 'file-explorer') {
|
||||
leaf = x;
|
||||
if ((x as FileExplorerWorkspaceLeaf).tabHeaderEl?.dataset?.type == 'file-explorer') {
|
||||
leaf = x as FileExplorerWorkspaceLeaf;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -58,12 +60,13 @@ export function getFileExplorer(
|
|||
return leaf;
|
||||
}
|
||||
|
||||
export function getFileExplorerView(plugin: FolderNotesPlugin): FileExplorerView {
|
||||
return getFileExplorer(plugin).view;
|
||||
export function getFileExplorerView(plugin: FolderNotesPlugin): FileExplorerView | undefined {
|
||||
return getFileExplorer(plugin)?.view;
|
||||
}
|
||||
|
||||
export function getFocusedItem(plugin: FolderNotesPlugin): TreeNode<FileTreeItem> | null {
|
||||
const fileExplorer = getFileExplorer(plugin) as unknown as FileExplorerLeaf;
|
||||
const fileExplorer = getFileExplorer(plugin) as unknown as FileExplorerLeaf | undefined;
|
||||
if (!fileExplorer) { return null; }
|
||||
const { focusedItem } = fileExplorer.view.tree;
|
||||
return focusedItem;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ export async function renderExcludeFolders(settingsTab: SettingsTab): Promise<vo
|
|||
);
|
||||
addExcludeFolderListItem(settingsTab, containerEl, excludedFolder);
|
||||
addExcludedFolder(settingsTab.plugin, excludedFolder);
|
||||
settingsTab.display();
|
||||
settingsTab.renderSettingsPage(settingsTab.plugin.settings.settingsTab);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue