Skip to content

Commit

Permalink
feat(Path View): ✨ Option to show all trails if none are found going …
Browse files Browse the repository at this point in the history
…up to an index note (fix #69)
  • Loading branch information
SkepticMystic committed Nov 23, 2021
1 parent e2b68d6 commit c97cfd9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 53 deletions.
85 changes: 42 additions & 43 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21827,7 +21827,12 @@ function debugGroupEnd(settings, type) {
* @param {string} path
*/
const getBasename = (path) => path.split("/").last();
const splitAndTrim = (fields) => fields.split(",").map((str) => str.trim());
const splitAndTrim = (fields) => {
if (fields === "")
return [];
else
return fields.split(",").map((str) => str.trim());
};
// This function takes the real & implied graphs for a given relation, and returns a new graphs with both.
// It makes implied relations real
// TODO use reflexiveClosure instead
Expand Down Expand Up @@ -24811,6 +24816,7 @@ const DEFAULT_SETTINGS = {
showNameOrType: true,
showRelationType: true,
rlLeaf: true,
showAllPathsIfNoneToIndexNote: false,
showBCs: true,
showBCsInEditLPMode: false,
showTrail: true,
Expand Down Expand Up @@ -25605,13 +25611,7 @@ function instance$4($$self, $$props, $$invalidate) {

const change_handler = async (i, dir, e) => {
const { value } = e.target;

if (value === "") {
$$invalidate(0, currHiers[i][dir] = [], currHiers);
} else {
$$invalidate(0, currHiers[i][dir] = splitAndTrim(value), currHiers);
}

$$invalidate(0, currHiers[i][dir] = splitAndTrim(value), currHiers);
await update(currHiers);
};

Expand Down Expand Up @@ -25672,20 +25672,17 @@ class BCSettingTab extends obsidian.PluginSettingTab {
.setName("Hierarchy Note(s)")
.setDesc("A list of notes used to create external Breadcrumb structures.")
.addText((text) => {
let finalValue;
text
.setPlaceholder("Hierarchy Note(s)")
.setValue([settings.hierarchyNotes].flat().join(", "))
.onChange(async (value) => {
finalValue = splitAndTrim(value);
});
.setValue(settings.hierarchyNotes.join(", "));
text.inputEl.onblur = async () => {
if (finalValue[0] === "") {
settings.hierarchyNotes = finalValue;
const splits = splitAndTrim(text.getValue());
if (splits[0] === undefined) {
settings.hierarchyNotes = splits;
await plugin.saveSettings();
}
else if (finalValue.every((note) => isInVault(this.app, note))) {
settings.hierarchyNotes = finalValue;
else if (splits.every((note) => isInVault(this.app, note))) {
settings.hierarchyNotes = splits;
await plugin.saveSettings();
}
else {
Expand Down Expand Up @@ -25743,12 +25740,9 @@ class BCSettingTab extends obsidian.PluginSettingTab {
.setName("Fields used for Alternative note names (Aliases)")
.setDesc("A comma-separated list of fields you use to specify note name aliases. These fields will be checked, in order, and be used to display an alternate note title in both the list/matrix view, and trail/grid view. This field will probably be `alias` or `aliases`, but it can be anything, like `title`, for example.")
.addText((text) => {
let finalValue;
text.setValue(settings.altLinkFields.join(", ")).onChange((str) => {
finalValue = str;
});
text.setValue(settings.altLinkFields.join(", "));
text.inputEl.onblur = async () => {
settings.altLinkFields = splitAndTrim(finalValue);
settings.altLinkFields = splitAndTrim(text.getValue());
await plugin.saveSettings();
};
});
Expand Down Expand Up @@ -26030,28 +26024,34 @@ class BCSettingTab extends obsidian.PluginSettingTab {
.setName("Index/Home Note(s)")
.setDesc("The note that all of your other notes lead back to. The parent of all your parent notes. Just enter the name. So if your index note is `000 Home.md`, enter `000 Home`. You can also have multiple index notes (comma-separated list). The breadcrumb trail will show the shortest path back to any one of the index notes listed. You can now leave this field empty, meaning the trail will show a path going as far up the parent-tree as possible.")
.addText((text) => {
let finalValue;
text
.setPlaceholder("Index Note")
.setValue([settings.indexNotes].flat().join(", "))
.onChange(async (value) => {
finalValue = splitAndTrim(value);
});
.setValue(settings.indexNotes.join(", "));
text.inputEl.onblur = async () => {
// TODO Refactor this to general purpose isInVault function
if (finalValue[0] === "") {
settings.indexNotes = finalValue;
const splits = splitAndTrim(text.getValue());
if (splits[0] === undefined) {
settings.indexNotes = splits;
await plugin.saveSettings();
}
else if (finalValue.every((index) => isInVault(this.app, index))) {
settings.indexNotes = finalValue;
else if (splits.every((index) => isInVault(this.app, index))) {
settings.indexNotes = splits;
await plugin.saveSettings();
}
else {
new obsidian.Notice(`Atleast one of the notes is not in your vault`);
}
};
});
new obsidian.Setting(trailDetails)
.setName("Shows all paths if none to index note are found")
.setDesc("If you have an index notes chosen, but the trail view has no paths going up to those index notes, should it show all paths instead?")
.addToggle((toggle) => toggle
.setValue(settings.showAllPathsIfNoneToIndexNote)
.onChange(async (value) => {
settings.showAllPathsIfNoneToIndexNote = value;
await plugin.saveSettings();
await plugin.drawTrail();
}));
new obsidian.Setting(trailDetails)
.setName("Default: All or Shortest")
.setDesc("If multiple paths are found going up the parent tree, should all of them be shown by default, or only the shortest? On = all, off = shortest")
Expand Down Expand Up @@ -50055,13 +50055,17 @@ class BCPlugin extends obsidian.Plugin {
const { basename, extension } = currFile;
if (extension !== "md")
return null;
const allTrails = this.bfsAllPaths(g, basename);
let filteredTrails = [...allTrails];
const { indexNotes } = this.settings;
let allTrails = this.bfsAllPaths(g, basename);
// No index note chosen
if (indexNotes[0] !== "" && allTrails[0].length > 0) {
allTrails = allTrails.filter((trail) => indexNotes.includes(trail[0]));
// Filter for index notes
if (indexNotes[0] !== "" && filteredTrails[0].length > 0) {
filteredTrails = filteredTrails.filter((trail) => indexNotes.includes(trail[0]));
if (filteredTrails.length === 0 &&
this.settings.showAllPathsIfNoneToIndexNote)
filteredTrails = [...allTrails];
}
const sortedTrails = allTrails
const sortedTrails = filteredTrails
.filter((trail) => trail.length > 0)
.sort((a, b) => a.length - b.length);
this.debug({ sortedTrails });
Expand Down Expand Up @@ -50106,17 +50110,13 @@ class BCPlugin extends obsidian.Plugin {
return;
}
let view;
let livePreview = false;
if (mode === "preview") {
view = activeMDView.previewMode.containerEl.querySelector("div.markdown-preview-view");
}
else {
view = activeMDView.contentEl.querySelector("div.markdown-source-view");
if (view.hasClass("is-live-preview")) {
livePreview = true;
}
if (view.hasClass("is-live-preview")) ;
}
console.log({ view, livePreview });
(_b = activeMDView.containerEl
.querySelectorAll(".BC-trail")) === null || _b === void 0 ? void 0 : _b.forEach((trail) => trail.remove());
const closedUp = this.getLimitedTrailSub();
Expand Down Expand Up @@ -50163,7 +50163,6 @@ class BCPlugin extends obsidian.Plugin {
(_c = cmEditor.firstChild) === null || _c === void 0 ? void 0 : _c.before(trailDiv);
if (cmSizer)
cmSizer.before(trailDiv);
// view.querySelector("div.cm-editor")?.firstChild?.before(trailDiv);
}
trailDiv.empty();
if (noItems) {
Expand Down
16 changes: 16 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,22 @@ export class BCSettingTab extends PluginSettingTab {
};
});

new Setting(trailDetails)
.setName("Shows all paths if none to index note are found")
.setDesc(
"If you have an index notes chosen, but the trail view has no paths going up to those index notes, should it show all paths instead?"
)
.addToggle((toggle) =>
toggle
.setValue(settings.showAllPathsIfNoneToIndexNote)
.onChange(async (value) => {
settings.showAllPathsIfNoneToIndexNote = value;

await plugin.saveSettings();
await plugin.drawTrail();
})
);

new Setting(trailDetails)
.setName("Default: All or Shortest")
.setDesc(
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
showNameOrType: true,
showRelationType: true,
rlLeaf: true,
showAllPathsIfNoneToIndexNote: false,
showBCs: true,
showBCsInEditLPMode: false,
showTrail: true,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface BCSettings {
refreshOnNoteChange: boolean;
// refreshIntervalTime: number;
respectReadableLineLength: boolean;
showAllPathsIfNoneToIndexNote: boolean;
showNameOrType: boolean;
showRelationType: boolean;
showWriteAllBCsCmd: boolean;
Expand Down
25 changes: 15 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,15 +965,23 @@ export default class BCPlugin extends Plugin {
const { basename, extension } = currFile;
if (extension !== "md") return null;

const { indexNotes } = this.settings;

let allTrails: string[][] = this.bfsAllPaths(g, basename);
const allTrails: string[][] = this.bfsAllPaths(g, basename);
let filteredTrails = [...allTrails];

// No index note chosen
if (indexNotes[0] !== "" && allTrails[0].length > 0) {
allTrails = allTrails.filter((trail) => indexNotes.includes(trail[0]));
const { indexNotes } = this.settings;
// Filter for index notes
if (indexNotes[0] !== "" && filteredTrails[0].length > 0) {
filteredTrails = filteredTrails.filter((trail) =>
indexNotes.includes(trail[0])
);
if (
filteredTrails.length === 0 &&
this.settings.showAllPathsIfNoneToIndexNote
)
filteredTrails = [...allTrails];
}
const sortedTrails = allTrails

const sortedTrails = filteredTrails
.filter((trail) => trail.length > 0)
.sort((a, b) => a.length - b.length);

Expand Down Expand Up @@ -1049,8 +1057,6 @@ export default class BCPlugin extends Plugin {
}
}

console.log({ view, livePreview });

activeMDView.containerEl
.querySelectorAll(".BC-trail")
?.forEach((trail) => trail.remove());
Expand Down Expand Up @@ -1116,7 +1122,6 @@ export default class BCPlugin extends Plugin {
const cmSizer = view.querySelector("div.CodeMirror-sizer");
if (cmEditor) cmEditor.firstChild?.before(trailDiv);
if (cmSizer) cmSizer.before(trailDiv);
// view.querySelector("div.cm-editor")?.firstChild?.before(trailDiv);
}

trailDiv.empty();
Expand Down

0 comments on commit c97cfd9

Please sign in to comment.