diff --git a/src/List.svelte b/src/List.svelte
index 818f8954..8e97402a 100644
--- a/src/List.svelte
+++ b/src/List.svelte
@@ -12,8 +12,22 @@
export let list: SquareProps;
const { realItems, impliedItems, fieldName, app } = list;
- async function openLink(item: internalLinkObj) {
- await app.workspace.openLinkText(item.to, item.currFile.path);
+ const currFile = app.workspace.getActiveFile();
+
+ async function linkClick(item: internalLinkObj) {
+ const openLeaves = [];
+ // For all open leaves, if the leave's basename is equal to the link destination, rather activate that leaf instead of opening it in two panes
+ app.workspace.iterateAllLeaves((leaf) => {
+ if (leaf.view?.file?.basename === item.to) {
+ openLeaves.push(leaf);
+ }
+ });
+
+ if (openLeaves.length) {
+ app.workspace.setActiveLeaf(openLeaves[0]);
+ } else {
+ await app.workspace.openLinkText(item.to, item.currFile.path);
+ }
}
function hoverPreview(e) {
@@ -43,7 +57,7 @@
openLink(realItem)}
+ on:click={async () => linkClick(realItem)}
on:mouseover={hoverPreview}
>
{realItem.to.split("/").last()}
@@ -64,7 +78,7 @@
openLink(impliedItem)}
+ on:click={async () => linkClick(impliedItem)}
on:mouseover={hoverPreview}
>{impliedItem.to.split("/").last()}
diff --git a/src/MatrixView.ts b/src/MatrixView.ts
index be487ec1..c9b9a970 100644
--- a/src/MatrixView.ts
+++ b/src/MatrixView.ts
@@ -104,36 +104,56 @@ export default class MatrixView extends ItemView {
});
}
- nextLevel(obj: { [x: string]: any }, gChildren: Graph): void {
- for (const child in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, child)) {
- const childrenOfChild = (gChildren.successors(obj[child]) ??
- []) as string[];
- childrenOfChild.forEach((innerChild) => (obj[child] = { innerChild }));
- obj[child] = { ...childrenOfChild };
- }
+ getAdjList(
+ gChildren: Graph,
+ currFile: string,
+ depth: number
+ ): Map {
+ const adjList: Map = new Map();
+
+ function addNode(node: string) {
+ adjList.set(node, []);
+ }
+
+ addNode(currFile)
+
+ // const immediateChildren = (gChildren.successors(currFile) ??
+ // []) as string[];
+ // immediateChildren.forEach(addNode);
+
+ const visited: Set = new Set();
+
+ // Do this `depth` number of times
+ for (let i = 1; i < depth; i++) {
+ console.log(adjList);
+ adjList.forEach((childArr, parent) => {
+ let childrenOfKey: string[];
+ // If the node hasn't been visited before
+ if (!visited.has(parent)) {
+ // Get it's children
+ childrenOfKey = (gChildren.successors(parent) ?? []) as string[];
+ // Mark it as visited
+ visited.add(parent);
+ // Add it to the adjList
+ adjList.set(parent, childrenOfKey);
+ // Add the children as top-level map items
+ childrenOfKey.forEach((childOfKey) => {
+ addNode(childOfKey);
+ });
+ }
+ });
}
+
+ return adjList;
}
- // createIndexObj(gChildren: Graph, currFile: string, depth: number) {
- // const initialChildren: [string, number][][] = [[]];
-
- // const immediateChildren = (gChildren.successors(currFile) ??
- // []) as string[];
- // immediateChildren.forEach((child) => initialChildren[0].push([child, 1]));
-
- // console.log(initialChildren);
-
- // for (let i = 0; i < depth; i++) {
- // initialChildren.push([]);
- // initialChildren[i].forEach((childArr) => {
- // const childrenOfChild = (
- // (gChildren.successors(childArr[0]) ?? []) as string[]
- // ).map((child) => [child, i + 2]);
- // initialChildren[i + 1].push(childrenOfChild);
- // });
- // }
- // console.log(initialChildren);
+ // mapToMD(adjList: Map): string {
+ // let md = '';
+ // adjList.forEach((childArr, parent) => {
+
+ // })
+
+ // return md
// }
async draw(): Promise {
@@ -148,18 +168,14 @@ export default class MatrixView extends ItemView {
await this.draw();
});
- // const createIndexButton = this.contentEl.createEl("button", {
- // text: "Create Index",
- // });
- // createIndexButton.addEventListener("click", () =>
- // console.log(
- // this.createIndexObj(
- // this.plugin.currGraphs.gChildren,
- // currFile.basename,
- // 2
- // )
- // )
- // );
+ const createIndexButton = this.contentEl.createEl("button", {
+ text: "Create Index",
+ });
+ createIndexButton.addEventListener("click", () =>
+ console.log(
+ this.getAdjList(this.plugin.currGraphs.gChildren, currFile.basename, 2)
+ )
+ );
this.currGraphs = this.plugin.currGraphs;
const currFile = this.app.workspace.getActiveFile();
@@ -180,12 +196,12 @@ export default class MatrixView extends ItemView {
impliedParents,
impliedChildren,
] = [
- this.squareItems(gParents, currFile),
- this.squareItems(gSiblings, currFile),
- this.squareItems(gChildren, currFile),
- this.squareItems(gChildren, currFile, false),
- this.squareItems(gParents, currFile, false),
- ];
+ this.squareItems(gParents, currFile),
+ this.squareItems(gSiblings, currFile),
+ this.squareItems(gChildren, currFile),
+ this.squareItems(gChildren, currFile, false),
+ this.squareItems(gParents, currFile, false),
+ ];
/// Implied Siblings
const currParents = (gParents.successors(currFile.basename) ??
diff --git a/src/Square.svelte b/src/Square.svelte
index 424bf5cd..c2048dce 100644
--- a/src/Square.svelte
+++ b/src/Square.svelte
@@ -11,8 +11,24 @@
export let settings: BreadcrumbsSettings;
export let matrixView: MatrixView;
- async function openLink(item: internalLinkObj) {
- await app.workspace.openLinkText(item.to, item.currFile.path);
+ // async function openLink(item: internalLinkObj) {
+ // await app.workspace.openLinkText(item.to, item.currFile.path);
+ // }
+
+ async function linkClick(item: internalLinkObj) {
+ const openLeaves = [];
+ // For all open leaves, if the leave's basename is equal to the link destination, rather activate that leaf instead of opening it in two panes
+ app.workspace.iterateAllLeaves((leaf) => {
+ if (leaf.view?.file?.basename === item.to) {
+ openLeaves.push(leaf);
+ }
+ });
+
+ if (openLeaves.length) {
+ app.workspace.setActiveLeaf(openLeaves[0]);
+ } else {
+ await app.workspace.openLinkText(item.to, item.currFile.path);
+ }
}
function hoverPreview(e) {
@@ -42,7 +58,7 @@
openLink(realItem)}
+ on:click={async () => linkClick(realItem)}
on:mouseover={hoverPreview}
>{realItem.to.split("/").last()}
@@ -61,7 +77,7 @@
openLink(impliedItem)}
+ on:click={async () => linkClick(impliedItem)}
on:mouseover={hoverPreview}
>{impliedItem.to.split("/").last()}