Skip to content

Commit

Permalink
feat(DendronNote): ✨ Option to display trimmed dendron note
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Dec 16, 2021
1 parent 95f414d commit 16defd6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,19 @@ export class BCSettingTab extends PluginSettingTab {
};
});

new Setting(alternativeHierarchyDetails)
.setName("Trim Dendron Note Names")
.setDesc(
"When displaying a dendron note name, should it be trimmed to only show the last item in the chain? e.g. `A.B.C` would be trimmed to only display `C`."
)
.addToggle((toggle) =>
toggle.setValue(settings.trimDendronNotes).onChange(async (value) => {
settings.trimDendronNotes = value;
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
})
);

const fields = getFields(settings.userHiers);

if (!fields.includes(settings.dendronNoteField)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Down.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
getSubInDirs,
} from "../graphUtils";
import type BCPlugin from "../main";
import { dropDendron } from "../sharedFunctions";
export let plugin: BCPlugin;
export let view: DownView;
Expand Down Expand Up @@ -91,7 +92,7 @@
<a
class="internal-link {isInVault(plugin.app, line[1])
? ''
: 'is-unresolved'}">{line[1]}</a
: 'is-unresolved'}">{dropDendron(line[1], settings)}</a
>
</span>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/Components/Lists.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import type { App, TFile } from "obsidian";
import { hoverPreview, openOrSwitch } from "obsidian-community-lib";
import { dropPathNDendron } from "../sharedFunctions";
import type { BCSettings, SquareProps } from "../interfaces";
import type MatrixView from "../MatrixView";
Expand Down Expand Up @@ -40,7 +41,7 @@
on:mouseover={(e) =>
hoverPreview(e, matrixView, realItem.to)}
>
{realItem.alt ?? realItem.to.split("/").last()}
{realItem.alt ?? dropPathNDendron(realItem.to, settings)}
</div>
</li>
{/each}
Expand All @@ -62,8 +63,10 @@
on:mouseover={(e) =>
hoverPreview(e, matrixView, impliedItem.to)}
aria-label={impliedItem.parent ?? ""}
aria-label-position="left"
>
{impliedItem.alt ?? impliedItem.to.split("/").last()}
{impliedItem.alt ??
dropPathNDendron(impliedItem.to, settings)}
</div>
</li>
{/each}
Expand Down
6 changes: 4 additions & 2 deletions src/Components/Matrix.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { hoverPreview, openOrSwitch } from "obsidian-community-lib";
import type { BCSettings, SquareProps } from "../interfaces";
import type MatrixView from "../MatrixView";
import { dropPathNDendron } from "../sharedFunctions";
export let filteredSquaresArr: SquareProps[][];
export let currFile: TFile;
Expand Down Expand Up @@ -40,7 +41,7 @@
on:mouseover={(event) =>
hoverPreview(event, matrixView, realItem.to)}
>
{realItem.alt ?? realItem.to.split("/").last()}
{realItem.alt ?? dropPathNDendron(realItem.to, settings)}
</div>
</li>
{/each}
Expand Down Expand Up @@ -70,7 +71,8 @@
: ""}
aria-label-position="left"
>
{impliedItem.alt ?? impliedItem.to.split("/").last()}
{impliedItem.alt ??
dropPathNDendron(impliedItem.to, settings)}
</div>
</li>
{/each}
Expand Down
14 changes: 7 additions & 7 deletions src/Components/TrailGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
hoverPreview,
openOrSwitch,
} from "obsidian-community-lib/dist/utils";
import {
closeImpliedLinks,
getOutNeighbours,
getSubInDirs,
} from "../graphUtils";
import type BCPlugin from "../main";
import {
dropDendron,
linkClass,
normalise,
padArray,
runs,
transpose,
} from "../sharedFunctions";
import {
closeImpliedLinks,
getOutNeighbours,
getSubInDirs,
} from "../graphUtils";
export let sortedTrails: string[][];
export let app: App;
export let plugin: BCPlugin;
Expand Down Expand Up @@ -114,7 +114,7 @@
on:mouseover={(e) => hoverPreview(e, activeLeafView, step.value)}
>
<div class={linkClass(app, step.value)}>
{step.value}
{dropDendron(step.value, settings)}
</div>
{#if step.value && settings.gridDots}
<div class="dots">
Expand Down
3 changes: 2 additions & 1 deletion src/Components/TrailPath.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
hoverPreview,
openOrSwitch,
} from "obsidian-community-lib/dist/utils";
import { dropDendron } from "../sharedFunctions";
import type BCPlugin from "../main";
export let sortedTrails: string[][];
Expand Down Expand Up @@ -31,7 +32,7 @@
on:click={async (e) => await openOrSwitch(app, crumb, e)}
on:mouseover={(e) => hoverPreview(e, view, crumb)}
>
{crumb}
{dropDendron(crumb, settings)}
</span>
{#if i < trail.length - 1}
<span>{" " + settings.trailSeperator + " "}</span>
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
treatCurrNodeAsImpliedSibling: false,
trimDendronNotes: false,
respectReadableLineLength: true,
userHiers: [
{
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface BCSettings {
showTrail: boolean;
trailSeperator: string;
treatCurrNodeAsImpliedSibling: boolean;
trimDendronNotes: boolean;
useAllMetadata: boolean;
userHiers: UserHier[];
visGraph: visTypes;
Expand Down
10 changes: 10 additions & 0 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "./constants";
import { getOppDir, getOppFields } from "./graphUtils";
import type {
BCSettings,
Directions,
MetaeditApi,
RealNImplied,
Expand Down Expand Up @@ -36,6 +37,15 @@ export function splitAndDrop(str: string): string[] {
);
}

export const dropPath = (path: string) => path.replace(/^.*\//, "");
export const dropDendron = (path: string, settings: BCSettings) =>
settings.trimDendronNotes
? path.split(settings.dendronNoteDelimiter).last()
: path;

export const dropPathNDendron = (path: string, settings: BCSettings) =>
dropDendron(dropPath(path), settings);

/**
* Get basename from a **Markdown** `path`
* @param {string} path
Expand Down

0 comments on commit 16defd6

Please sign in to comment.