Skip to content

Commit

Permalink
feat(internal-plugins): add functionality of adding icons for outline (
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWoelki committed Jun 22, 2024
1 parent 186faa7 commit 9e1ca69
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/@types/internal-plugin-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default abstract class InternalPluginInjector {
) as unknown as FileExplorerWorkspaceLeaf[];
}

// eslint-disable-next-line
onMount(): void {}

abstract get enabled(): boolean;
Expand Down
33 changes: 31 additions & 2 deletions src/internal-plugins/outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import InternalPluginInjector from '@app/@types/internal-plugin-injector';
import { createIconShortcodeRegex } from '@app/editor/markdown-processors';
import svg from '@app/lib/util/svg';
import icon from '@app/lib/icon';
import { logger } from '@app/lib/logger';
import { LoggerPrefix, logger } from '@app/lib/logger';
import IconFolderPlugin from '@app/main';
import { View } from 'obsidian';

Expand All @@ -23,7 +23,8 @@ export default class OutlineInternalPlugin extends InternalPluginInjector {
register(): void {
if (!this.enabled) {
logger.info(
`Outline: Skipping internal plugin registration because it is not enabled.`,
'Skipping internal plugin registration because it is not enabled.',
LoggerPrefix.Outline,
);
return;
}
Expand Down Expand Up @@ -91,16 +92,44 @@ export default class OutlineInternalPlugin extends InternalPluginInjector {

this.plugin.getEventEmitter().once('allIconsLoaded', () => {
updateTreeItems();

const callback = (mutations: MutationRecord[]) => {
mutations.forEach((mutation) => {
if (mutation.type !== 'childList') {
return;
}

const addedNodes = mutation.addedNodes;
if (addedNodes.length === 0) {
return;
}

updateTreeItems();
});

if (!this.enabled) {
observer.disconnect();
}
};

const observer = new MutationObserver(callback);

observer.observe(this.leaf.tree.containerEl, {
childList: true,
subtree: true,
});
});
}

get leaf(): OutlineView | undefined {
const leaf = this.plugin.app.workspace.getLeavesOfType('outline');
if (!leaf) {
logger.log('`leaf` in outline is undefined', LoggerPrefix.Outline);
return undefined;
}

if (leaf.length === 0) {
logger.log('`leaf` length in outline is 0', LoggerPrefix.Outline);
return undefined;
}

Expand Down

0 comments on commit 9e1ca69

Please sign in to comment.