diff --git a/src/MatrixView.ts b/src/MatrixView.ts index 91b55f46..7f08cbb3 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -1,3 +1,4 @@ +import { internalLinkObj } from "./interfaces"; import type { Graph } from "graphlib"; import { ItemView, TFile, WorkspaceLeaf } from "obsidian"; import { @@ -88,16 +89,24 @@ export default class MatrixView extends ItemView { return internalLinkObjArr; } - // removeDuplicateImpliedLinks(real: internalLinkObj[], implied: internalLinkObj[]) { - // real.forEach(realItem => { - // implied.forEach(impliedItem => { - // if(impliedItem.to === realItem.to) { - // implied - // } - - // }) - // }) - // } + // ANCHOR Remove duplicate implied links + + removeDuplicateImplied( + real: internalLinkObj[], + implied: internalLinkObj[] + ): void { + const impliedTos: [string, number][] = implied.map((impliedObj, i) => [ + impliedObj.to, + i, + ]); + real.forEach((realItem) => { + impliedTos.forEach((impliedTo) => { + if (impliedTo[0] === realItem.to) { + implied.splice(impliedTo[1], 1); + } + }); + }); + } async draw(): Promise { this.contentEl.empty(); @@ -161,6 +170,10 @@ export default class MatrixView extends ItemView { }); } + this.removeDuplicateImplied(realParents, impliedParents); + this.removeDuplicateImplied(realSiblings, impliedSiblingsArr); + this.removeDuplicateImplied(realChildren, impliedChildren); + const parentsSquare: SquareProps = { realItems: realParents, impliedItems: impliedParents, diff --git a/src/main.ts b/src/main.ts index 033afe0f..99615afb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -54,7 +54,6 @@ export default class BreadcrumbsPlugin extends Plugin { (leaf: WorkspaceLeaf) => (this.matrixView = new MatrixView(leaf, this)) ); - this.initView(VIEW_TYPE_BREADCRUMBS_MATRIX); this.trailDiv = createDiv({ @@ -71,9 +70,9 @@ export default class BreadcrumbsPlugin extends Plugin { this.registerEvent( this.app.workspace.on("active-leaf-change", async () => { + this.currGraphs = await this.initGraphs(); + await this.matrixView.draw(); if (this.settings.showTrail) { - this.currGraphs = await this.initGraphs(); - await this.matrixView.draw(); await this.drawTrail(this.currGraphs.gParents); } }) @@ -101,7 +100,7 @@ export default class BreadcrumbsPlugin extends Plugin { ); this.addCommand({ - id: "show-breadcrumb-matrix-view", + id: "show-breadcrumbs-matrix-view", name: "Open Matrix View", checkCallback: (checking: boolean) => { if (checking) { @@ -240,7 +239,9 @@ export default class BreadcrumbsPlugin extends Plugin { initView = async (type: string): Promise => { let leaf: WorkspaceLeaf = null; for (leaf of this.app.workspace.getLeavesOfType(type)) { - if (leaf.view instanceof MatrixView) return; + if (leaf.view instanceof MatrixView) { + return; + } await leaf.setViewState({ type: "empty" }); break; } @@ -259,10 +260,13 @@ export default class BreadcrumbsPlugin extends Plugin { } onunload(): void { + console.log("unloading"); // Detach matrix view - this.app.workspace - .getLeavesOfType(VIEW_TYPE_BREADCRUMBS_MATRIX) - .forEach((leaf) => leaf.detach()); + const openLeaves = this.app.workspace.getLeavesOfType( + VIEW_TYPE_BREADCRUMBS_MATRIX + ); + console.log(openLeaves) + openLeaves.forEach((leaf) => leaf.detach()); // Empty trailDiv if (this.trailDiv) {