Skip to content

Commit

Permalink
feat(CreateIndex): ✨ Improve CreateIndexButton Functionality
Browse files Browse the repository at this point in the history
The CreateIndex Functionality seems to be working now. I have a feeling there is a bug, but my tests didn't show it
  • Loading branch information
SkepticMystic committed Jul 21, 2021
1 parent af4027a commit 6a60509
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"conventionalCommits.scopes": [
"CreateIndex"
]
}
61 changes: 33 additions & 28 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,36 @@ export default class MatrixView extends ItemView {
return pathsArr;
}

createIndex(allPaths: string[][], currFile: string): string {
const reversed = allPaths.map((path) => path.reverse());
reversed.forEach((path) => path.shift());

let txt = currFile + "\n";
const indent = " ";
const visited: { [node: string]: number[] } = {};
reversed.forEach((path) => {
for (let depth = 0; depth < path.length; depth++) {
const currNode = path[depth];

// If that node has been visited before at the current depth
if (
visited.hasOwnProperty(currNode) &&
visited[currNode].includes(depth)
) {
continue;
} else {
txt += `${indent.repeat(depth)} - [[${currNode}]]\n`;

if (!visited.hasOwnProperty(currNode)) {
visited[currNode] = [];
}
visited[currNode].push(depth);
}
}
});
return txt;
}

async draw(): Promise<void> {
this.contentEl.empty();
// this.currGraphs = this.plugin.currGraphs;
Expand All @@ -138,33 +168,6 @@ export default class MatrixView extends ItemView {
closeImpliedLinks(gChildren, gParents),
currFile.basename
);
const reversed = allPaths.map((path) => path.reverse());
reversed.forEach((path) => path.shift());

let txt = currFile.basename + "\n";
const indent = " ";
const visited: string[] = [];
const depths: number[] = [];
reversed.forEach((path) => {
for (let i = 0; i < path.length; i++) {
const curr = path[i];
if (!visited.includes(curr)) {
const index = visited.indexOf(curr);
if (depths[index] !== i) {
txt += indent.repeat(i + 1);
txt += `- ${curr}\n`;
visited.push(curr);
depths.push(i);
}
} else {
const next = path[i + 1];
if (next) {
txt += indent.repeat(i + 2);
txt += `- ${next}\n`;
}
}
}
});

// !SECTION Create Index

Expand All @@ -180,7 +183,9 @@ export default class MatrixView extends ItemView {
const createIndexButton = this.contentEl.createEl("button", {
text: "Create Index",
});
createIndexButton.addEventListener("click", () => console.log(txt));
createIndexButton.addEventListener("click", () => {
console.log(this.createIndex(allPaths, currFile.basename));
});

const [parentFieldName, siblingFieldName, childFieldName] = [
settings.showNameOrType ? settings.parentFieldName : "Parent",
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as graphlib from "graphlib";
import { Graph } from "graphlib";
import { addIcon, MarkdownView, Plugin, TFile, WorkspaceLeaf } from "obsidian";
import { BreadcrumbsSettingTab } from "src/BreadcrumbsSettingTab";
Expand Down Expand Up @@ -35,7 +34,9 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = {
showTrail: true,
trailOrTable: 3,
gridHeatmap: false,
heatmapColour: getComputedStyle(document.body).getPropertyValue("--text-accent"),
heatmapColour: getComputedStyle(document.body).getPropertyValue(
"--text-accent"
),
showAll: false,
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
Expand Down

0 comments on commit 6a60509

Please sign in to comment.