Skip to content

Commit

Permalink
fix: removeDupliedImplied
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jun 30, 2021
1 parent 0d45e84 commit 82409d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
33 changes: 23 additions & 10 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { internalLinkObj } from "./interfaces";
import type { Graph } from "graphlib";
import { ItemView, TFile, WorkspaceLeaf } from "obsidian";
import {
Expand Down Expand Up @@ -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<void> {
this.contentEl.empty();
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 12 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
}
})
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -240,7 +239,9 @@ export default class BreadcrumbsPlugin extends Plugin {
initView = async (type: string): Promise<void> => {
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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit 82409d7

Please sign in to comment.