From b76f919741042fd56dd24951261f02935e21d153 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Wed, 21 Jul 2021 15:07:58 +0200 Subject: [PATCH] feat(CreateIndex): Add setting to toggle wikilinks in index --- src/BreadcrumbsSettingTab.ts | 18 ++++++++++++++++++ src/MatrixView.ts | 22 +++++++++++++++++----- src/interfaces.ts | 3 ++- src/main.ts | 1 + 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index cd4d71f9..0556e17e 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -303,6 +303,24 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { }) ); + const createIndexDetails: HTMLDetailsElement = + containerEl.createEl("details"); + createIndexDetails.createEl("summary", { text: "Create Index" }); + + new Setting(createIndexDetails) + .setName("Add wiklink brackets") + .setDesc( + "When creating an index, should it wrap the note name in wikilinks `[[]]` or not. On = yes, off = no." + ) + .addToggle((toggle) => + toggle + .setValue(plugin.settings.wikilinkIndex) + .onChange(async (value) => { + plugin.settings.wikilinkIndex = value; + await plugin.saveSettings(); + }) + ); + const debugDetails: HTMLDetailsElement = containerEl.createEl("details"); debugDetails.createEl("summary", { text: "Debugging" }); diff --git a/src/MatrixView.ts b/src/MatrixView.ts index f2fa8227..0635d334 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -1,13 +1,17 @@ import type { Graph } from "graphlib"; import { ItemView, TFile, WorkspaceLeaf } from "obsidian"; +import { closeImpliedLinks, debug } from "src/sharedFunctions"; import { DATAVIEW_INDEX_DELAY, TRAIL_ICON, VIEW_TYPE_BREADCRUMBS_MATRIX, } from "src/constants"; -import type { internalLinkObj, SquareProps } from "src/interfaces"; +import type { + BreadcrumbsSettings, + internalLinkObj, + SquareProps, +} from "src/interfaces"; import type BreadcrumbsPlugin from "src/main"; -import { closeImpliedLinks, debug, dropMD } from "src/sharedFunctions"; import Lists from "./Lists.svelte"; import Matrix from "./Matrix.svelte"; @@ -125,7 +129,11 @@ export default class MatrixView extends ItemView { return pathsArr; } - createIndex(allPaths: string[][], currFile: string): string { + createIndex( + allPaths: string[][], + currFile: string, + settings: BreadcrumbsSettings + ): string { const reversed = allPaths.map((path) => path.reverse()); reversed.forEach((path) => path.shift()); @@ -143,7 +151,11 @@ export default class MatrixView extends ItemView { ) { continue; } else { - txt += `${indent.repeat(depth)} - [[${currNode}]]\n`; + txt += `${indent.repeat(depth)}- `; + txt += settings.wikilinkIndex ? "[[" : ""; + txt += currNode; + txt += settings.wikilinkIndex ? "]]" : ""; + txt += "\n"; if (!visited.hasOwnProperty(currNode)) { visited[currNode] = []; @@ -184,7 +196,7 @@ export default class MatrixView extends ItemView { text: "Create Index", }); createIndexButton.addEventListener("click", () => { - console.log(this.createIndex(allPaths, currFile.basename)); + console.log(this.createIndex(allPaths, currFile.basename, settings)); }); const [parentFieldName, siblingFieldName, childFieldName] = [ diff --git a/src/interfaces.ts b/src/interfaces.ts index f43b61d2..8131fec1 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -18,6 +18,7 @@ export interface BreadcrumbsSettings { noPathMessage: string; trailSeperator: string; respectReadableLineLength: boolean; + wikilinkIndex: boolean; debugMode: boolean; superDebugMode: boolean; } @@ -27,7 +28,7 @@ export interface JugglLink { links: { type: string; linksInLine: string[]; - }[] + }[]; } export interface neighbourObj { diff --git a/src/main.ts b/src/main.ts index caa33422..c23e81b6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -41,6 +41,7 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = { noPathMessage: `This note has no real or implied parents`, trailSeperator: "→", respectReadableLineLength: true, + wikilinkIndex: true, debugMode: false, superDebugMode: false, };