diff --git a/src/TrailGrid.svelte b/src/TrailGrid.svelte
index d4bc288d..b31e0970 100644
--- a/src/TrailGrid.svelte
+++ b/src/TrailGrid.svelte
@@ -31,10 +31,18 @@ debug(settings, {maxLength, paddedTrails, transposedTrails, uniqueValuesPerCol})
{#each transposedTrails as col, i}
{#each uniqueValuesPerCol[i] as step}
-
- {step}
+
+ {step}
{/each}
diff --git a/src/main.ts b/src/main.ts
index 6609cebf..428bc781 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -40,9 +40,7 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = {
export default class BreadcrumbsPlugin extends Plugin {
settings: BreadcrumbsSettings;
matrixView: MatrixView;
- trailDiv: HTMLDivElement;
- // activeTrails: { file: TFile, trailDiv: HTMLDivElement }[];
- // previousFile: TFile[];
+ visited: [string, HTMLDivElement][];
refreshIntervalID: number;
currGraphs: allGraphs;
@@ -51,8 +49,7 @@ export default class BreadcrumbsPlugin extends Plugin {
await this.loadSettings();
- // this.activeTrails = [];
- // this.previousFile = [this.app.workspace.getActiveFile(), this.app.workspace.getActiveFile()];
+ this.visited = [];
this.registerView(
VIEW_TYPE_BREADCRUMBS_MATRIX,
@@ -60,13 +57,12 @@ export default class BreadcrumbsPlugin extends Plugin {
);
this.app.workspace.onLayoutReady(async () => {
- this.trailDiv = createDiv()
+ // this.trailDiv = createDiv()
setTimeout(async () => {
this.currGraphs = await this.initGraphs();
this.initView(VIEW_TYPE_BREADCRUMBS_MATRIX);
-
if (this.settings.showTrail) {
await this.drawTrail();
}
@@ -78,11 +74,6 @@ export default class BreadcrumbsPlugin extends Plugin {
await this.matrixView.draw();
if (this.settings.showTrail) {
- // this.activeTrails.last().trailDiv.remove
- // this.activeTrails.splice(this.activeTrails.length - 1, 1)
- // this.previousFile.shift();
- // this.previousFile.push(this.app.workspace.getActiveFile())
- // console.log(this.previousFile)
await this.drawTrail();
}
})
@@ -255,31 +246,6 @@ export default class BreadcrumbsPlugin extends Plugin {
return sortedTrails;
}
-
- fillTrailDiv(trailDiv: HTMLDivElement, breadcrumbs: string[], currFile: TFile): void {
- // If a path was found
- if (breadcrumbs.length > 0) {
- breadcrumbs.forEach((crumb) => {
- const link = trailDiv.createSpan({
- text: crumb,
- // A link in the trail will never be unresolved, so no need to check
- cls: "internal-link breadcrumbs-link",
- });
- link.addEventListener("click", async (e) => {
- await openOrSwitch(this.app, crumb, currFile, e);
- });
- trailDiv.createSpan({
- text: ` ${this.settings.trailSeperator} `,
- });
- });
- trailDiv.removeChild(trailDiv.lastChild);
- }
- // Otherwise don't add any links, just text
- else {
- trailDiv.createSpan({ text: this.settings.noPathMessage });
- }
- }
-
async drawTrail(): Promise
{
const { gParents, gChildren } = this.currGraphs;
const closedParents = closeImpliedLinks(gParents, gChildren)
@@ -291,24 +257,29 @@ export default class BreadcrumbsPlugin extends Plugin {
const previewView = document.querySelector(
"div.mod-active div.view-content div.markdown-preview-view"
);
+ previewView.querySelector('div.breadcrumbs-trail')?.remove()
+
+ const trailDiv = createDiv()
+ previewView.prepend(trailDiv)
+ this.visited.push([currFile.path, trailDiv])
- this.trailDiv.className = `breadcrumbs-trail is-readable-line-width${settings.respectReadableLineLength
+ trailDiv.className = `breadcrumbs-trail is-readable-line-width${settings.respectReadableLineLength
? " markdown-preview-sizer markdown-preview-section"
: ""
}`
- previewView.prepend(this.trailDiv);
+ previewView.prepend(trailDiv);
- this.trailDiv.empty();
+ trailDiv.empty();
if (settings.trailOrTable) {
new TrailPath({
- target: this.trailDiv,
+ target: trailDiv,
props: { sortedTrails, app: this.app, settings, currFile }
})
} else {
new TrailGrid({
- target: this.trailDiv,
+ target: trailDiv,
props: { sortedTrails, app: this.app, settings }
})
}
@@ -347,7 +318,7 @@ export default class BreadcrumbsPlugin extends Plugin {
openLeaves.forEach((leaf) => leaf.detach());
// Empty trailDiv
- this.trailDiv.remove();
+ this.visited.forEach(visit => visit[1].remove())
}
}
diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts
index ad1d81ff..ce10271f 100644
--- a/src/sharedFunctions.ts
+++ b/src/sharedFunctions.ts
@@ -1,6 +1,6 @@
import type { Graph } from "graphlib";
import { parseTypedLink } from "juggl-api";
-import type { App, FrontMatterCache, TFile } from "obsidian";
+import type { App, FrontMatterCache, TFile, WorkspaceLeaf } from "obsidian";
import { dropHeaderOrAlias, splitLinksRegex } from "src/constants";
import type {
BreadcrumbsSettings,
@@ -227,19 +227,6 @@ export function closeImpliedLinks(real: Graph, implied: Graph): Graph {
return closedG
}
-// This doesn't work for some reason. Even if you pass it `app`, metadatacache is undefined
-// export function resolvedClass(
-// app: App,
-// toFile: string,
-// currFile: TFile
-// ):
-// | "internal-link is-unresolved breadcrumbs-link"
-// | "internal-link breadcrumbs-link" {
-// return app.metadataCache.unresolvedLinks[currFile.path][toFile] > 0
-// ? "internal-link is-unresolved breadcrumbs-link"
-// : "internal-link breadcrumbs-link";
-// }
-
export const isInVault = (app: App, note: string): boolean =>
!!app.metadataCache.getFirstLinkpathDest(
note,
@@ -267,7 +254,7 @@ export async function openOrSwitch(
const { workspace } = app;
const destFile = app.metadataCache.getFirstLinkpathDest(dest, currFile.path);
- const openLeaves = [];
+ const openLeaves: WorkspaceLeaf[] = [];
// 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
workspace.iterateAllLeaves((leaf) => {
if (leaf.view?.file?.basename === dest) {
@@ -275,7 +262,9 @@ export async function openOrSwitch(
}
});
- if (openLeaves.length) {
+
+ if (openLeaves.length > 0) {
+ console.log(openLeaves[0])
workspace.setActiveLeaf(openLeaves[0]);
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any