Skip to content

Commit

Permalink
fix: trailOrTable
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jul 9, 2021
1 parent a88c815 commit ceb61cd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 75 deletions.
48 changes: 21 additions & 27 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
await plugin.saveSettings();

plugin.refreshIntervalID = window.setInterval(async () => {
if (plugin.trailDiv || plugin.matrixView) {
plugin.currGraphs = await plugin.initGraphs();
}
if (plugin.trailDiv) {
plugin.currGraphs = await plugin.initGraphs();
if (plugin.settings.showTrail) {
await plugin.drawTrail();
}
if (plugin.matrixView) {
Expand Down Expand Up @@ -149,43 +147,39 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
containerEl.createEl("h3", { text: "Breadcrumb Trail" });

new Setting(containerEl)
.setName("Show Breadcrumb Trail")
.setName("Show Breadcrumbs")
.setDesc(
"Show a trail of notes leading from your index note down to the current note you are in (if a path exists)"
)
.addToggle((toggle) =>
toggle.setValue(plugin.settings.showTrail).onChange(async (value) => {
plugin.settings.showTrail = value;

await plugin.saveSettings();
if (value) {
plugin.trailDiv = createDiv({
cls: `breadcrumbs-trail is-readable-line-width${plugin.settings.respectReadableLineLength
? " markdown-preview-sizer markdown-preview-section"
: ""
}`,
});
await plugin.drawTrail();
} else {
plugin.trailDiv.remove();
}
await plugin.drawTrail();
})
);


new Setting(containerEl)
.setName("Trail or Table mode")
.setName("Trail or Table or Both")
.setDesc(
"Wether to show the regular breadcrumb trails, or a table view. On = Trail, Off = Table"
"Wether to show the regular breadcrumb trails, the table view, neither, or both. 1 = Only Trail, 2 = Only Grid, 3 = Both"
)
.addToggle((toggle) =>
toggle
.setValue(plugin.settings.trailOrTable)
.addText((text) => {
text
.setPlaceholder("Index Note")
.setValue(plugin.settings.trailOrTable.toString())
.onChange(async (value) => {
plugin.settings.trailOrTable = value;
await plugin.saveSettings();
await plugin.drawTrail()
})
);
const num = parseInt(value);
if ([1, 2, 3].includes(num)) {
plugin.settings.trailOrTable = num as 1 | 2 | 3;
await plugin.saveSettings();
await plugin.drawTrail();
} else {
new Notice("The value has to be 1, 2, or 3")
}
});
});

new Setting(containerEl)
.setName("Index/Home Note(s)")
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface BreadcrumbsSettings {
showNameOrType: boolean;
showRelationType: boolean;
showTrail: boolean;
trailOrTable: boolean;
trailOrTable: 1 | 2 | 3;
showAll: boolean;
noPathMessage: string;
trailSeperator: string;
Expand Down
99 changes: 52 additions & 47 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import type {
neighbourObj
} from "src/interfaces";
import MatrixView from "src/MatrixView";
import { closeImpliedLinks, debug, getFileFrontmatterArr, getNeighbourObjArr, isInVault, openOrSwitch } from "src/sharedFunctions";
import { closeImpliedLinks, debug, getFileFrontmatterArr, getNeighbourObjArr, isInVault } from "src/sharedFunctions";
import TrailGrid from "./TrailGrid.svelte";
import TrailPath from "./TrailPath.svelte";

const DEFAULT_SETTINGS: BreadcrumbsSettings = {
parentFieldName: "parent",
siblingFieldName: "sibling",
childFieldName: "child",
indexNote: ["Index"],
indexNote: [""],
refreshIntervalTime: 0,
defaultView: true,
showNameOrType: true,
showRelationType: true,
showTrail: true,
trailOrTable: false,
trailOrTable: 3,
showAll: false,
noPathMessage: `No path to index note was found`,
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
respectReadableLineLength: true,
debugMode: false,
Expand Down Expand Up @@ -211,16 +211,7 @@ export default class BreadcrumbsPlugin extends Plugin {
indexNotes.forEach((index) => {
let step = index;

// Check if indexNote exists
if (
!isInVault(this.app, index)
) {
return [
`${index} is not a note in your vault. Please change the settings for Index Notes`
];
}
// Check if a path even exists
else if (paths[step].distance !== Infinity) {
if (paths[step].distance !== Infinity) {
const breadcrumbs: string[] = [];
// Walk it until arriving at `from`
while (paths[step].distance !== 0) {
Expand All @@ -247,41 +238,55 @@ export default class BreadcrumbsPlugin extends Plugin {
}

async drawTrail(): Promise<void> {
const { gParents, gChildren } = this.currGraphs;
const closedParents = closeImpliedLinks(gParents, gChildren)
const sortedTrails = this.getBreadcrumbs(closedParents);
const currFile = this.app.workspace.getActiveFile();
const settings = this.settings

// Get the container div of the active note
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])
if (this.settings.showTrail) {

trailDiv.className = `breadcrumbs-trail is-readable-line-width${settings.respectReadableLineLength
? " markdown-preview-sizer markdown-preview-section"
: ""
}`
const { gParents, gChildren } = this.currGraphs;
const closedParents = closeImpliedLinks(gParents, gChildren)
const sortedTrails = this.getBreadcrumbs(closedParents);
const currFile = this.app.workspace.getActiveFile();
const settings = this.settings

previewView.prepend(trailDiv);

trailDiv.empty();
if (settings.trailOrTable) {
new TrailPath({
target: trailDiv,
props: { sortedTrails, app: this.app, settings, currFile }
})
} else {
new TrailGrid({
target: trailDiv,
props: { sortedTrails, app: this.app, settings }
})
// Get the container div of the active note
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])

trailDiv.className = `breadcrumbs-trail is-readable-line-width${settings.respectReadableLineLength
? " markdown-preview-sizer markdown-preview-section"
: ""
}`

previewView.prepend(trailDiv);

trailDiv.empty();


if (settings.trailOrTable === 1) {
new TrailPath({
target: trailDiv,
props: { sortedTrails, app: this.app, settings, currFile }
})
} else if (settings.trailOrTable === 2) {
new TrailGrid({
target: trailDiv,
props: { sortedTrails, app: this.app, settings }
})
} else {
new TrailPath({
target: trailDiv,
props: { sortedTrails, app: this.app, settings, currFile }
});
new TrailGrid({
target: trailDiv,
props: { sortedTrails, app: this.app, settings }
})
}
}
}

Expand Down

0 comments on commit ceb61cd

Please sign in to comment.