Skip to content

Commit

Permalink
fix(nextPrev): 🐛 Still show nextPrev (if there are any) even in no pa…
Browse files Browse the repository at this point in the history
…rents
  • Loading branch information
SkepticMystic committed Nov 18, 2021
1 parent eec41a7 commit b1b4c25
Showing 1 changed file with 43 additions and 14 deletions.
57 changes: 43 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Notice,
Plugin,
TFile,
WorkspaceLeaf
WorkspaceLeaf,
} from "obsidian";
import { openView, wait } from "obsidian-community-lib/dist/utils";
import { BCSettingTab } from "src/BreadcrumbsSettingTab";
Expand All @@ -17,14 +17,14 @@ import {
MATRIX_VIEW,
STATS_VIEW,
TRAIL_ICON,
TRAIL_ICON_SVG
TRAIL_ICON_SVG,
} from "src/constants";
import type {
BCIndex,
BCSettings,
Directions,
dvFrontmatterCache,
HierarchyGraphs
HierarchyGraphs,
} from "src/interfaces";
import MatrixView from "src/MatrixView";
import {
Expand All @@ -45,7 +45,7 @@ import {
mergeGs,
oppFields,
removeDuplicates,
writeBCToFile
writeBCToFile,
} from "src/sharedFunctions";
import StatsView from "src/StatsView";
import { VisModal } from "src/VisModal";
Expand Down Expand Up @@ -683,16 +683,40 @@ export default class BCPlugin extends Plugin {
const sortedTrails = this.getBreadcrumbs(closedUp, currFile);
debug(settings, { sortedTrails });

if (sortedTrails.length === 0 && settings.noPathMessage === "") {
const { basename } = currFile;
const { main } = this.currGraphs;

const next: { to: string; real: boolean }[] = [];
const prev: { to: string; real: boolean }[] = [];
main.forEachEdge(basename, (k, a, s, t) => {
if (a.dir === "next" && s === basename) {
next.push({ to: t, real: true });
}
if (a.dir === "prev" && t === basename) {
next.push({ to: s, real: false });
}
if (a.dir === "prev" && s === basename) {
prev.push({ to: t, real: true });
}
if (a.dir === "next" && t === basename) {
prev.push({ to: s, real: false });
}
});

const noItems =
sortedTrails.length === 0 && next.length === 0 && prev.length === 0;

if (noItems && settings.noPathMessage === "") {
debugGroupEnd(settings, "debugMode");
return;
}

const trailDiv = createDiv({
cls: `BC-trail ${settings.respectReadableLineLength
? "is-readable-line-width markdown-preview-sizer markdown-preview-section"
: ""
}`,
cls: `BC-trail ${
settings.respectReadableLineLength
? "is-readable-line-width markdown-preview-sizer markdown-preview-section"
: ""
}`,
});

this.visited.push([currFile.path, trailDiv]);
Expand All @@ -701,7 +725,7 @@ export default class BCPlugin extends Plugin {

trailDiv.empty();

if (sortedTrails.length === 0) {
if (noItems) {
trailDiv.innerText = settings.noPathMessage;
debugGroupEnd(settings, "debugMode");
return;
Expand All @@ -710,18 +734,23 @@ export default class BCPlugin extends Plugin {
const pathProps = { sortedTrails, app: this.app, settings, currFile };
const gridProps = { sortedTrails, app: this.app, plugin: this };

if (settings.showTrail) {
if (settings.showTrail && sortedTrails.length) {
new TrailPath({
target: trailDiv,
props: pathProps,
});
} if (settings.showGrid) {
}
if (settings.showGrid && sortedTrails.length) {
new TrailGrid({
target: trailDiv,
props: gridProps,
});
} if (settings.showPrevNext) {
new NextPrev({ target: trailDiv, props: { app: this.app, plugin: this } })
}
if (settings.showPrevNext && (next.length || prev.length)) {
new NextPrev({
target: trailDiv,
props: { app: this.app, plugin: this, next, prev },
});
}
}

Expand Down

0 comments on commit b1b4c25

Please sign in to comment.